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
This commit is contained in:
2 files changed
+54
-21
No files matched your search
+49
-18
@@ -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 }}
|
||||
|
||||
Reference in new issue
Block a user