Notes
Triggers
The file lives in dot github slash workflows. The on section lists triggers: every pull request, every push to main, a nightly schedule written as cron, here two seventeen in the morning UTC, and workflow dispatch, which adds a run button in the GitHub interface. Then come jobs. Each job runs on a fresh virtual machine, so nothing leaks between runs.
name: tests
on:
pull_request:
push:
branches: [main]
schedule:
- cron: "17 2 * * *" # nightly
workflow_dispatch: # a Run button
jobs:
api: ... Start the app
The API job runs on Ubuntu with a fifteen minute timeout, so a hung test cannot burn hours. Steps run in order. Checkout fetches the code. Setup node installs Node twenty two. Then ShopRung starts in the background, with its output saved to a log file, and wait on polls the health endpoint until the shop answers, up to a minute. Never use a fixed sleep here; wait for the health check.
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 22 }
- name: Start ShopRung
working-directory: shoprung
run: |
npm start > shoprung.log 2>&1 &
npx --yes wait-on@8 http-get://... Run the suite
Next, setup python installs Python three point twelve, and its cache option keeps downloaded packages between runs, which saves time on every pull request. The API tests step installs the pinned requirements and runs pytest with a JUnit XML report. If any test fails, pytest exits with an error, the step fails, the job fails, and GitHub marks the check red.
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: API tests
working-directory: api-tests
run: |
pip install -r requirements.txt
pytest --junitxml=results/api.xml Artifacts
A failed step normally stops the job, so the upload step says if always: run it whatever happened. Upload artifact stores the JUnit report and ShopRung's own log with the run, where anyone can download them. The application's log is often the fastest way to understand a failing API test: it shows the error from the server side.
- name: Keep results and logs
if: always()
uses: actions/upload-artifact@v4
with:
name: api-results
path: |
api-tests/results/
shoprung/shoprung.log Matrix
The UI job needs the API job: it only starts if the API tests passed, which saves expensive browser minutes when the basics are broken. A matrix runs the same job once per browser, Chromium and Firefox, in parallel. Fail fast false keeps the other browser running when one fails, so you see the full picture. Each copy installs its browser with its system libraries, then runs only that browser's Playwright project.
ui:
needs: api
strategy:
fail-fast: false
matrix:
browser: [chromium, firefox]
steps: ... start ShopRung ...
- run: npx playwright install
--with-deps ${{ matrix.browser }}
- run: npx playwright test
--project=${{ matrix.browser }} Secrets
Real credentials never go in the file. They are stored as repository secrets in GitHub's settings and passed to a step as environment variables; GitHub masks them in logs. ShopRung's practice passwords are public, but the habit matters. On failure, the Playwright report with its traces is uploaded per browser and kept for fourteen days.
- run: npx playwright test ...
env:
ALICE_PASSWORD:
${{ secrets.ALICE_PASSWORD }}
- if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-report-
${{ matrix.browser }}
path: e2e/playwright-report/
retention-days: 14 Block bad merges
A workflow only reports. To stop broken code, protect the main branch in the repository settings: require pull requests, and require the status checks to pass, here the API job and both UI matrix jobs. Then a red check blocks the merge button. This is where tests turn into a quality gate, which a later episode covers in depth.
- branch protection (or rulesets) on main: require a pull request require status checks: api, ui (chromium), ui (firefox) require branches up to date
- red check → the Merge button is blocked
Check it before pushing
A few habits. Run actionlint on workflow files before pushing; it catches syntax and expression mistakes, and the workflow in this episode passes it. Pin action versions. Cache dependencies. Put a timeout on every job. And keep slow suites for the nightly run by checking the event name in an if condition, so pull requests stay fast.
- actionlint: checks syntax and expressions before you push (this file passes it)
- pin action versions (@v4)
- cache dependencies
- timeouts on every job
- run the slow nightly suite only on schedule: if: github.event_name == 'schedule'
Common mistakes
Mistakes. Sleep thirty instead of waiting for a health check. Secrets written into the YAML. Uploading artifacts only when everything passed, which is exactly when nobody needs them. No timeout, so a hung test runs for hours. Every suite on every pull request. And checks that are not required, so red pull requests can still be merged.
- sleep 30 instead of a health check
- secrets in the YAML
- artifacts only on success
- no timeout (hung job, hours)
- every suite on every PR
- checks not required, so red PRs still merge
Say it like this
In the interview: a workflow triggered by pull requests, pushes to main and a nightly schedule. Each job checks out the code, sets up Node or Python with caching, starts the app and waits for its health check, runs the suite with a JUnit report, and uploads results, traces and the app's logs even on failure. UI tests use a browser matrix, secrets come from repository settings, and branch protection makes the checks required.
- "A workflow on PRs, main and nightly. Each job checks out, sets up Node or Python with caching, starts the app and waits on its health check, runs
- the suite with a JUnit report, and uploads results, traces and app logs with if: always(). UI
- uses a browser matrix; secrets
- from settings; checks required."