mirror of
https://github.com/mlocati/docker-php-extension-installer
synced 2025-05-09 00:22:40 +00:00
Let TravisCI automatically rebuild README.md when pushing
This commit is contained in:
parent
e0965d93e3
commit
830d462bd8
3 changed files with 120 additions and 0 deletions
77
scripts/travisci-update-readme
Executable file
77
scripts/travisci-update-readme
Executable file
|
@ -0,0 +1,77 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Let's set a sane environment
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
UPDATE_README_COMMIT_AUTHOR_NAME='Travis CI'
|
||||
UPDATE_README_COMMIT_AUTHOR_EMAIL='michele@locati.it'
|
||||
UPDATE_README_COMMIT_MESSAGE='Automatically update README.md'
|
||||
WATCHED_FILES='data/special-requirements data/supported-extensions scripts/common scripts/update-readme scripts/travisci-update-readme'
|
||||
|
||||
|
||||
echo 'Checking environment'
|
||||
if test -z "${TRAVIS_BUILD_DIR:-}" -o -z "${TRAVIS_BRANCH:-}" -o -z "${TRAVIS_EVENT_TYPE:-}" -o -z "${TRAVIS_REPO_SLUG:-}"
|
||||
then
|
||||
echo 'Not in a TravisCI environment' >&2
|
||||
exit 1
|
||||
fi
|
||||
if test -z "${GUTHUB_ACCESS_TOKEN:-}"
|
||||
then
|
||||
|
||||
echo 'GitHub access token not set' >&2
|
||||
# To create it:
|
||||
# - go to https://github.com/settings/tokens/new?scopes=repo
|
||||
# - create a new token
|
||||
# - sudo apt install -y build-essential ruby ruby-dev
|
||||
# - sudo gem install travis
|
||||
# - travis encrypt -r <owner>/<repo> GUTHUB_ACCESS_TOKEN=<TOKEN>
|
||||
# - Add to .travis.yml:
|
||||
# env:
|
||||
# global:
|
||||
# - secure: "encrypted string"
|
||||
exit 1
|
||||
fi
|
||||
if test "${TRAVIS_EVENT_TYPE}" != 'push'
|
||||
then
|
||||
echo 'This script should only be run in push builds' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LAST_AUTO_UPDATED_IN="$(git -C "${TRAVIS_BUILD_DIR}" rev-list --max-count 1 --author "<${UPDATE_README_COMMIT_AUTHOR_EMAIL}>" --grep "${UPDATE_README_COMMIT_MESSAGE}" "${TRAVIS_BRANCH}")"
|
||||
if test -z "${LAST_AUTO_UPDATED_IN}"
|
||||
then
|
||||
printf 'Rebuild of README.md enabled (no previous automatic refresh of it in branch %s)\n' "${TRAVIS_BRANCH}"
|
||||
else
|
||||
MODIFIED_FILES_SINCE="$(git -C "${TRAVIS_BUILD_DIR}" diff --name-only "${LAST_AUTO_UPDATED_IN}...${TRAVIS_BRANCH}")"
|
||||
if test -z "$(commonElements "${WATCHED_FILES}" "${MODIFIED_FILES_SINCE}")"
|
||||
then
|
||||
printf 'Rebuild of README.md not needed (no relevant files changed in branch %s since commit %s)\n' "${TRAVIS_BRANCH}" "${LAST_AUTO_UPDATED_IN}"
|
||||
exit 0
|
||||
fi
|
||||
printf 'Rebuild of README.md enabled (relevant files changed in branch %s since commit %s)\n' "${TRAVIS_BRANCH}" "${LAST_AUTO_UPDATED_IN}"
|
||||
fi
|
||||
|
||||
echo 'Updating README.md'
|
||||
"${TRAVIS_BUILD_DIR}/scripts/update-readme"
|
||||
set -x
|
||||
if test -z "$(git -C "${TRAVIS_BUILD_DIR}" ls-files -m | grep -E '^README\.md$')"
|
||||
then
|
||||
echo 'README.md has not been changed'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo 'Committing changes to README.md'
|
||||
git -C "${TRAVIS_BUILD_DIR}" config user.name "${UPDATE_README_COMMIT_AUTHOR_NAME}"
|
||||
git -C "${TRAVIS_BUILD_DIR}" config user.email "${UPDATE_README_COMMIT_AUTHOR_EMAIL}"
|
||||
git -C "${TRAVIS_BUILD_DIR}" add README.md
|
||||
git -C "${TRAVIS_BUILD_DIR}" commit -m "${UPDATE_README_COMMIT_MESSAGE}"
|
||||
|
||||
printf 'Adding %s remote\n' "${TRAVIS_REPO_SLUG}"
|
||||
git remote add deploy "https://${GUTHUB_ACCESS_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git"
|
||||
|
||||
printf 'Pushing to %s\n' "${TRAVIS_REPO_SLUG}"
|
||||
git push deploy "${TARGET_BRANCH}"
|
||||
git -C "${TRAVIS_BUILD_DIR}" push add deploy "https://${GUTHUB_ACCESS_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git"
|
||||
|
||||
echo 'Done.'
|
Loading…
Add table
Add a link
Reference in a new issue