Skip to content

Commit

Permalink
A github-actions based test and build pipeline (#1932)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
scottaubrey authored Nov 28, 2024
1 parent 45de1c3 commit 5948b89
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 5948b89

Please sign in to comment.