|
|
|
@@ -2,9 +2,9 @@ name: CI
|
|
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches: [main, dev]
|
|
|
|
|
branches: [main, dev, uat]
|
|
|
|
|
pull_request:
|
|
|
|
|
branches: [main, dev]
|
|
|
|
|
branches: [main, dev, uat]
|
|
|
|
|
|
|
|
|
|
concurrency:
|
|
|
|
|
group: ci-${{ github.ref }}
|
|
|
|
@@ -15,12 +15,12 @@ permissions:
|
|
|
|
|
packages: write
|
|
|
|
|
|
|
|
|
|
env:
|
|
|
|
|
REGISTRY: git.farh.net
|
|
|
|
|
REGISTRY: ghcr.io
|
|
|
|
|
IMAGE_NAME: cartsnitch/api
|
|
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
|
lint:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
- uses: actions/setup-python@v5
|
|
|
|
@@ -34,7 +34,7 @@ jobs:
|
|
|
|
|
run: ruff format --check .
|
|
|
|
|
|
|
|
|
|
typecheck:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
continue-on-error: true
|
|
|
|
|
steps:
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
@@ -49,7 +49,7 @@ jobs:
|
|
|
|
|
run: mypy src/cartsnitch_api
|
|
|
|
|
|
|
|
|
|
test:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
services:
|
|
|
|
|
postgres:
|
|
|
|
|
image: postgres:15-alpine
|
|
|
|
@@ -96,7 +96,7 @@ jobs:
|
|
|
|
|
run: pytest --tb=short -q
|
|
|
|
|
|
|
|
|
|
build-and-push:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
needs: [lint, test]
|
|
|
|
|
outputs:
|
|
|
|
|
calver_tag: ${{ steps.calver.outputs.version }}
|
|
|
|
@@ -123,13 +123,19 @@ jobs:
|
|
|
|
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
|
|
|
echo "CalVer tag: $VERSION"
|
|
|
|
|
|
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
- name: Log in to Docker Hub
|
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
|
with:
|
|
|
|
|
registry: git.farh.net
|
|
|
|
|
username: cartsnitch
|
|
|
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Log in to GHCR
|
|
|
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
|
with:
|
|
|
|
|
registry: ${{ env.REGISTRY }}
|
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
|
|
|
|
|
- name: Extract metadata
|
|
|
|
|
id: meta
|
|
|
|
@@ -166,11 +172,7 @@ jobs:
|
|
|
|
|
only-fixed: "true"
|
|
|
|
|
output-format: sarif
|
|
|
|
|
|
|
|
|
|
- name: Upload api scan results to GitHub Security
|
|
|
|
|
uses: github/codeql-action/upload-sarif@v3
|
|
|
|
|
if: always()
|
|
|
|
|
with:
|
|
|
|
|
sarif_file: ${{ steps.scan.outputs.sarif }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Push Docker image
|
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
@@ -192,24 +194,15 @@ jobs:
|
|
|
|
|
git push origin "v${{ steps.calver.outputs.version }}"
|
|
|
|
|
|
|
|
|
|
deploy-dev:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
needs: [build-and-push]
|
|
|
|
|
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main')
|
|
|
|
|
steps:
|
|
|
|
|
- name: Generate GitHub App token
|
|
|
|
|
id: app-token
|
|
|
|
|
uses: actions/create-github-app-token@v1
|
|
|
|
|
with:
|
|
|
|
|
app-id: ${{ secrets.CARTSNITCH_APP_ID }}
|
|
|
|
|
private-key: ${{ secrets.CARTSNITCH_APP_PRIVATE_KEY }}
|
|
|
|
|
owner: ${{ github.repository_owner }}
|
|
|
|
|
repositories: infra
|
|
|
|
|
|
|
|
|
|
- name: Checkout infra repo
|
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
with:
|
|
|
|
|
repository: cartsnitch/infra
|
|
|
|
|
token: ${{ steps.app-token.outputs.token }}
|
|
|
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
|
ref: main
|
|
|
|
|
path: infra
|
|
|
|
|
|
|
|
|
@@ -245,24 +238,15 @@ jobs:
|
|
|
|
|
git push origin main
|
|
|
|
|
|
|
|
|
|
deploy-uat:
|
|
|
|
|
runs-on: runners-cartsnitch
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
needs: [build-and-push]
|
|
|
|
|
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/uat' || github.ref == 'refs/heads/main')
|
|
|
|
|
steps:
|
|
|
|
|
- name: Generate GitHub App token
|
|
|
|
|
id: app-token
|
|
|
|
|
uses: actions/create-github-app-token@v1
|
|
|
|
|
with:
|
|
|
|
|
app-id: ${{ secrets.CARTSNITCH_APP_ID }}
|
|
|
|
|
private-key: ${{ secrets.CARTSNITCH_APP_PRIVATE_KEY }}
|
|
|
|
|
owner: ${{ github.repository_owner }}
|
|
|
|
|
repositories: infra
|
|
|
|
|
|
|
|
|
|
- name: Checkout infra repo
|
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
with:
|
|
|
|
|
repository: cartsnitch/infra
|
|
|
|
|
token: ${{ steps.app-token.outputs.token }}
|
|
|
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
|
ref: main
|
|
|
|
|
path: infra
|
|
|
|
|
|