Files
budget2.0/.gitea/workflows/ci.yml
T
Lucas Winther f02c452d6c
Continuous Integration / lint-and-test (push) Successful in 13s
Continuous Integration / docker-build-and-push (push) Successful in 35s
fix: nest legacy bills and stamp builds with commit
2026-09-30 14:35:29 +02:00

97 lines
3.0 KiB
YAML

name: Continuous Integration
on:
push:
branches: [main]
tags: ['v*']
pull_request:
branches: [main]
env:
REGISTRY: gitea.lucaswinther.info
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Typecheck
run: bunx tsc --noEmit
- name: Run test suite
run: bun test
- name: Build app
run: bun run build
docker-build-and-push:
runs-on: ubuntu-latest
needs: [lint-and-test]
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Gitea's job token cannot publish packages; use a package-write PAT.
- name: Log in to Gitea Container Registry
if: gitea.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ gitea.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=semver,pattern={{version}}
type=sha,prefix=sha-
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
build-args: |
BUILD_VERSION=${{ gitea.sha }}
BUILD_REPOSITORY=https://gitea.lucaswinther.info/${{ gitea.repository }}
push: ${{ gitea.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Pull and smoke-test published image
if: gitea.event_name != 'pull_request'
env:
PUBLISHED_TAGS: ${{ steps.meta.outputs.tags }}
run: |
image="$(printf '%s\n' "$PUBLISHED_TAGS" | head -n 1)"
docker pull "$image"
docker run -d --rm --name budget2-ci "$image"
trap 'docker stop budget2-ci' EXIT
docker exec budget2-ci bun -e '
const base = "http://127.0.0.1:3000";
let ready = false;
for (let attempt = 0; attempt < 30; attempt++) {
try {
const response = await fetch(base + "/");
if (response.ok && (await response.text()).includes("Budget")) {
ready = true;
break;
}
} catch {}
await Bun.sleep(1000);
}
if (!ready) throw new Error("App did not serve its HTML");
for (const path of ["/sw.js", "/manifest.webmanifest"]) {
const response = await fetch(base + path);
if (!response.ok) throw new Error(`${path} returned ${response.status}`);
}
'