Skip to content

Commit

Permalink
feat: Reusable GitHub Actions Workflow (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickevansuk authored Jan 31, 2025
1 parent a602e77 commit 51be7aa
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 80 deletions.
64 changes: 0 additions & 64 deletions .github/workflows/docker.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Code Tests

on:
# This does not run on push to master, as tests will instead be run there as
# part of the docker.yml workflow.
# part of the test-and-publish workflow.
pull_request:
branches: [ master ]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
name: Reference Implementation
name: Test and Publish

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_call:
inputs:
quick_test:
description: 'Run only random mode with all-features and both flows'
required: false
type: boolean
default: true
data-models_ref:
required: false
type: string
data-model-validator_ref:
required: false
type: string
rpde-validator_ref:
required: false
type: string
openactive-test-suite_ref:
required: false
type: string
default: 'refs/heads/master'

jobs:
tests:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
mode: ['random', 'controlled']
profile: ['all-features', 'single-seller', 'no-payment-reconciliation', 'no-auth', 'no-tax-calculation', 'prepayment-always-required', 'facilityuse-has-slots']
flow: ['simple', 'approval']
include:
- mode: 'random'
profile: 'all-features'
flow: 'both'
- mode: 'controlled'
profile: 'all-features'
flow: 'both'
mode: ${{ inputs.quick_test == 'true' && fromJson('["random"]') || fromJson('["random","controlled"]') }}
profile: ${{ inputs.quick_test == 'true' && fromJson('["all-features"]') || fromJson('["all-features","single-seller","no-payment-reconciliation","no-auth","no-tax-calculation","prepayment-always-required","facilityuse-has-slots"]') }}
flow: ${{ inputs.quick_test == 'true' && fromJson('["both"]') || fromJson('["simple","approval"]') }}
include: ${{ inputs.quick_test == 'true' && fromJson('[]') || fromJson('[{"mode":"random","profile":"all-features","flow":"both"},{"mode":"controlled","profile":"all-features","flow":"both"}]') }}

concurrency:
group: openactive-test-suite--${{ github.head_ref }}--${{ matrix.mode }}.${{ matrix.profile }}.${{ matrix.flow }}
Expand All @@ -32,8 +46,11 @@ jobs:
uses: actions/checkout@v4
with:
path: tests
repository: openactive/openactive-test-suite
# If this is being called from another workflow, then the openactive-test-suite_ref will be provided or defaulted; otherwise we can assume a different trigger
ref: ${{ inputs.openactive-test-suite_ref || github.ref }}
- name: Use matching coverage/* branch ${{ github.head_ref }} in OpenActive.Server.NET
if: ${{ startsWith(github.head_ref, 'coverage/') }}
if: ${{ github.repository == 'openactive/openactive-test-suite' && startsWith(github.head_ref, 'coverage/') }}
id: refs
run: echo "::set-output name=mirror_ref::${{ github.head_ref }}"
- name: Checkout OpenActive.Server.NET ${{ steps.refs.outputs.mirror_ref }}
Expand Down Expand Up @@ -74,6 +91,30 @@ jobs:
npm install
working-directory: tests

- name: Install specific version of data-models ${{ inputs.data-models_ref }}
if: ${{ inputs.data-models_ref }}
run: |
cd packages/openactive-broker-microservice && npm install github:openactive/data-models#${{ inputs.data-models_ref }}
cd packages/openactive-integration-tests && npm install github:openactive/data-models#${{ inputs.data-models_ref }}
working-directory: tests

- name: Install specific version of data-model-validator ${{ inputs.data-model-validator_ref }}
if: ${{ inputs.data-model-validator_ref }}
run: |
cd packages/openactive-broker-microservice && npm install github:openactive/data-model-validator#${{ inputs.data-model-validator_ref }}
cd packages/openactive-integration-tests && npm install github:openactive/data-model-validator#${{ inputs.data-model-validator_ref }}
working-directory: tests

- name: Install specific version of rpde-validator ${{ inputs.rpde-validator_ref }}
if: ${{ inputs.rpde-validator_ref }}
run: |
cd packages/openactive-broker-microservice && npm install github:openactive/rpde-validator#${{ inputs.rpde-validator_ref }}
working-directory: tests

- name: Run Checks on the Code (Test the Tests!)
run: npm test
working-directory: tests

- name: Run OpenActive Integration Tests in ${{ matrix.mode }} mode
run: npm start
env:
Expand All @@ -83,6 +124,7 @@ jobs:
NODE_ENV: .example.${{ matrix.profile }}
NODE_APP_INSTANCE: ci
working-directory: tests

# Two purposes to uploading the output from these tests:
# 1. So that the `deploy-output` job can use this output in order to publish it, as examples, to gh-pages
# 2. Make the artifact downloadable from GitHub to a developer so that they can debug
Expand All @@ -96,9 +138,9 @@ jobs:
deploy-output:
needs: tests
# Master branch only
if: ${{ github.ref == 'refs/heads/master' }}
if: ${{ github.repository == 'openactive/openactive-test-suite' && github.ref == 'refs/heads/master' }}

runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
# Checkout the repo to seed the contents of ./tests/publish/
Expand All @@ -124,3 +166,45 @@ jobs:
publish_dir: ./tests/publish
force_orphan: true
enable_jekyll: true

# Publish to GitHub Container Registry
build-and-push-docker-image:
# Master branch only - extra checks
if: ${{ github.repository == 'openactive/openactive-test-suite' && github.ref == 'refs/heads/master' }}
needs: tests
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for OpenActive Test Suite
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/openactive/test-suite
labels: |
org.opencontainers.image.title=OpenActive Test Suite
org.opencontainers.image.description=Test suite for OpenActive data publishing and Open Booking API implementations
org.opencontainers.image.vendor=OpenActive
tags: |
latest
- name: Build and push Docker image for OpenActive Test Suite
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit 51be7aa

Please sign in to comment.