2016-12-25 13:13:33 +01:00
|
|
|
#!/usr/bin/env bash
|
2015-07-27 15:57:11 +02:00
|
|
|
#
|
|
|
|
# Process (API) docs after a successful build on Travis (via ../.travis.yml).
|
|
|
|
#
|
|
|
|
# Updated/changed documentation for "master" is pushed to gh-pages.
|
|
|
|
# In case of pull requests or other branches, it will get added to a separate branch.
|
|
|
|
# In case of a pull request, a compare view comment will be posted.
|
|
|
|
#
|
|
|
|
# NOTE: stdout/stderr might/should be discarded to not leak sensitive information.
|
|
|
|
|
|
|
|
echo "Post-processing (API) documentation."
|
|
|
|
echo "TRAVIS_PULL_REQUEST: $TRAVIS_PULL_REQUEST"
|
|
|
|
echo "TRAVIS_BRANCH: $TRAVIS_BRANCH"
|
|
|
|
|
2016-05-01 18:06:18 +02:00
|
|
|
if [ -z "$GH_APIDOC_TOKEN" ]; then
|
|
|
|
echo "No GH_APIDOC_TOKEN available. Skipping."
|
2015-07-27 15:57:11 +02:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2016-05-01 18:06:18 +02:00
|
|
|
# NOTE: DO NOT USE "set -x", or anything else that would reveal GH_APIDOC_TOKEN!
|
2015-07-27 15:57:11 +02:00
|
|
|
set -e
|
|
|
|
set +x
|
|
|
|
|
2016-05-09 01:05:53 +02:00
|
|
|
# Display exit code in term of failure (probably due to 'set -x').
|
|
|
|
trap '[ "$?" = 0 ] || echo "EXIT CODE: $?"' EXIT
|
|
|
|
|
2016-05-01 18:06:18 +02:00
|
|
|
REPO_APIDOC="https://${GH_APIDOC_TOKEN}@github.com/awesomeWM/apidoc"
|
2015-07-27 15:57:11 +02:00
|
|
|
REPO_DIR="$PWD"
|
|
|
|
|
|
|
|
export GIT_AUTHOR_NAME="awesome-robot on Travis CI"
|
|
|
|
export GIT_AUTHOR_EMAIL="awesome-robot@users.noreply.github.com"
|
|
|
|
export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
|
|
|
|
export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
|
|
|
|
|
2016-05-16 18:54:19 +02:00
|
|
|
git clone --branch gh-pages "$REPO_APIDOC" build/apidoc \
|
|
|
|
2>&1 | sed "s/$GH_APIDOC_TOKEN/GH_APIDOC_TOKEN/g"
|
2015-07-27 15:57:11 +02:00
|
|
|
cd build/apidoc
|
|
|
|
|
|
|
|
# This will re-use already existing branches (updated PR).
|
|
|
|
if [ "$TRAVIS_PULL_REQUEST" != false ]; then
|
|
|
|
BRANCH="pr-$TRAVIS_PULL_REQUEST"
|
|
|
|
elif [ "$TRAVIS_BRANCH" != master ]; then
|
|
|
|
# Use merge-base of master in branch name, to keep different branches with
|
|
|
|
# the same name apart.
|
2016-04-05 00:59:29 +02:00
|
|
|
# shellcheck disable=SC2015
|
|
|
|
BRANCH="$TRAVIS_BRANCH-$(cd "$REPO_DIR" \
|
2015-07-27 15:57:11 +02:00
|
|
|
&& git fetch --unshallow origin master \
|
2016-04-05 00:59:29 +02:00
|
|
|
&& git rev-parse --short "$(git merge-base HEAD FETCH_HEAD || true)" || true)"
|
2015-07-27 15:57:11 +02:00
|
|
|
else
|
|
|
|
BRANCH="gh-pages"
|
|
|
|
fi
|
|
|
|
if [ "$BRANCH" != "gh-pages" ]; then
|
|
|
|
git checkout -b "$BRANCH" "origin/${BRANCH}" || git checkout -b "$BRANCH"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Use a temporary branch for the two commits, which allows for a better UI.
|
|
|
|
git checkout -b merged-update
|
|
|
|
|
|
|
|
# Create a patch without irrelevant changes (version / timestamp).
|
|
|
|
diff -Nur . ../doc -I "Last updated" -I "<strong>Release</strong>:" \
|
2015-10-28 01:21:16 +01:00
|
|
|
-I "<h2>API documentation for awesome, a highly configurable X window manager (version .*)\.</h2>" \
|
2017-01-13 14:35:31 +01:00
|
|
|
-x .git -x README.md | patch -p1
|
2015-07-27 15:57:11 +02:00
|
|
|
|
|
|
|
git add --all .
|
|
|
|
if git diff --cached --exit-code --quiet; then
|
|
|
|
echo "Documentation has not changed."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2016-05-01 17:31:38 +02:00
|
|
|
LAST_COMMIT_MSG="$(cd "$REPO_DIR" && git log -1 --pretty=format:%s)"
|
|
|
|
LAST_COMMIT="$(cd "$REPO_DIR" && git rev-parse --short HEAD)"
|
|
|
|
|
2015-07-27 15:57:11 +02:00
|
|
|
# Commit the relevant changes.
|
|
|
|
COMMIT_MSG="Update docs for $AWESOME_VERSION via Travis
|
|
|
|
|
|
|
|
Last commit message:
|
2016-05-01 17:31:38 +02:00
|
|
|
$LAST_COMMIT_MSG
|
2015-07-27 15:57:11 +02:00
|
|
|
|
2016-12-25 13:13:33 +01:00
|
|
|
Commits: https://github.com/awesomeWM/awesome/compare/${TRAVIS_COMMIT_RANGE/.../..}
|
2015-07-27 15:57:11 +02:00
|
|
|
Build URL: https://travis-ci.org/awesomeWM/awesome/builds/${TRAVIS_BUILD_ID}"
|
|
|
|
git commit -m "[relevant] $COMMIT_MSG"
|
|
|
|
|
|
|
|
# Commit the irrelevant changes.
|
|
|
|
mv .git ../doc
|
|
|
|
cd ../doc
|
|
|
|
git add --all .
|
|
|
|
git commit -m "[boilerplate] $COMMIT_MSG"
|
|
|
|
|
2015-10-30 00:02:19 +01:00
|
|
|
# Reorder/swap commits, to have "relevant" after "boilerplate".
|
|
|
|
# This makes it show up earlier in the Github interface etc.
|
|
|
|
git tag _old
|
|
|
|
git reset --hard HEAD~2
|
|
|
|
git cherry-pick _old _old~1
|
2016-04-04 23:35:40 +02:00
|
|
|
RELEVANT_REV="$(git rev-parse --short HEAD)"
|
2015-10-30 00:02:19 +01:00
|
|
|
git tag -d _old
|
|
|
|
|
2015-07-27 15:57:11 +02:00
|
|
|
git checkout "$BRANCH"
|
2016-04-04 23:35:40 +02:00
|
|
|
OLD_REV="$(git rev-parse --short HEAD)"
|
2016-04-05 00:27:57 +02:00
|
|
|
if [ "$TRAVIS_PULL_REQUEST" != false ]; then
|
2016-05-01 17:31:38 +02:00
|
|
|
MERGE_COMMIT_MSG="$COMMIT_MSG
|
2016-04-05 00:27:57 +02:00
|
|
|
Pull request: https://github.com/awesomeWM/awesome/pull/${TRAVIS_PULL_REQUEST}"
|
2016-05-01 17:31:38 +02:00
|
|
|
else
|
2016-05-09 01:05:53 +02:00
|
|
|
PR_OR_ISSUE="$(echo "$COMMIT_MSG" | head -n 1 | grep -o '#[0-9]\+' || true)"
|
2016-05-01 17:31:38 +02:00
|
|
|
if [ -n "$PR_OR_ISSUE" ]; then
|
|
|
|
MERGE_COMMIT_MSG="$COMMIT_MSG
|
|
|
|
Ref: https://github.com/awesomeWM/awesome/pull/${PR_OR_ISSUE}"
|
|
|
|
else
|
|
|
|
PR_OR_ISSUE_URL="$(echo "$COMMIT_MSG" \
|
2016-05-09 01:05:53 +02:00
|
|
|
| grep -Eo 'https://github.com/awesomeWM/awesome/(issues|pull)/[0-9]+' || true)"
|
2016-05-01 17:31:38 +02:00
|
|
|
if [ -n "$PR_OR_ISSUE_URL" ]; then
|
|
|
|
MERGE_COMMIT_MSG="$COMMIT_MSG
|
|
|
|
Ref: $PR_OR_ISSUE_URL"
|
|
|
|
else
|
|
|
|
MERGE_COMMIT_MSG="$COMMIT_MSG
|
|
|
|
Commit: https://github.com/awesomeWM/awesome/commit/${LAST_COMMIT}
|
|
|
|
Tree: https://github.com/awesomeWM/awesome/commits/${LAST_COMMIT}"
|
|
|
|
fi
|
|
|
|
fi
|
2016-04-05 00:27:57 +02:00
|
|
|
fi
|
|
|
|
git merge --no-ff -m "$MERGE_COMMIT_MSG" merged-update
|
2016-04-04 23:35:40 +02:00
|
|
|
NEW_REV="$(git rev-parse --short HEAD)"
|
2015-07-27 15:57:11 +02:00
|
|
|
|
2016-05-16 18:54:19 +02:00
|
|
|
git push origin "$BRANCH" 2>&1 | sed "s/$GH_APIDOC_TOKEN/GH_APIDOC_TOKEN/g"
|
2015-07-27 15:57:11 +02:00
|
|
|
|
|
|
|
# Generate compare view links.
|
2016-04-05 00:28:21 +02:00
|
|
|
# NOTE: use "\n" for line endings, not real ones for valid json!
|
2015-07-27 15:57:11 +02:00
|
|
|
COMPARE_LINKS="Compare view: https://github.com/awesomeWM/apidoc/compare/${OLD_REV}...${NEW_REV}"
|
2016-04-04 23:35:40 +02:00
|
|
|
COMPARE_LINKS="$COMPARE_LINKS\nRelevant changes: https://github.com/awesomeWM/apidoc/commit/${RELEVANT_REV}"
|
2015-07-27 15:57:11 +02:00
|
|
|
if [ "$BRANCH" != "gh-pages" ]; then
|
|
|
|
COMPARE_LINKS="$COMPARE_LINKS\nComparison against master (gh-pages): https://github.com/awesomeWM/apidoc/compare/gh-pages...${NEW_REV}"
|
|
|
|
fi
|
2016-04-05 00:59:29 +02:00
|
|
|
# shellcheck disable=SC2028
|
2015-07-27 15:57:11 +02:00
|
|
|
echo "Compare links:\n$COMPARE_LINKS"
|
|
|
|
|
|
|
|
# Post a comment to the PR.
|
|
|
|
if [ "$TRAVIS_PULL_REQUEST" != false ]; then
|
2016-05-01 18:06:18 +02:00
|
|
|
curl -H "Authorization: token $GH_APIDOC_TOKEN" \
|
2016-05-01 17:31:38 +02:00
|
|
|
-d "{\"body\": \"Documentation has been updated for this PR.\n\n$COMPARE_LINKS\"}" \
|
2016-05-16 18:54:19 +02:00
|
|
|
"https://api.github.com/repos/awesomeWM/awesome/issues/${TRAVIS_PULL_REQUEST}/comments" \
|
|
|
|
2>&1 | sed "s/$GH_APIDOC_TOKEN/GH_APIDOC_TOKEN/g"
|
2015-07-27 15:57:11 +02:00
|
|
|
fi
|
2015-12-12 17:34:16 +01:00
|
|
|
|
|
|
|
# vim: filetype=sh:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|