Files
mtusi2026lab4/.gitea/workflows/ci.yml
T

94 lines
3.0 KiB
YAML

name: CI
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
concurrency:
group: ci-${{ github.repository }}-${{ github.ref }}
cancel-in-progress: true
jobs:
verify:
runs-on: ubuntu-latest
timeout-minutes: 45
env:
COMPOSE_PROJECT_NAME: mtusi2026lab4-${{ github.run_id }}
API_BIND_ADDRESS: 127.0.0.1:0
SWAGGER_BIND_ADDRESS: 127.0.0.1:0
PROMETHEUS_BIND_ADDRESS: 127.0.0.1:0
GRAFANA_BIND_ADDRESS: 127.0.0.1:0
steps:
- name: Checkout exact commit
run: |
git init .
git remote add origin https://gitea.privcloud.tech/${{ github.repository }}.git
git fetch --depth=1 origin ${{ github.sha }}
git checkout --detach FETCH_HEAD
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false
- name: Check contract
run: make check
- name: Validate OpenAPI
run: |
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements-dev.txt
make validate PYTHON=.venv/bin/python
- name: Check formatting and shell scripts
run: |
test -z "$(gofmt -l cmd internal migrations)"
sh -n infra/minio/bootstrap.sh scripts/restart.sh scripts/rolling-update.sh scripts/stop-one.sh
- name: Lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.13.2
args: --timeout=5m
skip-cache: true
- name: Unit tests and build
run: |
go test -race ./...
go build ./cmd/...
- name: Prepare local stack
run: |
cp lab4.env.example .env
docker compose config --quiet
docker compose up -d --build --scale api=2 --wait --wait-timeout 150
docker network connect "${COMPOSE_PROJECT_NAME}_application" "$HOSTNAME"
docker network connect "${COMPOSE_PROJECT_NAME}_data" "$HOSTNAME"
- name: Integration checks
run: |
set -a
. ./.env
set +a
test "$(curl --noproxy '*' -s -o /dev/null -w '%{http_code}' "http://s3:9000/$S3_BUCKET")" = "403"
make test BASE_URL=http://nginx:8080
docker compose --profile tests run --rm --build tests
go run ./cmd/dependencycheck -base-url=http://nginx:8080
make test-persistence ACTION_SCRIPT=scripts/restart.sh BASE_URL=http://nginx:8080
make test-failover ACTION_SCRIPT=scripts/stop-one.sh BASE_URL=http://nginx:8080
docker compose up -d --scale api=2 --wait --wait-timeout 90
- name: Container logs
if: failure()
run: if [ -f .env ]; then docker compose logs --no-color --tail=200; fi
- name: Stop local stack
if: always()
run: |
docker network disconnect "${COMPOSE_PROJECT_NAME}_application" "$HOSTNAME" 2>/dev/null || true
docker network disconnect "${COMPOSE_PROJECT_NAME}_data" "$HOSTNAME" 2>/dev/null || true
if [ -f .env ]; then docker compose --profile tests down -v --remove-orphans; fi