Run tests and deploy in one Gitea Actions job
Test and deploy / test-and-deploy (pull_request) Successful in 2m25s
Test and deploy / test-and-deploy (pull_request) Successful in 2m25s
Two jobs meant checking out, setting up Node and running npm ci (and in the frontend the build) twice, about two minutes each, because every job starts in a fresh container. Now one job tests and, for pushes to master only, deploys. The push-to-master condition is spelled out on every deploy step instead of an env flag compared to 'true', which would skip the deploy silently and stay green if the boolean were rendered differently. A failed test still stops the deploy (an if: without a status function implies success()). Docs: the one-job layout, and that Jenkins deployed as root - files it left in an app folder must be chowned to the subscription user before the first Gitea deploy (hit on the API). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
3 files changed
+34
-29
No files matched your search
+18
-24
@@ -12,28 +12,12 @@ on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
# Same major as Passenger on the server (26.13.0 as of 2026-11-08).
|
||||
node-version-file: .nvmrc
|
||||
- run: npm ci
|
||||
- run: npm run lint
|
||||
- run: npx tsc --noEmit
|
||||
- run: npm test
|
||||
# Proves the production build works, with the production values: NEXT_PUBLIC_* are inlined
|
||||
# at build time, and lib/env.ts fails the build if one is missing.
|
||||
- run: npm run build
|
||||
env:
|
||||
NEXT_PUBLIC_API_BASE_URL: ${{ vars.NEXT_PUBLIC_API_BASE_URL }}
|
||||
NEXT_PUBLIC_ADMIN_APP_URL: ${{ vars.NEXT_PUBLIC_ADMIN_APP_URL }}
|
||||
|
||||
deploy:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
# One job, not test + deploy: every job starts in a fresh container, so two jobs meant checking out,
|
||||
# setting up Node, `npm ci` and building twice (~2 min each, 2026-11-08). The deploy steps only run
|
||||
# for pushes to master; on pull requests the job ends after the build. The condition is spelled out
|
||||
# on every deploy step rather than stored in an env flag: a flag compared as a string ('true') would
|
||||
# skip the deploy silently - and green - if the runner ever rendered the boolean differently.
|
||||
test-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
|
||||
@@ -48,8 +32,14 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
# Same major as Passenger on the server (26.13.0 as of 2026-11-08).
|
||||
node-version-file: .nvmrc
|
||||
- run: npm ci
|
||||
- run: npm run lint
|
||||
- run: npx tsc --noEmit
|
||||
- run: npm test
|
||||
# The production build, with the production values: NEXT_PUBLIC_* are inlined at build time,
|
||||
# and lib/env.ts fails the build if one is missing. On master this is also what gets deployed.
|
||||
- name: Build
|
||||
run: npm run build
|
||||
env:
|
||||
@@ -60,9 +50,11 @@ jobs:
|
||||
# own there (server.js serves .next/static), so an empty public/ is enough. Created here so
|
||||
# rsync --delete doesn't remove it on the server.
|
||||
- name: Prepare bundle
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
run: mkdir -p .next/standalone/public
|
||||
|
||||
- name: SSH setup
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
env:
|
||||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
|
||||
@@ -79,6 +71,7 @@ jobs:
|
||||
printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$SSH_DIR/known_hosts"
|
||||
|
||||
- name: Upload
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
run: |
|
||||
# Straight into the app folder (no release folders - decided 2026-11-08; a rollback is a
|
||||
# redeploy of an older commit). That folder is the one Plesk created for the subdomain,
|
||||
@@ -89,6 +82,7 @@ jobs:
|
||||
.next/standalone/ "$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/"
|
||||
|
||||
- name: Restart
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
run: |
|
||||
# Passenger restarts the app on its next request when tmp/restart.txt is touched.
|
||||
ssh -p "${DEPLOY_PORT:-22}" -i "$SSH_DIR/key" -o "UserKnownHostsFile=$SSH_DIR/known_hosts" \
|
||||
@@ -98,7 +92,7 @@ jobs:
|
||||
# Optional until Plesk serves the Node app: set DEPLOY_SMOKE_URL then. Checks the page loads
|
||||
# and references the build's static files (the classic standalone failure is missing CSS/JS).
|
||||
- name: Smoke test
|
||||
if: vars.DEPLOY_SMOKE_URL != ''
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && vars.DEPLOY_SMOKE_URL != ''
|
||||
env:
|
||||
DEPLOY_SMOKE_URL: ${{ vars.DEPLOY_SMOKE_URL }}
|
||||
run: |
|
||||
@@ -112,5 +106,5 @@ jobs:
|
||||
echo "OK: page and $asset served"
|
||||
|
||||
- name: Remove key
|
||||
if: always()
|
||||
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
run: rm -f "$SSH_DIR/key"
|
||||
Reference in new issue
Block a user