Skip to content

Commit

Permalink
ci: Make test workflow reusable and add run sanity check
Browse files Browse the repository at this point in the history
* Add sanity run steps to check for obvious errors when running in production
* Refactor test job to be reusable
  • Loading branch information
FoxxMD committed Oct 10, 2024
1 parent abc5d18 commit 1b0e7a3
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 73 deletions.
10 changes: 8 additions & 2 deletions .github/act/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ docker pull ghcr.io/jefuller/artifact-server:latest
docker run -d --name artifact-server -p 8082:8080 --add-host host.docker.internal:host-gateway -e AUTH_KEY=foo ghcr.io/jefuller/artifact-server:latest
```

Run the following **from this directory** to make use of `.actrc` and proper working directoy.
Run the following **from this directory** to make use of `.actrc` and proper working directory.

### Test Branch Test Suite

```shell
act -W '.github/act/testSuite.yml' -e '.github/act/actBranchEvent.json'
```

### Test Branch Push

Expand Down Expand Up @@ -44,4 +50,4 @@ act -W '.github/act/multiRunnerTest.yml' -e '.github/act/actBranchEvent.json'

```shell
act -W '.github/act/multiRunnerBakeTest.yml' -e '.github/act/actBranchEvent.json'
```
```
17 changes: 1 addition & 16 deletions .github/act/testSuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,4 @@ on:

jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dev dependencies
run: npm ci
- name: Build Backend
run: 'npm run build:backend'
- name: Test Backend
run: npm run test
uses: ./.github/workflows/testAndSanity.yml
22 changes: 2 additions & 20 deletions .github/workflows/dependabotTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ on:

jobs:
test:
name: Run Tests and Build (sanity)
name: Tests / Build / Sanity Run
if: github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dev dependencies
run: npm ci
- name: Build Backend
run: 'npm run build:backend'
- name: Test Backend
run: npm run test
- name: Install Docs Deps
run: npm run docs:install
- name: Build
run: npm run build
uses: ./.github/workflows/testAndSanity.yml
20 changes: 1 addition & 19 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,8 @@ on:

jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'safe to test')
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dev dependencies
run: npm ci
- name: Build Backend
run: 'npm run build:backend'
- name: Test Backend
run: npm run test
uses: ./.github/workflows/testAndSanity.yml

release-snapshot:
name: Release snapshot
Expand All @@ -45,9 +30,6 @@ jobs:
- dockerfile: ./Dockerfile
suffix: ''
platforms: 'linux/amd64,linux/arm64'
# - dockerfile: ./alpine.Dockerfile
# suffix: '-alpine'
# platforms: 'linux/amd64,linux/arm64'
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down
17 changes: 1 addition & 16 deletions .github/workflows/publishImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,8 @@ on:

jobs:
test:
name: Run Tests
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dev dependencies
run: npm ci
- name: Build Backend
run: 'npm run build:backend'
- name: Test Backend
run: npm run test
uses: ./.github/workflows/testAndSanity.yml

push_to_registry:
name: Build and push container images
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/testAndSanity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Tests and Sanity Run

on:
workflow_call:
inputs:
node-version:
description: "Node version"
required: false
default: '18.x'
type: string

jobs:
test:
name: Tests / Build / Sanity Run
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: 'npm'

- name: Install dev dependencies
run: npm ci
- name: Test Backend
run: npm run test

- name: Install Docs Deps
run: NODE_ENV=production npm run docs:install
- name: Build
run: NODE_ENV=production npm run build

# remove modules that might include dev stuff
# so that in the next step we are sure that prod-only runs work correctly
- name: Install Prod Deps
run: |
rm -rf node_modules && \
rm -rf docsite/node_modules && \
NODE_ENV=production npm ci --omit=dev
# run app for 10 seconds as sanity check to see if it errors for any reason
# easy testcase for missing packages and init errors
- name: Sanity Run
run: |
set +e
export NODE_ENV=production
timeout --preserve-status 10s node node_modules/.bin/tsx src/backend/index.ts
exitcode="$?"
if [[ "$exitcode" -eq 143 ]] || [[ "$exitcode" -eq 137 ]]; then
echo "App stayed up long enough and exited with expected status"
exit 0
else
echo "App exited with unexpected code $exitcode"
exit "$exitcode"
fi

0 comments on commit 1b0e7a3

Please sign in to comment.