-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: test for ci pytest (without img build)
- Loading branch information
1 parent
f03e8f6
commit 6506cef
Showing
2 changed files
with
77 additions
and
2 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,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 |
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