diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..69db14c --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,57 @@ +name: CI + +on: + pull_request: + branches: [main] + types: [edited] + +jobs: + verify: + if: >- + contains(github.event.pull_request.body, format('CI-Head: {0}', github.event.pull_request.head.sha)) + runs-on: ubuntu-latest + container: node:20-bookworm + services: + postgres: + image: postgres:16-alpine + env: + POSTGRES_DB: family_budget_test + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd "pg_isready -U postgres -d family_budget_test" + --health-interval 5s + --health-timeout 5s + --health-retries 10 + env: + NODE_ENV: test + DB_HOST: postgres + DB_PORT: "5432" + DB_NAME: family_budget_test + DB_USER: postgres + DB_PASSWORD: postgres + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Install dependencies and build + run: | + npm ci --include=dev + npm run build -w @family-budget/shared + npm run build -w @family-budget/backend + npm run build -w @family-budget/frontend + - name: Run backend and frontend tests + run: | + npm run migrate -w @family-budget/backend + npm run -w @family-budget/backend test:analytics + npm run -w @family-budget/backend test:analytics:query + npm run -w @family-budget/backend test:analytics:db + npm run -w @family-budget/backend test:portfolio + npm run -w @family-budget/backend test:portfolio:overview + npm run -w @family-budget/backend test:portfolio:moex + npm run -w @family-budget/backend test:portfolio:db + npm run -w @family-budget/backend test:transactions + npm run -w @family-budget/backend test:import:direction + npm run -w @family-budget/backend test:import:db + npm run -w @family-budget/backend test:broker:xlsx + npm run -w @family-budget/frontend test:portfolio diff --git a/.gitea/workflows/publish.yml b/.gitea/workflows/publish.yml new file mode 100644 index 0000000..7ec78d9 --- /dev/null +++ b/.gitea/workflows/publish.yml @@ -0,0 +1,55 @@ +name: Publish images + +on: + push: + branches: [main] + +jobs: + images: + if: github.server_url == 'https://git.vakanaut.ru' && github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'admin/family_budget' + runs-on: home-publish + strategy: + matrix: + include: + - component: backend + dockerfile: Dockerfile.backend + - component: frontend + dockerfile: Dockerfile.frontend + env: + REGISTRY: git.vakanaut.ru + COMPONENT: ${{ matrix.component }} + DOCKERFILE: ${{ matrix.dockerfile }} + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Publish Docker image and record its digest + shell: bash + env: + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} + REGISTRY_OWNER: ${{ vars.REGISTRY_OWNER }} + run: | + set -euo pipefail + : "${REGISTRY_USERNAME:?set REGISTRY_USERNAME}" + : "${REGISTRY_TOKEN:?set REGISTRY_TOKEN}" + owner="${REGISTRY_OWNER:-$REGISTRY_USERNAME}" + [[ "$owner" =~ ^[a-z0-9][a-z0-9_-]*$ ]] + + export DOCKER_CONFIG + DOCKER_CONFIG="$(mktemp -d)" + metadata="$(mktemp)" + trap 'rm -rf -- "$DOCKER_CONFIG"; rm -f -- "$metadata"' EXIT + + image="$REGISTRY/$owner/family-budget-$COMPONENT" + printf '%s\n' "$REGISTRY_TOKEN" | docker login "$REGISTRY" --username "$REGISTRY_USERNAME" --password-stdin + docker buildx build --file "$DOCKERFILE" --tag "$image:$GITHUB_SHA" \ + --label "org.opencontainers.image.revision=$GITHUB_SHA" \ + --label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ + --metadata-file "$metadata" --push . + + digest="$(jq -er '."containerimage.digest" | select(test("^sha256:[a-f0-9]{64}$"))' "$metadata")" + printf '%s\n' "$image@$digest" + if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then + printf '%s\n' "$image@$digest" >> "$GITHUB_STEP_SUMMARY" + fi diff --git a/CHANGELOG.md b/CHANGELOG.md index f8abac5..f9f6016 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- CI builds and tests the final pull request commit before merge. A separate workflow publishes backend and frontend images after merge to main. + ## [Backend 0.15.6] - 2026-08-29 ### Fixed