106 lines
3.4 KiB
YAML
106 lines
3.4 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main, master]
|
|
pull_request:
|
|
branches: [main, master]
|
|
|
|
jobs:
|
|
build-and-test:
|
|
runs-on: ubuntu-latest
|
|
container: node:20-bookworm
|
|
services:
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
env:
|
|
POSTGRES_DB: calendar_run_test
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: postgres
|
|
options: >-
|
|
--health-cmd "pg_isready -U postgres -d calendar_run_test"
|
|
--health-interval 5s
|
|
--health-timeout 5s
|
|
--health-retries 10
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
persist-credentials: false
|
|
- name: Backend — install, build, test
|
|
working-directory: backend
|
|
env:
|
|
NODE_ENV: test
|
|
DB_HOST: postgres
|
|
DB_PORT: "5432"
|
|
DB_NAME: calendar_run_test
|
|
DB_USER: postgres
|
|
DB_PASSWORD: postgres
|
|
SESSION_SECRET: test-session-secret
|
|
TURNSTILE_BYPASS_TOKEN: mock-turnstile-token
|
|
run: |
|
|
npm ci
|
|
npm run build
|
|
npm test
|
|
|
|
- name: Frontend — install, build
|
|
working-directory: frontend
|
|
run: |
|
|
npm ci
|
|
npm run build
|
|
|
|
images:
|
|
if: github.server_url == 'https://git.vakanaut.ru'
|
|
needs: build-and-test
|
|
runs-on: home-build
|
|
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: Check Docker image build
|
|
if: github.event_name == 'pull_request'
|
|
shell: bash
|
|
run: docker buildx build --file "$DOCKERFILE" --load .
|
|
|
|
- name: Publish Docker image and record its digest
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'admin/runners-calendar'
|
|
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/runners-calendar-$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
|