Skip to content

Commit

Permalink
feat: GitHub actions support (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickevansuk authored Nov 21, 2024
1 parent 8d6b18e commit 1acba68
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,45 @@ Some things to note:
- When using a hostname other than `localhost` for your booking system, it must included at least one `.` to pass the validator.
- `host.docker.internal` must be the host to access your booking system locally if it is not running in another Docker container. This hostname must also be used within `NODE_CONFIG`.
### CI - GitHub Actions
This repository can also be referenced as a GitHub action, which conveniently wraps the Docker container.
The following steps may be used within a GitHub Actions script:
```yaml
steps:
- name: Run OpenActive Test Suite
uses: openactive/openactive-test-suite@master
with:
config_file: ./test-suite-config.json
NODE_CONFIG: |
{"ci": true, "broker": {"outputPath": "/github/workspace/test-suite/output/", "datasetSiteUrl": "http://host.docker.internal/openactive"}, "integrationTests": { "outputPath": "/github/workspace/test-suite/output/", "conformanceCertificatePath": "/github/workspace/test-suite/conformance/", "conformanceCertificateId": "https://certificates.example.com/openactive/" }, "sellers": {"primary": { "@id": "http://host.docker.internal/api/identifiers/sellers/1","secondary": { "@id": "http://host.docker.internal/api/identifiers/sellers/2"}}}}
- name: Upload test output as artifact
uses: actions/upload-artifact@v2
if: ${{ success() || failure() }}
with:
name: openactive-test-suite
path: ./test-suite/output/
- name: Deploy conformance certificate to Azure Blob Storage (master branch only)
uses: bacongobbler/[email protected]
if: ${{ github.ref == 'refs/heads/master' }}
with:
source_dir: ./test-suite/conformance/
container_name: '$web'
connection_string: ${{ secrets.CONFORMANCE_CERTIFICATE_BLOB_STORAGE_CONNECTION_STRING }}
sync: false
```
And as in the parent section, `NODE_CONFIG` must include `"ci": true`.
Note that `outputPath` and `conformanceCertificatePath` must start with `/github/workspace/` to ensure these outputs are accessible in subsequent steps.
As in the previous section, `host.docker.internal` must be the host to access your booking system locally to the GitHub action if it is not running in another Docker container. This hostname must also be used within `NODE_CONFIG` for `datasetSiteUrl` and Seller `@id`s.
The Test Suite Certificate should be updated upon each successfull CI run.
## Test Data Requirements
In order to run the tests in random mode, the target Open Booking API implementation will need to have some Opportunity data pre-loaded. Use [Test Data Generator](./packages/openactive-integration-tests/test-data-generator/) to find out how much data is needed and in what configuration.
Expand Down
37 changes: 37 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'OpenActive Test Suite'
description: 'Test suite for OpenActive implementations'
inputs:
args:
description: 'Arguments to pass to `npm start` of OpenActive Test Suite'
required: false
default: ''
config_dir:
description: 'The path of a config directory to copy into ./config/ of OpenActive Test Suite'
required: false
default: ''
config_file:
description: 'The path of a config file to copy into ./config/ of OpenActive Test Suite. This will also set NODE_CONFIG and NODE_APP_INSTANCE to ensure that the test suite uses this file.'
required: false
default: ''
NODE_CONFIG:
description: 'JSON configuration string to pass into OpenActive Test Suite'
required: true
default: '{ "ci": true }'
NODE_ENV:
description: 'Value of NODE_ENV environment variable to pass into OpenActive Test Suite'
required: false
default: ''
NODE_APP_INSTANCE:
description: 'Value of NODE_APP_INSTANCE environment variable to pass into OpenActive Test Suite'
required: false
default: ''
runs:
using: 'docker'
image: 'docker://ghcr.io/openactive/test-suite:latest'
args:
- ${{ inputs.args }}
env:
FORCE_COLOR: 1
NODE_CONFIG: ${{ inputs.NODE_CONFIG }}
NODE_ENV: ${{ inputs.NODE_ENV }}
NODE_APP_INSTANCE: ${{ inputs.NODE_APP_INSTANCE }}
21 changes: 18 additions & 3 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@
# The `exec` command replaces the current process with the new process, which
# enables signal interactivity (e.g. Ctrl-C).

## INPUT_CONFIG_DIR and INPUT_CONFIG_FILE relate to the `config_dir` and `config_file` inputs in GitHub Actions
## The below is used by the GitHub Action

## Specify the working directory explicitly as GitHub Actions will overwrite it
## Copy any config directory specified by `INPUT_CONFIG_DIR` to the config directory
if [ -f "${INPUT_CONFIG_DIR}" ]; then
cp "${INPUT_CONFIG_DIR}" /openactive-test-suite/config/
## Reset NODE_CONFIG_DIR so that the test suite does not use it, to ensure that this directory is used
export NODE_CONFIG_DIR=
fi

## Specify the working directory explicitly as GitHub Actions will overwrite it
## Copy any config file specified by `INPUT_CONFIG` to the config directory (used by GitHub Actions)
if [ -f "${INPUT_CONFIG}" ]; then
cp "${INPUT_CONFIG}" /openactive-test-suite/config/
## Copy any config file specified by `INPUT_CONFIG_FILE` to the config directory
if [ -f "${INPUT_CONFIG_FILE}" ]; then
cp "${INPUT_CONFIG_FILE}" /openactive-test-suite/config/dev.json
## Configure test suite to use this file
export NODE_ENV=dev
export NODE_APP_INSTANCE=
export NODE_CONFIG_DIR=
fi

# Change directory and start the app
Expand Down

0 comments on commit 1acba68

Please sign in to comment.