Run tests and deploy in one Gitea Actions job
Test and deploy / test-and-deploy (pull_request) Successful in 33s
Test and deploy / test-and-deploy (pull_request) Successful in 33s
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:
2 files changed
+41
-25
No files matched your search
+23
-21
@@ -13,23 +13,12 @@ on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
- run: npm ci
|
||||
- run: npx tsc --noEmit
|
||||
# Unit tests only. The integration tests (npm run test:integration) start their own MariaDB
|
||||
# container and aren't run here.
|
||||
# FEEDBACK_IP_SALT (which the Jenkins job exported) isn't needed: vitest.config.ts sets one.
|
||||
- run: npm test
|
||||
|
||||
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 and running `npm ci` twice (~2 min each, 2026-11-08). The deploy steps only run
|
||||
# for pushes to master; on pull requests the job ends after the tests. 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 }}
|
||||
@@ -45,11 +34,22 @@ jobs:
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
- run: npm ci
|
||||
- run: npm run build
|
||||
- run: npx tsc --noEmit
|
||||
# Unit tests only. The integration tests (npm run test:integration) start their own MariaDB
|
||||
# container and aren't run here.
|
||||
# FEEDBACK_IP_SALT (which the Jenkins job exported) isn't needed: vitest.config.ts sets one.
|
||||
- run: npm test
|
||||
|
||||
- name: Build
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
run: npm run build
|
||||
# Only runtime dependencies go to the server (no typescript, vitest, ...).
|
||||
- run: npm prune --omit=dev
|
||||
- name: Prune dev dependencies
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
run: npm prune --omit=dev
|
||||
|
||||
- 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 }}
|
||||
@@ -65,6 +65,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: |
|
||||
rsh="ssh -p ${DEPLOY_PORT:-22} -i $SSH_DIR/key -o UserKnownHostsFile=$SSH_DIR/known_hosts -o IdentitiesOnly=yes -o BatchMode=yes"
|
||||
target="$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH"
|
||||
@@ -78,6 +79,7 @@ jobs:
|
||||
rsync -az -e "$rsh" package.json package-lock.json "$target/"
|
||||
|
||||
- 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" \
|
||||
@@ -87,7 +89,7 @@ jobs:
|
||||
# Set DEPLOY_SMOKE_URL to an endpoint that must answer 200 without a session, e.g.
|
||||
# https://api.nachklang.art/calendar/events/public/json (what nachklang.art itself reads).
|
||||
- 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: |
|
||||
@@ -100,5 +102,5 @@ jobs:
|
||||
exit 1
|
||||
|
||||
- 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