ci(forgejo): add contract tests and docs deployment

- Add contract-test.yml workflow for API contract testing
- Add docs-deploy.yml for automated documentation deployment
This commit is contained in:
Jeremie Fraeys 2026-02-20 15:51:29 -05:00
parent 23e5f3d1dc
commit 96c4c376d8
No known key found for this signature in database
2 changed files with 183 additions and 0 deletions

View file

@ -0,0 +1,120 @@
name: Contract Tests
on:
workflow_dispatch:
push:
paths:
- 'api/openapi.yaml'
- 'internal/api/server_gen.go'
- 'internal/api/adapter.go'
- '.forgejo/workflows/contract-test.yml'
pull_request:
paths:
- 'api/openapi.yaml'
- 'internal/api/server_gen.go'
- 'internal/api/adapter.go'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
GO_VERSION: '1.25.0'
jobs:
spec-drift-check:
name: Spec Drift Detection
runs-on: self-hosted
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
run: |
go version || (wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz && \
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz)
echo "PATH=$PATH:/usr/local/go/bin" >> $GITHUB_ENV
go version
- name: Install oapi-codegen
run: |
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest
echo "PATH=$PATH:$(go env GOPATH)/bin" >> $GITHUB_ENV
- name: Verify spec matches implementation
run: make openapi-check-implementation
contract-test:
name: API Contract Tests
runs-on: self-hosted
timeout-minutes: 15
needs: spec-drift-check
services:
redis:
image: redis:7
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
run: |
go version || (wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz && \
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz)
echo "PATH=$PATH:/usr/local/go/bin" >> $GITHUB_ENV
go version
- name: Build API server
run: |
go build -o api-server ./cmd/api-server
- name: Start API server
run: |
./api-server --config configs/api/dev-local.yaml &
echo "API_PID=$!" >> $GITHUB_ENV
sleep 5
- name: Install schemathesis
run: |
pip install schemathesis
- name: Run contract tests
run: |
schemathesis run api/openapi.yaml \
--base-url http://localhost:8080 \
--checks all \
--max-response-time 5000 \
--hypothesis-max-examples 50
continue-on-error: true # Allow failures until all endpoints are fully implemented
- name: Stop API server
if: always()
run: |
if [ -n "$API_PID" ]; then
kill $API_PID || true
fi
- name: Basic endpoint verification
run: |
echo "Testing /health endpoint..."
curl -s http://localhost:8080/health || echo "Server not running, skipping"
echo "Testing /v1/experiments endpoint..."
curl -s http://localhost:8080/v1/experiments || echo "Server not running, skipping"
echo "Testing /v1/tasks endpoint..."
curl -s http://localhost:8080/v1/tasks || echo "Server not running, skipping"
continue-on-error: true

View file

@ -0,0 +1,63 @@
name: Deploy API Docs
on:
workflow_dispatch:
push:
branches: [main]
paths:
- 'api/openapi.yaml'
- '.forgejo/workflows/docs-deploy.yml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pages: write
id-token: write
jobs:
build-docs:
name: Build API Documentation
runs-on: self-hosted
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Redocly CLI
run: npm install -g @redocly/cli
- name: Generate documentation
run: |
mkdir -p docs/api
redocly build-docs api/openapi.yaml \
--output docs/api/index.html \
--title "FetchML API"
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/api
deploy-docs:
name: Deploy to GitHub Pages
needs: build-docs
runs-on: self-hosted
timeout-minutes: 10
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4