-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
45de1c3
commit 5948b89
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |