From 13bb928ca4da3fa472d58f674cda00e38cbbab22 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Sun, 2 Feb 2020 16:17:49 +0100 Subject: [PATCH] Switch from TravisCI to GitHub Actions --- .github/workflows/test-extensions.yml | 78 +++++++++++++++++++ .github/workflows/update-readme.yml | 20 +++++ .travis.yml | 74 ------------------ README.md | 2 +- ...sci-test-extensions => ci-test-extensions} | 29 ++++--- scripts/ci-update-readme | 70 +++++++++++++++++ scripts/invoke-shfmt | 4 +- scripts/travisci-update-readme | 73 ----------------- 8 files changed, 191 insertions(+), 159 deletions(-) create mode 100644 .github/workflows/test-extensions.yml create mode 100644 .github/workflows/update-readme.yml delete mode 100644 .travis.yml rename scripts/{travisci-test-extensions => ci-test-extensions} (88%) create mode 100755 scripts/ci-update-readme delete mode 100755 scripts/travisci-update-readme diff --git a/.github/workflows/test-extensions.yml b/.github/workflows/test-extensions.yml new file mode 100644 index 0000000..27ea415 --- /dev/null +++ b/.github/workflows/test-extensions.yml @@ -0,0 +1,78 @@ +name: Test extensions + +on: + - pull_request + +jobs: + check_syntax_shell: + name: Check shell coding style + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v1 + with: + go-version: "1.13" + - name: Install shfmt + run: GO111MODULE=on go install mvdan.cc/sh/v3/cmd/shfmt + - name: Checkout + uses: actions/checkout@v1 + with: + fetch-depth: 1 + - name: Check coding style + run: | + export PATH=$PATH:$(go env GOPATH)/bin + ./scripts/invoke-shfmt check + check_syntax_php: + name: Check PHP coding style + runs-on: ubuntu-latest + steps: + - name: Install PHP + uses: shivammathur/setup-php@v1 + with: + php-version: "7.4" + tools: composer + - name: Checkout + uses: actions/checkout@v1 + with: + fetch-depth: 1 + - name: Install Composer dependencies + run: composer install -a + - name: Check coding style + run: composer run-script lint -- --dry-run --diff + test_extensions: + needs: + - check_syntax_shell + - check_syntax_php + strategy: + matrix: + distro: + - alpine3.7 + - alpine3.8 + - alpine3.9 + - alpine3.10 + - jessie + - stretch + - buster + name: Check on ${{ matrix.distro }} + runs-on: ubuntu-latest + env: + DOCKER_DISTRO: ${{ matrix.distro }} + steps: + - name: Checkout + uses: actions/checkout@v1 + with: + fetch-depth: 1 + - name: Test extensions + run: ./scripts/ci-test-extensions "${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}" + test_restoring_packages: + name: Test restoring packages + needs: + - check_syntax_shell + - check_syntax_php + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + with: + fetch-depth: 1 + - run: docker run --rm --volume "$(pwd):/app" --workdir /app php:7.3-stretch ./scripts/test-restore-apt diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml new file mode 100644 index 0000000..3da82d3 --- /dev/null +++ b/.github/workflows/update-readme.yml @@ -0,0 +1,20 @@ +name: Update README + +on: + push: + branches: + - master + +jobs: + update_readme: + name: Update README + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Update README + env: + DEPLOY_KEY: "${{ secrets.DEPLOY_KEY }}" + GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no" + run: ./scripts/ci-update-readme diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 43d226f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,74 +0,0 @@ -sudo: false - -notifications: - email: false - -branches: - only: - - master - -language: minimal - -test-extensions-job-template: &test-extensions-job-template - stage: Test extensions - if: type = pull_request - services: - - docker - script: ./scripts/travisci-test-extensions - -jobs: - include: - - stage: Pre-test checks - name: Check shell coding style - if: type = pull_request - language: go - go: '1.13' - before_script: GO111MODULE=on go install mvdan.cc/sh/v3/cmd/shfmt - script: ./scripts/invoke-shfmt check - - - stage: Pre-test checks - name: Check PHP coding style - if: type = pull_request - language: php - php: '7.4' - install: composer install -a - script: composer run-script lint -- --dry-run --diff - - - <<: *test-extensions-job-template - name: Test extensions on Alpine 3.7 - env: DOCKER_DISTRO=alpine3.7 - - - <<: *test-extensions-job-template - name: Test extensions on Alpine 3.8 - env: DOCKER_DISTRO=alpine3.8 - - - <<: *test-extensions-job-template - name: Test extensions on Alpine 3.9 - env: DOCKER_DISTRO=alpine3.9 - - - <<: *test-extensions-job-template - name: Test extensions on Alpine 3.10 - env: DOCKER_DISTRO=alpine3.10 - - - <<: *test-extensions-job-template - name: Test extensions on Debian 8 (jessie) - env: DOCKER_DISTRO=jessie - - - <<: *test-extensions-job-template - name: Test extensions on Debian 9 (stretch) - env: DOCKER_DISTRO=stretch - - - <<: *test-extensions-job-template - name: Test extensions on Debian 10 (buster) - env: DOCKER_DISTRO=buster - - - <<: *test-extensions-job-template - name: Test restoring previous packages - script: docker run --rm --volume "$TRAVIS_BUILD_DIR:/app" --workdir /app php:7.3-stretch ./scripts/test-restore-apt - - - stage: Update docs - name: Update README.md - if: branch = master AND type = push - env: - - secure: "vsl8z41oBky/MDRDKqs74Bif6BJldCPFVdl2lbPcjehOYG5cZ4YRLIEuhgJfnOglCGdyY6gh/2umSowRI4r5mC/ZR42RKJzWj9xQX2usJbzeOeZj+5eQv5im1DVwRmigUMzQOS743bd/zEeR9J3MLMgTGhKWEPKOJI6CHseUIKazAc0Z8vH6055YtkhGMqnolOe9h0gJx/sLP18qo2LTw82SyjOAMfbyYuHpiLznAqIOpNtwyj9WAujE3qN2oCo+9ALOnnrlINPqeLjnIOxRcSgYO4wIGPGSXIDTquuUht0McszOLuC9/kc6RybcyxmcqsssYRK2y0DQuavzyja5UaB4Pzf2vMrlbozAxdtF3oadZzfsAYfbhzaLbx0g1aAzL1CTJvXrWkZQgiy2c7tboXKJ3SvOqDp+GXEw08kCTpUq1AYSLw8ExlqcWZGiQxJfnfA05fWOkf8xM38ZQ+LPUHyGrt+PIw8FPAGhOV4E+BmHUlOoXOwoNllCEJ4QNkwxYT90eAMS5Rw8q6KASedwDFwyPCv8VtpNEtsl/FVa3m8/6wA7QmtuPxg7E2wceSkzsqHEcGLzERb4DnhVfrW0wv8zRw92vsnBmZdxusBT5uuyp9h5asjj6YhhVJ52g2NdCAGJlobiPk5X4uifshcdlcS8vF/jBMpI03XyJU4V4xc=" - script: ./scripts/travisci-update-readme diff --git a/README.md b/README.md index 062c0c5..40ef6e4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![TravisCI Build Status](https://travis-ci.org/mlocati/docker-php-extension-installer.svg?branch=master)](https://travis-ci.org/mlocati/docker-php-extension-installer) +![Test extensions](https://github.com/mlocati/docker-php-extension-installer/workflows/Test%20extensions/badge.svg) # Easy installation of PHP extensions in official PHP Docker images diff --git a/scripts/travisci-test-extensions b/scripts/ci-test-extensions similarity index 88% rename from scripts/travisci-test-extensions rename to scripts/ci-test-extensions index f2a56bf..65758e2 100755 --- a/scripts/travisci-test-extensions +++ b/scripts/ci-test-extensions @@ -5,12 +5,23 @@ set -o errexit set -o nounset echo 'Checking environment' -if test -z "${TRAVIS_BUILD_DIR:-}" || test -z "${TRAVIS_COMMIT_RANGE:-}" || test -z "${DOCKER_DISTRO:-}"; then - echo 'Not in a TravisCI environment' >&2 +if test -n "${GITHUB_WORKSPACE:-}" && test -n "${GITHUB_SHA:-}"; then + if test -z "${1:-}"; then + echo 'Missing commit range of the push event' >&2 + exit 1 + fi + CI_BUILD_DIR="$GITHUB_WORKSPACE" + CI_COMMIT_RANGE="$1" +else + echo 'Not in a CI environment' >&2 + exit 1 +fi +if test -z "${DOCKER_DISTRO:-}"; then + echo 'DOCKER_DISTRO environment variable not set' >&2 exit 1 fi -. "$TRAVIS_BUILD_DIR/scripts/common" +. "$CI_BUILD_DIR/scripts/common" ALREADY_TESTED_EXTENSIONS='' @@ -29,7 +40,7 @@ getDockerImageName() { ;; esac getDockerImageName_suffix='cli' - getDockerImageName_reqs="$TRAVIS_BUILD_DIR/data/special-requirements" + getDockerImageName_reqs="$CI_BUILD_DIR/data/special-requirements" if test -f "$getDockerImageName_reqs"; then IFS=' ' for getDockerImageName_testExtension in $1; do @@ -86,7 +97,7 @@ testExtension() { fi printf ' - Docker image: %s\n' "$testExtension_Image" testExtension_out="$(mktemp)" - if $(docker run --rm --volume "$TRAVIS_BUILD_DIR:/app" --workdir /app "$testExtension_Image" sh -c "./install-php-extensions $1 && php ./scripts/check-installed-extension.php $1" >"$testExtension_out" 2>&1); then + if $(docker run --rm --volume "$CI_BUILD_DIR:/app" --workdir /app "$testExtension_Image" sh -c "./install-php-extensions $1 && php ./scripts/check-installed-extension.php $1" >"$testExtension_out" 2>&1); then rm -rf "$testExtension_out" printf ' - Passed\n' return 0 @@ -192,7 +203,7 @@ getAllPHPVersionsForExtension() { fi fi done - done <"$TRAVIS_BUILD_DIR/data/supported-extensions" + done <"$CI_BUILD_DIR/data/supported-extensions" printf '%s' "$getAllPHPVersionsForExtension_result" } @@ -211,7 +222,7 @@ testExtensionsFromMessage() { testExtensionsFromMessage_result=0 TEST_EXTENSIONS= FIRST_LINE=1 - testExtensionsFromMessage_message="$(git -C "$TRAVIS_BUILD_DIR" log --pretty='format:%B' -n 1 "$1")" + testExtensionsFromMessage_message="$(git -C "$CI_BUILD_DIR" log --pretty='format:%B' -n 1 "$1")" IFS=' ' for COMMIT_LINE in $testExtensionsFromMessage_message; do @@ -269,7 +280,7 @@ ADDED_EXTENSION_LINE= FOUND_ATAT= IFS=' ' -for DIFF_LINE in $(git -C "$TRAVIS_BUILD_DIR" diff --no-indent-heuristic --minimal --no-color --word-diff=none -no-renames --unified=0 "$TRAVIS_COMMIT_RANGE" -- data/supported-extensions); do +for DIFF_LINE in $(git -C "$CI_BUILD_DIR" diff --no-indent-heuristic --minimal --no-color --word-diff=none -no-renames --unified=0 "$CI_COMMIT_RANGE" -- data/supported-extensions); do if test -n "$DIFF_LINE"; then if test -z "$FOUND_ATAT"; then if test -z "${DIFF_LINE##@@*}"; then @@ -287,7 +298,7 @@ done IFS=' ' -for COMMIT_HASH in $(git -C "$TRAVIS_BUILD_DIR" log --pretty='format:%H' "$TRAVIS_COMMIT_RANGE"); do +for COMMIT_HASH in $(git -C "$CI_BUILD_DIR" log --pretty='format:%H' "$CI_COMMIT_RANGE"); do if ! testExtensionsFromMessage "$COMMIT_HASH"; then TESTS_RESULTS=1 fi diff --git a/scripts/ci-update-readme b/scripts/ci-update-readme new file mode 100755 index 0000000..31f2744 --- /dev/null +++ b/scripts/ci-update-readme @@ -0,0 +1,70 @@ +#!/bin/sh + +# Let's set a sane environment +set -o errexit +set -o nounset + +UPDATE_README_COMMIT_AUTHOR_NAME='CI' +UPDATE_README_COMMIT_AUTHOR_EMAIL='michele@locati.it' +UPDATE_README_COMMIT_MESSAGE='[skip ci] Automatically update README.md' +WATCHED_FILES='data/special-requirements data/supported-extensions scripts/common scripts/update-readme scripts/ci-update-readme' +UPDATE_BRANCH='master' + +echo 'Checking environment' +if test -z "${GITHUB_WORKSPACE:-}" || test -z "${GITHUB_REF:-}" || test -z "${GITHUB_EVENT_NAME:-}" || test -z "${GITHUB_REPOSITORY:-}"; then + echo 'Not in a GitHub Actions environment' >&2 + exit 1 +fi +if test "$GITHUB_EVENT_NAME" != 'push' || test "$GITHUB_REF" != "refs/heads/$UPDATE_BRANCH"; then + echo 'This script should only be run in push builds to %s' "$UPDATE_BRANCH" >&2 + exit 1 +fi +if test -z "${DEPLOY_KEY:-}"; then + echo 'GitHub deploy key not set' >&2 + exit 1 +fi + +SCRIPTS_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" +. "$SCRIPTS_DIR/common" + +cd "$GITHUB_WORKSPACE" + +printf 'Checking-out branch %s\n' "$UPDATE_BRANCH" +git checkout --force "$UPDATE_BRANCH" + +LAST_AUTO_UPDATED_IN="$(git rev-list --max-count 1 --author "<$UPDATE_README_COMMIT_AUTHOR_EMAIL>" --grep "$UPDATE_README_COMMIT_MESSAGE" "$UPDATE_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' "$UPDATE_BRANCH" +else + MODIFIED_FILES_SINCE="$(git diff --name-only "$LAST_AUTO_UPDATED_IN...$UPDATE_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' "$UPDATE_BRANCH" "$LAST_AUTO_UPDATED_IN" + exit 0 + fi + printf 'Rebuild of README.md enabled (relevant files changed in branch %s since commit %s)\n' "$UPDATE_BRANCH" "$LAST_AUTO_UPDATED_IN" +fi + +echo 'Updating README.md' +"$SCRIPTS_DIR/update-readme" +if test -z "$(git ls-files -m | grep -E '^README\.md$')"; then + echo 'README.md has not been changed' + exit 0 +fi + +printf 'Initializing SSH' +eval "$(ssh-agent)" +printf '%s' "$DEPLOY_KEY" | tr -d '\r' | ssh-add - >/dev/null + +printf 'Adding %s remote\n' "$GITHUB_REPOSITORY" +git remote add deploy "git@github.com/$GITHUB_REPOSITORY.git" + +echo 'Committing changes to README.md' +git config user.name "$UPDATE_README_COMMIT_AUTHOR_NAME" +git config user.email "$UPDATE_README_COMMIT_AUTHOR_EMAIL" +git add README.md +git commit -m "$UPDATE_README_COMMIT_MESSAGE" + +printf 'Pushing to %s\n' "$GITHUB_REPOSITORY" +git push deploy "$UPDATE_BRANCH" + +echo 'Done.' diff --git a/scripts/invoke-shfmt b/scripts/invoke-shfmt index 4c24e41..cd3d51f 100755 --- a/scripts/invoke-shfmt +++ b/scripts/invoke-shfmt @@ -24,6 +24,6 @@ shfmt $PARAMS \ scripts/invoke-shfmt \ scripts/lint \ scripts/test-restore-apt \ - scripts/travisci-test-extensions \ - scripts/travisci-update-readme \ + scripts/ci-test-extensions \ + scripts/ci-update-readme \ scripts/update-readme diff --git a/scripts/travisci-update-readme b/scripts/travisci-update-readme deleted file mode 100755 index 7af4b2e..0000000 --- a/scripts/travisci-update-readme +++ /dev/null @@ -1,73 +0,0 @@ -#!/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='[skip ci] Automatically update README.md' -WATCHED_FILES='data/special-requirements data/supported-extensions scripts/common scripts/update-readme scripts/travisci-update-readme' - -SCRIPTS_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" -. "$SCRIPTS_DIR/common" - -echo 'Checking environment' -if test -z "${TRAVIS_BUILD_DIR:-}" || test -z "${TRAVIS_BRANCH:-}" || test -z "${TRAVIS_EVENT_TYPE:-}" || test -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 / GUTHUB_ACCESS_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 - -printf 'Checking-out branch %s\n' "$TRAVIS_BRANCH" -git checkout --force "$TRAVIS_BRANCH" - -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" -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 - -printf 'Adding %s remote\n' "$TRAVIS_REPO_SLUG" -git remote add deploy "https://$GUTHUB_ACCESS_TOKEN@github.com/$TRAVIS_REPO_SLUG.git" - -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 'Pushing to %s\n' "$TRAVIS_REPO_SLUG" -git push deploy "$TRAVIS_BRANCH" - -echo 'Done.'