Skip to content

A github-actions based test and build pipeline #2

A github-actions based test and build pipeline

A github-actions based test and build pipeline #2

Workflow file for this run

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
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: build images
uses: docker/bake-action@v5
with:
files: docker-compose.yml,docker-compose.ci.yml
tests:
runs-on: ubuntu-latest
needs: [build]
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: |
docker compose -f 'docker-compose.yml' -f 'docker-compose.ci.yml' build
docker image tag elifesciences/journal:develop ${CONTAINER_REPO}:${CONTAINER_TAG}
- name: Push container image
run: docker push ${CONTAINER_REPO}:${CONTAINER_TAG}