ci: add gitea actions for quality checks and versioned images
- run server lint, type-check, tests and build, and client lint, build and storybook tests on master and pull requests - when a push to master changes the package.json version, build the docker image and push it to the gitea registry tagged with the version and latest - document the workflow and the REGISTRY_TOKEN secret
This commit is contained in:
1 parent
8d8aed7b87
commit
b15fe56e70
2 files changed
+115
No files matched your search
@@ -0,0 +1,103 @@
|
||||
# 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`.
|
||||
#
|
||||
# Needs a repository (or owner) secret REGISTRY_TOKEN: a Gitea access token
|
||||
# with package write access for the repository owner.
|
||||
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
server:
|
||||
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:
|
||||
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
|
||||
|
||||
# Compares the root package.json version with the one before the push
|
||||
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
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- id: check
|
||||
env:
|
||||
BEFORE: ${{ github.event.before }}
|
||||
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
|
||||
echo "changed=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
image:
|
||||
needs: [server, client, version]
|
||||
if: needs.version.outputs.changed == 'true'
|
||||
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: |
|
||||
registry="${GITHUB_SERVER_URL#*://}"
|
||||
echo "REGISTRY=${registry}" >> "$GITHUB_ENV"
|
||||
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 -t "${IMAGE}:${VERSION}" -t "${IMAGE}:latest" .
|
||||
- name: Push
|
||||
run: |
|
||||
docker push "${IMAGE}:${VERSION}"
|
||||
docker push "${IMAGE}:latest"
|
||||
@@ -218,6 +218,18 @@ docker compose build --no-cache
|
||||
|
||||
---
|
||||
|
||||
## CI (Gitea Actions)
|
||||
|
||||
`.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 instance's container registry as `<gitea host>/<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).
|
||||
|
||||
---
|
||||
|
||||
## Running with Docker Compose
|
||||
|
||||
Start (detached):
|
||||
|
||||
Reference in new issue
Block a user