Skip to content

Commit

Permalink
ci: test for ci pytest (without img build)
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Jan 5, 2024
1 parent f03e8f6 commit 6506cef
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/tests/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# A generic workflow to run tests within a docker compose stack

name: Run Tests

on:
pull_request:
branches:
- main
- staging
- development

jobs:
run-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Vars and Secrets to Env
env:
TAG_OVERRIDE: ${{ env.TAG_OVERRIDE || 'ci-development' }}
GIT_BRANCH: ${{ github.ref_name }}
VARS_CONTEXT: ${{ toJson(vars) }}
SECRETS_CONTEXT: ${{ toJson(secrets) }}
run: |
# Random delimeter string for security
delim=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
# Parse JSON with multiline strings, using delimeter (Github specific)
to_envs() { jq -r "to_entries[] | \"\(.key)<<$delim\n\(.value)\n$delim\n\""; }
# Set all vars
echo "TAG_OVERRIDE=${TAG_OVERRIDE}" >> $GITHUB_ENV
echo "GIT_BRANCH=${GIT_BRANCH}" >> $GITHUB_ENV
# Set VARS_CONTEXT if not null
if [ "${VARS_CONTEXT}" != "null" ]; then
echo "${VARS_CONTEXT}" | to_envs >> $GITHUB_ENV
fi
# Set SECRETS_CONTEXT if not null
if [ "${SECRETS_CONTEXT}" != "null" ]; then
echo "${SECRETS_CONTEXT}" | to_envs >> $GITHUB_ENV
fi
- name: Create .env file
run: |
# Get a8m/envsubst (required for default vals syntax ${VAR:-default})
echo "Downloading envsubst"
curl -L https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst-`uname -s`-`uname -m` -o envsubst
chmod +x envsubst
# Check if .env.example exists
if [ -f .env.example ]; then
echo "Substituting variables from .env.example --> .env"
./envsubst < .env.example > .env
else
echo ".env.example not found, creating .env with GIT_BRANCH only"
echo "GIT_BRANCH=${GIT_BRANCH}" > .env
fi
echo "GIT_BRANCH=${GIT_BRANCH}" >> .env
- name: Run Tests
run: |
docker compose up -d proxy
docker compose run api pytest
11 changes: 9 additions & 2 deletions .github/workflows/tests/test_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ set -e
# GITHUB_TOKEN=input
# Feed to act using -s flag: -s GITHUB_TOKEN=input_personal_access_token

# PR Test Backend
act pull_request -W .github/workflows/pr_test_backend.yml \
# Run backend PyTest manually
docker compose build api
act pull_request -W .github/workflows/tests/pytest.yml \
-e .github/workflows/tests/pr_payload.json \
--var-file=.env --secret-file=.env

# # PR Test Backend
# Includes image build, which fails due to registry auth
# act pull_request -W .github/workflows/pr_test_backend.yml \
# -e .github/workflows/tests/pr_payload.json \
# --var-file=.env --secret-file=.env

# PR Test Frontend
act pull_request -W .github/workflows/pr_test_frontend.yml \
-e .github/workflows/tests/pr_payload.json \
Expand Down

0 comments on commit 6506cef

Please sign in to comment.