From 5948b894179e156e0785ddc7d5b017d3c40f8a60 Mon Sep 17 00:00:00 2001 From: Scott Aubrey Date: Thu, 28 Nov 2024 15:01:12 +0000 Subject: [PATCH] A github-actions based test and build pipeline (#1932) * Start creating a github-actions based test and build pipeline * use a much better CONTAINER_TAG value * complete build phase with critical css building and pushing * fix use of old docker-compose command * only build and push on master --- .github/workflows/ci.yaml | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..8e0ed885e --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,72 @@ +name: CI Pipeline + +on: + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + push: + branches: + - master + +jobs: + generate-date: + runs-on: ubuntu-latest + outputs: + date: ${{ steps.date.outputs.date }} + steps: + - name: Get current date + id: date + run: echo "date=$(date --utc +%Y%m%d.%H%M)" >> $GITHUB_OUTPUT + + tests: + runs-on: ubuntu-latest + strategy: + matrix: + test_script: ["phpcs", "phpunit", "behat"] + steps: + - uses: actions/checkout@v4 + - name: Bring up test stack + run: docker compose -f docker-compose.yml -f docker-compose.ci.yml up -d + - name: Debug bring up test stack + if: failure() + run: docker compose logs + - name: Run tests + run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run ci ./.ci/${{ matrix.test_script }} + - name: Take down test stack + if: always() + run: docker compose down + + build-and-push: + runs-on: ubuntu-latest + needs: [generate-date, tests] + if: github.ref == 'refs/heads/master' + env: + CONTAINER_REPO: ghcr.io/elifesciences/journal + CONTAINER_TAG: ${{ github.head_ref || github.ref_name }}-${{ github.sha }}-${{ needs.generate-date.outputs.date }} + steps: + - uses: actions/checkout@v4 + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build container image + run: | + # Build all images + docker compose -f docker-compose.yml -f docker-compose.ci.yml build + + # Build critical CSS + docker compose -f docker-compose.yml -f docker-compose.ci.yml run --name=journal_critical_css critical_css + docker cp journal_critical_css:build/critical-css/. build/critical-css/ + + # Rebuild app now we have new CSS + docker compose -f docker-compose.yml -f docker-compose.ci.yml build app + + # Retag and push + docker image tag elifesciences/journal:develop ${CONTAINER_REPO}:${CONTAINER_TAG} + - name: Push container image + run: docker push ${CONTAINER_REPO}:${CONTAINER_TAG}