photos/.forgejo/workflows/deploy.yml

76 lines
2.9 KiB
YAML

name: Check & deploy
on:
push:
workflow_dispatch:
jobs:
validate:
outputs:
publish: ${{ steps.validated_build.outcome }}
env:
PHOTO_ASSET_CACHE_URL: https://photos.schmelczer.dev/static/photos/
runs-on: docker
# Superseded validation runs can be cancelled freely.
concurrency:
group: 'photos-validate-${{ github.ref }}'
cancel-in-progress: true
steps:
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
persist-credentials: false
- name: Setup Node
uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
with:
node-version-file: .nvmrc
- name: Install dependencies
run: npm ci
- name: Lint and static checks
run: npm run lint:check
- name: Unit tests
run: npm test
- name: Build
run: npm run build
- name: Install Playwright browser
run: npx playwright install --with-deps --only-shell chromium
- name: End-to-end smoke test
env:
PLAYWRIGHT_USE_EXISTING_BUILD: '1'
run: npm run test:e2e
- name: Save validated build
id: validated_build
if: ${{ github.ref == 'refs/heads/main' }}
uses: https://github.com/actions/upload-artifact@ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5
with:
name: pages-deploy-0
path: dist
if-no-files-found: error
retention-days: 1
deploy:
runs-on: docker
needs: validate
# The upload step evaluates the trusted-main condition on the runner. Pass
# its result to Forgejo's dependent-job scheduler instead of repeating it.
if: ${{ needs.validate.outputs.publish == 'success' }}
steps:
# The Pages copier reads artifacts for this run after this job succeeds.
# Confirm the tested artifact instead of transferring the photos again.
- name: Release validated site to Pages
env:
ARTIFACTS_URL: ${{ github.api_url }}/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts
ARTIFACT_TOKEN: ${{ github.token }}
run: |
node --input-type=module <<'JS'
const response = await fetch(process.env.ARTIFACTS_URL, {
headers: { Authorization: `token ${process.env.ARTIFACT_TOKEN}` },
signal: AbortSignal.timeout(10_000),
});
if (!response.ok) throw new Error(`Artifact lookup failed: HTTP ${response.status}`);
const artifacts = await response.json();
const site = artifacts.find((artifact) =>
artifact.name === 'pages-deploy-0' && !artifact.expired &&
String(artifact.run_id) === process.env.GITHUB_RUN_ID
);
if (!site) throw new Error('The validated site artifact is missing.');
console.log(`Validated artifact ${site.id} is ready for the Pages copier.`);
JS