- defense in depth alongside the version job's existing push-only condition, so the image job can't run on pull requests
139 lines
4.7 KiB
YAML
139 lines
4.7 KiB
YAML
# Code quality checks on master and pull requests. The server and client jobs
|
|
# only run when their directory (or shared root files) changed. On a push to
|
|
# master, also builds the Docker image and pushes it to this Gitea instance's
|
|
# container registry, tagged with the root package.json version and `latest`
|
|
# - unless that version's image already exists in the registry, in which case
|
|
# the push is skipped.
|
|
#
|
|
# Needs a repository (or owner) secret REGISTRY_TOKEN: a Gitea access token
|
|
# with package write access for the repository owner. The registry host is
|
|
# set explicitly below rather than taken from the server URL, which is the
|
|
# address the runner was registered with and may be internal-only.
|
|
|
|
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
pull_request:
|
|
|
|
env:
|
|
REGISTRY: git.hq.ars9.space
|
|
|
|
jobs:
|
|
changes:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
server: ${{ steps.filter.outputs.server }}
|
|
client: ${{ steps.filter.outputs.client }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: dorny/paths-filter@v3
|
|
id: filter
|
|
with:
|
|
filters: |
|
|
server:
|
|
- 'server/**'
|
|
- 'package.json'
|
|
- 'package-lock.json'
|
|
- '.gitea/workflows/ci.yml'
|
|
client:
|
|
- 'client/**'
|
|
- 'package.json'
|
|
- 'package-lock.json'
|
|
- '.gitea/workflows/ci.yml'
|
|
|
|
server:
|
|
needs: changes
|
|
if: needs.changes.outputs.server == 'true'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 24
|
|
cache: npm
|
|
- run: npm ci -w server
|
|
- name: Lint
|
|
run: npm run -w server lint -- --max-warnings=0
|
|
- name: Type-check
|
|
run: npx tsc --noEmit -p server/tsconfig.json
|
|
- name: Test
|
|
run: npm test -w server
|
|
- name: Build
|
|
run: npm run -w server build
|
|
|
|
client:
|
|
needs: changes
|
|
if: needs.changes.outputs.client == 'true'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 24
|
|
cache: npm
|
|
- run: npm ci -w client
|
|
- name: Lint
|
|
run: npm run -w client lint -- --max-warnings=0
|
|
- name: Build
|
|
run: npm run -w client build
|
|
- name: Install headless Chromium for Storybook tests
|
|
run: npx playwright install --with-deps --only-shell chromium
|
|
- name: Storybook tests
|
|
run: npm run -w client test:storybook
|
|
|
|
# Skips the image job if the registry already has this version's image
|
|
version:
|
|
if: github.event_name == 'push'
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
version: ${{ steps.check.outputs.version }}
|
|
changed: ${{ steps.check.outputs.changed }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- id: check
|
|
env:
|
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
OWNER: ${{ github.repository_owner }}
|
|
run: |
|
|
version=$(node -p "require('./package.json').version")
|
|
image="${REGISTRY}/$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')"
|
|
echo "$REGISTRY_TOKEN" | docker login "$REGISTRY" -u "$OWNER" --password-stdin
|
|
if docker manifest inspect "${image}:${version}" >/dev/null 2>&1; then
|
|
echo "version ${version}: image already in registry, skipping"
|
|
echo "changed=false" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "version ${version}: not in registry, building"
|
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
echo "version=${version}" >> "$GITHUB_OUTPUT"
|
|
|
|
image:
|
|
needs: [server, client, version]
|
|
# server/client may be skipped when their paths didn't change
|
|
if: |
|
|
!failure() && !cancelled() &&
|
|
github.event_name == 'push' &&
|
|
needs.version.outputs.changed == 'true' &&
|
|
(needs.server.result == 'success' || needs.server.result == 'skipped') &&
|
|
(needs.client.result == 'success' || needs.client.result == 'skipped')
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
VERSION: ${{ needs.version.outputs.version }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Log in to the registry
|
|
env:
|
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
OWNER: ${{ github.repository_owner }}
|
|
run: |
|
|
echo "IMAGE=${REGISTRY}/$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
|
|
echo "$REGISTRY_TOKEN" | docker login "$REGISTRY" -u "$OWNER" --password-stdin
|
|
- name: Build
|
|
run: docker build --build-arg VERSION="${VERSION}" -t "${IMAGE}:${VERSION}" -t "${IMAGE}:latest" .
|
|
- name: Push
|
|
run: |
|
|
docker push "${IMAGE}:${VERSION}"
|
|
docker push "${IMAGE}:latest"
|