Skip to content

Commit

Permalink
chore: add CI workflow for server e2e tests (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan authored Oct 8, 2024
1 parent 350eb8a commit e47b743
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/fly-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Cleans up orphaned test apps on Fly
# TODO: check app creation date - could destroy an app during a test run

name: Fly Cleanup
on:
workflow_dispatch:
schedule:
- cron: '0 5 * * *' # Every day at 5am UTC
jobs:
cleanup:
name: Cleanup Orphaned Apps
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
run: |
fly apps list -q -o digidem | while IFS= read -r name; do
# Trim leading and trailing whitespace from $name
name=$(echo "$name" | xargs)
# Check if the name starts with 'comapeo-cloud-test-'
if [[ $name == comapeo-cloud-test-* ]]; then
# Call the fly destroy command with the name
fly apps destroy -y "$name"
fi
done
26 changes: 26 additions & 0 deletions .github/workflows/server-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Server e2e cloud test

on:
push:
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: npm ci
- run: npm run build --if-present
- run: node --test ./test-e2e/server.js
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
REMOTE_TEST_SERVER: true
2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

app = 'comapeo-cloud'
primary_region = 'ord'
primary_region = 'iad'

[env]
STORAGE_DIR = '/data'
Expand Down
18 changes: 10 additions & 8 deletions test-e2e/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,24 @@ async function createTestServer(t) {
* @returns {Promise<string>} server base URL
*/
async function createRemoteTestServer(t) {
const { stdout } = await execa(
'fly',
['apps', 'create', '--generate-name', '--org', 'digidem', '--json'],
{ stderr: 'inherit' }
const appName = 'comapeo-cloud-test-' + Math.random().toString(36).slice(8)
await execa(
'flyctl',
['apps', 'create', '--name', appName, '--org', 'digidem', '--json'],
{ stdio: 'inherit' }
)
const { ID: appName } = JSON.parse(stdout)
t.after(async () => {
await execa('fly', ['apps', 'destroy', appName, '-y'], { stdio: 'inherit' })
await execa('flyctl', ['apps', 'destroy', appName, '-y'], {
stdio: 'inherit',
})
})
await execa(
'fly',
'flyctl',
['secrets', 'set', 'SERVER_BEARER_TOKEN=ignored', '--app', appName],
{ stdio: 'inherit' }
)
await execa(
'fly',
'flyctl',
['deploy', '--app', appName, '-e', 'SERVER_NAME=test server'],
{
stdio: 'inherit',
Expand Down

0 comments on commit e47b743

Please sign in to comment.