ci: skip unaffected jobs and rebuilt image versions
CI / changes (pull_request) Successful in 11s
CI / version (pull_request) Skipped
CI / server (pull_request) Successful in 1m10s
CI / client (pull_request) Successful in 1m23s
CI / image (pull_request) Skipped

- server and client jobs only run when their directory (or shared
  root files) changed, via a new changes job using dorny/paths-filter
- the version job now checks the registry for an existing image tag
  of the current package.json version instead of diffing against the
  previous commit's package.json, so the image job is skipped once
  that version has already been pushed
- the image job tolerates server/client being skipped rather than
  requiring both to succeed
This commit is contained in:
ars9 committed 2026-10-01 12:26:57 +03:00
1 parent 0e998333e0
commit e577ee8683
2 files changed
+54 -21

No files matched your search

+49 -18
View File
@@ -1,7 +1,9 @@
# Code quality checks on master and pull requests. On a push to master that # Code quality checks on master and pull requests. The server and client jobs
# changes the version in the root package.json, also builds the Docker image # only run when their directory (or shared root files) changed. On a push to
# and pushes it to this Gitea instance's container registry, tagged with that # master, also builds the Docker image and pushes it to this Gitea instance's
# version and `latest`. # 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 # Needs a repository (or owner) secret REGISTRY_TOKEN: a Gitea access token
# with package write access for the repository owner. The registry host is # with package write access for the repository owner. The registry host is
@@ -19,7 +21,31 @@ env:
REGISTRY: git.hq.ars9.space REGISTRY: git.hq.ars9.space
jobs: 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: server:
needs: changes
if: needs.changes.outputs.server == 'true'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@@ -38,6 +64,8 @@ jobs:
run: npm run -w server build run: npm run -w server build
client: client:
needs: changes
if: needs.changes.outputs.client == 'true'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@@ -55,7 +83,7 @@ jobs:
- name: Storybook tests - name: Storybook tests
run: npm run -w client test:storybook run: npm run -w client test:storybook
# Compares the root package.json version with the one before the push # Skips the image job if the registry already has this version's image
version: version:
if: github.event_name == 'push' if: github.event_name == 'push'
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -64,28 +92,31 @@ jobs:
changed: ${{ steps.check.outputs.changed }} changed: ${{ steps.check.outputs.changed }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with:
fetch-depth: 0
- id: check - id: check
env: env:
BEFORE: ${{ github.event.before }} REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
OWNER: ${{ github.repository_owner }}
run: | run: |
version=$(node -p "require('./package.json').version") version=$(node -p "require('./package.json').version")
previous="" image="${REGISTRY}/$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')"
if git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then echo "$REGISTRY_TOKEN" | docker login "$REGISTRY" -u "$OWNER" --password-stdin
previous=$(git show "${BEFORE}:package.json" | node -p "JSON.parse(require('fs').readFileSync(0, 'utf8')).version") if docker manifest inspect "${image}:${version}" >/dev/null 2>&1; then
fi echo "version ${version}: image already in registry, skipping"
echo "version: ${previous:-none} -> ${version}"
echo "version=${version}" >> "$GITHUB_OUTPUT"
if [ "$version" != "$previous" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT" echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "version ${version}: not in registry, building"
echo "changed=true" >> "$GITHUB_OUTPUT"
fi fi
echo "version=${version}" >> "$GITHUB_OUTPUT"
image: image:
needs: [server, client, version] needs: [server, client, version]
if: needs.version.outputs.changed == 'true' # server/client may be skipped when their paths didn't change
if: |
!failure() && !cancelled() &&
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 runs-on: ubuntu-latest
env: env:
VERSION: ${{ needs.version.outputs.version }} VERSION: ${{ needs.version.outputs.version }}
+5 -3
View File
@@ -245,9 +245,11 @@ Before adding a dependency, check its license is compatible with MIT distributio
`.gitea/workflows/ci.yml` runs on pushes to `master` and on pull requests: `.gitea/workflows/ci.yml` runs on pushes to `master` and on pull requests:
- **server**: lint (no warnings allowed), type-check, tests, build. - **changes**: detects which of `server/` and `client/` changed (via `dorny/paths-filter`), also treating root `package.json`/`package-lock.json` and the workflow file itself as affecting both.
- **client**: lint (no warnings allowed), build, Storybook tests in headless Chromium. - **server** (skipped if nothing under `server/` changed): lint (no warnings allowed), type-check, tests, build.
- **image** (pushes to `master` only): when the push changes `version` in the root `package.json`, and both check jobs pass, builds the Docker image and pushes it to the Gitea container registry set by `REGISTRY` at the top of the workflow (`git.hq.ars9.space`) as `<registry>/<owner>/<repo>:<version>` and `:latest`. - **client** (skipped if nothing under `client/` changed): lint (no warnings allowed), build, Storybook tests in headless Chromium.
- **version** (pushes to `master` only): reads `version` from the root `package.json` and checks the registry for an existing `<registry>/<owner>/<repo>:<version>` image; skips the image job if that tag is already present.
- **image** (pushes to `master` only): when the version job found no existing image for the current version, and the server/client jobs passed or were skipped, builds the Docker image and pushes it to the Gitea container registry set by `REGISTRY` at the top of the workflow (`git.hq.ars9.space`) as `<registry>/<owner>/<repo>:<version>` and `:latest`.
The image job logs in as the repository owner with the `REGISTRY_TOKEN` secret: a Gitea access token with package write access (Settings → Applications → token with `write:package`), added under the repository's Settings → Actions → Secrets. It runs `docker` on the runner, so the runner must give jobs access to a Docker daemon (act_runner mounts the host's Docker socket into job containers by default). The image job logs in as the repository owner with the `REGISTRY_TOKEN` secret: a Gitea access token with package write access (Settings → Applications → token with `write:package`), added under the repository's Settings → Actions → Secrets. It runs `docker` on the runner, so the runner must give jobs access to a Docker daemon (act_runner mounts the host's Docker socket into job containers by default).