From 761e75123e96b4fba5880d323de6d7b85020db82 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Thu, 20 Jan 2022 16:45:26 +0100 Subject: [PATCH] Move from Travis to GHA - remove .travis.yml - Add GHA workflow with: - test (a very simple one, like it was @ travis). And, if it passes: - multi-platform build and publish to dockerhub and github. - Move the README badge to GHA. --- .github/workflows/test_buildx_and_publish.yml | 104 ++++++++++++++++++ .travis.yml | 15 --- README.md | 2 +- 3 files changed, 105 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/test_buildx_and_publish.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test_buildx_and_publish.yml b/.github/workflows/test_buildx_and_publish.yml new file mode 100644 index 0000000..cd85198 --- /dev/null +++ b/.github/workflows/test_buildx_and_publish.yml @@ -0,0 +1,104 @@ +name: Test and publish + +on: [push, pull_request] + +env: + REPOSITORY: moodle-exttests + DOCKERHUB_OWNER: moodlehq + GH_OWNER: moodlehq + +jobs: + Test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Build image + run: | + docker build . -t moodle-exttests + + - name: Run tests + run: | + docker run --name test0 -d -p 8000:80 moodle-exttests + until [ "`docker inspect -f {{.State.Health.Status}} test0`" == "healthy" ]; do + sleep 0.5; + done; + curl --fail -L http://127.0.0.1:8000/test_redir.php + + - name: Display container logs on failure + if: failure() + run: | + docker logs test0 + + - name: Cleanup docker images + run: | + docker rm -f test0 + + Publish: + # Completely avoid forks and pull requests to try this job. + if: github.repository_owner == 'moodlehq' && github.event_name == 'push' + # Requires Test to pass + needs: Test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + # Calculate the tags to be pussed to the registries. + - name: Calculate image tag names + id: calculatetags + uses: docker/metadata-action@v3 + with: + images: | + ${{ env.DOCKERHUB_OWNER }}/${{ env.REPOSITORY }} + ghcr.io/${{ env.GH_OWNER }}/${{ env.REPOSITORY }} + tags: | + type=raw,value=latest + + # https://github.com/docker/setup-qemu-action#usage + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + # https://github.com/marketplace/actions/docker-setup-buildx + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + # https://github.com/docker/login-action#docker-hub + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # https://github.com/docker/login-action#github-container-registry + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ secrets.GH_USERNAME }} + password: ${{ secrets.GITHUB_TOKEN }} + + # https://github.com/docker/build-push-action#multi-platform-image + - name: Build and push to Docker Hub and Github registries + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.calculatetags.outputs.tags }} + + # https://github.com/peter-evans/dockerhub-description + # It's horrible that we need to use password here instead of PAT, because + # that's only available via CLI what defeats 2FA. Anyway, we need to + # auto-update the description, so using it (till available via PAT). + # Link: https://github.com/peter-evans/dockerhub-description/issues/10 + # Note that we only update the description with the master branch version. + - name: Set Docker Hub description from README.md + if: github.ref == 'refs/heads/master' + uses: peter-evans/dockerhub-description@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + repository: ${{ env.DOCKERHUB_OWNER }}/${{ env.REPOSITORY }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 68b1d43..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: bash -services: docker -install: - - docker build -t moodle-exttests . - -script: - - "docker run --name test0 -d -p 8000:80 moodle-exttests" - - until [ "`docker inspect -f {{.State.Health.Status}} test0`" == "healthy" ]; do - sleep 0.5; - done; - - curl --fail -L http://127.0.0.1:8000/test_redir.php -after_failure: - - docker logs test0 -after_script: - - docker rm -f test0 diff --git a/README.md b/README.md index 422f281..030a08c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Test files for external Moodle tests ==================================== -[![Build Status](https://travis-ci.com/moodlehq/moodle-exttests.svg?branch=master)](https://travis-ci.com/moodlehq/moodle-exttests/branches) +[![Test and publish](https://github.com/moodlehq/moodle-exttests/actions/workflows/test_buildx_and_publish.yml/badge.svg?branch=master)](https://github.com/moodlehq/moodle-php-apache/actions/workflows/test_buildx_and_publish.yml) **It's really important to keep these files completely unmodified in order to obtain coherent test results in all supported Moodle versions.**