-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AUT-105: Add GitHub Workflows for building, integration and unit test…
…ing. (#916) * Add github workflow to build images * Run tests with built docker images * Use a github service container for the db in unit tests * Parallelize integration tests using a matrix job * Add test entrypoint to wait for autograph to start * Specify DB connection as URL * Don't bother compressing docker images - Github does it for us * Invert docker compose ordering * Add an integration test for the monitor-lambda-emulator
- Loading branch information
Showing
7 changed files
with
244 additions
and
29 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,120 @@ | ||
name: Tests | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
# Restrict tests to the most recent commit. | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
name: Build Docker Images | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
testcases: ${{ steps.enum-tests.outputs.testcases }} | ||
steps: | ||
- name: Clone repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build images | ||
shell: bash | ||
run: make generate build | ||
|
||
- name: Save images | ||
shell: bash | ||
run: | | ||
mkdir -p docker-cache | ||
docker save -o docker-cache/autograph-images.tar autograph-app autograph-app-hsm | ||
- name: Enumerate tests | ||
id: enum-tests | ||
shell: bash | ||
run: | | ||
echo -n "testcases=" >> $GITHUB_OUTPUT | ||
yq -o=json '.services | keys' tools/autograph-client/integration-tests.yml | jq -c >> $GITHUB_OUTPUT | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: autograph-images-${{ github.sha }} | ||
path: docker-cache/ | ||
|
||
unit-tests: | ||
name: Run Unit Tests | ||
runs-on: ubuntu-22.04 | ||
needs: | ||
- build | ||
env: | ||
DBNAME: autograph | ||
PGPASSWORD: myautographdbpassword | ||
|
||
services: | ||
database: | ||
image: postgres:11 | ||
env: | ||
POSTGRES_DB: ${{ env.DBNAME }} | ||
POSTGRES_PASSWORD: ${{ env.PGPASSWORD }} | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
ports: | ||
- 5432:5432 | ||
|
||
steps: | ||
- name: Clone repository | ||
uses: actions/checkout@v4 | ||
|
||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: autograph-images-${{ github.sha }} | ||
path: docker-cache/ | ||
|
||
- name: Initialize database | ||
shell: bash | ||
run: psql -h localhost -p 5432 -U postgres --no-password -f database/schema.sql ${{ env.DBNAME }} | ||
|
||
- name: Load images | ||
shell: bash | ||
run: docker load -i docker-cache/autograph-images.tar | ||
|
||
- name: Run Tests | ||
shell: bash | ||
env: | ||
AUTOGRAPH_DB_DSN: postgres://myautographdbuser:${{ env.PGPASSWORD }}@localhost/${{ env.DBNAME }}?sslmode=disable | ||
run: | | ||
docker run \ | ||
--env AUTOGRAPH_DB_DSN \ | ||
--env RACE_TEST=0 \ | ||
--workdir /app/src/autograph \ | ||
--net=host \ | ||
--user 0 \ | ||
autograph-app ./bin/run_unit_tests.sh | ||
integration-tests: | ||
name: Run Integration Tests | ||
runs-on: ubuntu-22.04 | ||
needs: | ||
- build | ||
strategy: | ||
fail-fast: false # Don't cancel other jobs if a test fails | ||
matrix: | ||
testcase: ${{ fromJSON(needs.build.outputs.testcases) }} | ||
steps: | ||
- name: Clone repository | ||
uses: actions/checkout@v4 | ||
|
||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: autograph-images-${{ github.sha }} | ||
path: docker-cache/ | ||
|
||
- name: Load images | ||
shell: bash | ||
run: docker load -i docker-cache/autograph-images.tar | ||
|
||
- name: Running ${{ matrix.testcase }} | ||
shell: bash | ||
run: docker compose -f tools/autograph-client/integration-tests.yml run ${{ matrix.testcase }} |
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
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
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,70 @@ | ||
include: | ||
- ../../docker-compose.yml | ||
services: | ||
test-api-app: | ||
container_name: test-api-app | ||
image: autograph-app | ||
user: "0" | ||
links: | ||
- app | ||
depends_on: | ||
- app | ||
entrypoint: ./test-entrypoint.sh | ||
environment: | ||
- CHECK_BOB=1 | ||
- AUTOGRAPH_URL=http://app:8000 | ||
working_dir: "/app/src/autograph/tools/autograph-client" | ||
command: [ "./integration_test_api.sh" ] | ||
|
||
test-api-hsm: | ||
container_name: test-api-hsm | ||
image: autograph-app | ||
user: "0" | ||
links: | ||
- app-hsm | ||
depends_on: | ||
- app-hsm | ||
entrypoint: ./test-entrypoint.sh | ||
environment: | ||
- AUTOGRAPH_URL=http://app-hsm:8001 | ||
working_dir: "/app/src/autograph/tools/autograph-client" | ||
command: [ "./integration_test_api.sh" ] | ||
|
||
test-gpg-signing: | ||
container_name: test-gpg-signing | ||
extends: | ||
service: test-api-app | ||
command: [ "./integration_test_gpg2_signer.sh" ] | ||
|
||
test-xpi-signing: | ||
container_name: test-xpi-signing | ||
extends: | ||
service: test-api-app | ||
command: [ "./integration_test_xpis.sh" ] | ||
|
||
test-xpi-signing-hsm: | ||
container_name: test-xpi-signing-hsm | ||
extends: | ||
service: test-api-hsm | ||
environment: | ||
- SIGNER_ID_PREFIX=hsm- | ||
command: [ "./integration_test_xpis.sh" ] | ||
|
||
test-apk-signing: | ||
container_name: test-apk-signing | ||
extends: | ||
service: test-api-app | ||
environment: | ||
- TARGET=http://app:8000 | ||
- VERIFY=1 | ||
command: [ "./build_test_apks.sh" ] | ||
|
||
test-monitor-app: | ||
container_name: test-monitor-app | ||
extends: | ||
file: ../../docker-compose.yml | ||
service: monitor-lambda-emulator | ||
entrypoint: [ "/usr/local/bin/lambda-selftest-entrypoint.sh" ] | ||
|
||
# TODO: Add a monitor test for the HSM lambda - tricky because we need | ||
# a way to dynamically grab the root hash from the HSM. |
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,23 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Wait for the heartbeat | ||
RESULT=$(curl --silent \ | ||
--connect-timeout 5 \ | ||
--max-time 10 \ | ||
--retry-connrefused \ | ||
--retry 5 \ | ||
--retry-delay 5 \ | ||
--retry-max-time 60 \ | ||
"${AUTOGRAPH_URL}/__heartbeat__") | ||
RETCODE=$? | ||
if [ $RETCODE -ne 0 ]; then | ||
echo "Failed to reach autograph heartbeat" >&2 | ||
exit $RETCODE | ||
else | ||
echo "Autograph is running: ${RESULT}" | ||
echo "Starting test" | ||
fi | ||
|
||
# Run the test | ||
set -e | ||
exec "$@" |
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
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