From e577ee868378cb20c3736d415fe0b46b552847c6 Mon Sep 17 00:00:00 2001 From: Andrii Arsenin Date: Thu, 1 Oct 2026 12:26:57 +0300 Subject: [PATCH] ci: skip unaffected jobs and rebuilt image versions - 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 --- .gitea/workflows/ci.yml | 67 ++++++++++++++++++++++++++++++----------- docs/development.md | 8 +++-- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 4d21e61..8b650ce 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -1,7 +1,9 @@ -# Code quality checks on master and pull requests. On a push to master that -# changes the version in the root package.json, also builds the Docker image -# and pushes it to this Gitea instance's container registry, tagged with that -# version and `latest`. +# 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 @@ -19,7 +21,31 @@ 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 @@ -38,6 +64,8 @@ jobs: run: npm run -w server build client: + needs: changes + if: needs.changes.outputs.client == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -55,7 +83,7 @@ jobs: - name: Storybook tests 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: if: github.event_name == 'push' runs-on: ubuntu-latest @@ -64,28 +92,31 @@ jobs: changed: ${{ steps.check.outputs.changed }} steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - id: check env: - BEFORE: ${{ github.event.before }} + REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} + OWNER: ${{ github.repository_owner }} run: | version=$(node -p "require('./package.json').version") - previous="" - if git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then - previous=$(git show "${BEFORE}:package.json" | node -p "JSON.parse(require('fs').readFileSync(0, 'utf8')).version") - fi - echo "version: ${previous:-none} -> ${version}" - echo "version=${version}" >> "$GITHUB_OUTPUT" - if [ "$version" != "$previous" ]; then - echo "changed=true" >> "$GITHUB_OUTPUT" - else + 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] - 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 env: VERSION: ${{ needs.version.outputs.version }} diff --git a/docs/development.md b/docs/development.md index 8841268..a59809a 100644 --- a/docs/development.md +++ b/docs/development.md @@ -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: -- **server**: lint (no warnings allowed), type-check, tests, build. -- **client**: lint (no warnings allowed), build, Storybook tests in headless Chromium. -- **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 `//:` and `:latest`. +- **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. +- **server** (skipped if nothing under `server/` changed): lint (no warnings allowed), type-check, tests, build. +- **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 `//:` 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 `//:` 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).