mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-26 00:47:57 +03:00
* fix: significantly more robust approach to committed=false scores * feat: partman * fix: pg partman lives elsewhere... * fix: ddkdk * fix: h a r d h o u s e 12
159 lines
5.1 KiB
YAML
159 lines
5.1 KiB
YAML
name: Bot CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- "main"
|
|
paths:
|
|
- "typescript/bot/**"
|
|
- "typescript/common/**"
|
|
- "typescript/db/**"
|
|
- "typescript/bliss/**"
|
|
- "typescript/db-migration-engine/**"
|
|
- "db/migrations/**"
|
|
- "docker/Dockerfile.bot"
|
|
- ".github/workflows/bot.yml"
|
|
pull_request:
|
|
branches:
|
|
- "main"
|
|
paths:
|
|
- "typescript/bot/**"
|
|
- "typescript/common/**"
|
|
- "typescript/db/**"
|
|
- "typescript/bliss/**"
|
|
- "typescript/db-migration-engine/**"
|
|
- "db/migrations/**"
|
|
- "docker/Dockerfile.bot"
|
|
- ".github/workflows/bot.yml"
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: "bot-${{ github.ref }}-${{ github.workflow }}"
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: ghcr.io/zkldi/tachi-ci:main
|
|
options: --user root
|
|
env:
|
|
NODE_ENV: "test"
|
|
services:
|
|
tachi-postgres-test:
|
|
image: ghcr.io/zkldi/zk-postgres:18@sha256:484fa9e6501ec93c5729ba9f9312d8ee4dfe0c136f1b4881fab5e0aed5aa68fd
|
|
env:
|
|
POSTGRES_USER: tachi
|
|
POSTGRES_PASSWORD: tachi
|
|
POSTGRES_DB: postgres
|
|
PGDATA: /var/lib/postgresql/data/pgdata
|
|
options: >-
|
|
--health-cmd "pg_isready -U tachi"
|
|
--health-interval 5s
|
|
--health-timeout 5s
|
|
--health-retries 10
|
|
--tmpfs /var/lib/postgresql/data:rw,size=1g
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Link workspace to /tachi
|
|
# tachidb and just recipes assume the repo lives at /tachi.
|
|
run: rm -rf /tachi && ln -sf "$GITHUB_WORKSPACE" /tachi
|
|
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
|
|
- name: Run tests
|
|
run: bun run --filter tachi-bot test
|
|
env:
|
|
NODE_ENV: "test"
|
|
POSTGRES_TEST_HOST: tachi-postgres-test
|
|
POSTGRES_TEST_URL: postgresql://tachi:tachi@tachi-postgres-test
|
|
|
|
docker-push:
|
|
runs-on: ubuntu-latest
|
|
needs: [test]
|
|
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
outputs:
|
|
image_tag: ${{ steps.revision.outputs.image_tag }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Revision tag (YYYYMMDD-shortsha + full SHA aliases)
|
|
id: revision
|
|
run: |
|
|
set -eu
|
|
short=$(git rev-parse --short=7 HEAD)
|
|
d=$(TZ=UTC0 git log -1 --format=%cd --date=format:%Y%m%d HEAD)
|
|
echo "image_tag=${d}-${short}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
|
|
|
|
- name: Set build time
|
|
id: build_time
|
|
run: echo "value=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
|
|
with:
|
|
context: .
|
|
file: docker/Dockerfile.bot
|
|
push: ${{ github.ref == 'refs/heads/main' }}
|
|
provenance: true
|
|
sbom: true
|
|
tags: |
|
|
ghcr.io/zkldi/tachi-bot:${{ steps.revision.outputs.image_tag }}
|
|
ghcr.io/zkldi/tachi-bot:${{ github.sha }}
|
|
ghcr.io/zkldi/tachi-bot:main
|
|
ghcr.io/zkldi/tachi-bot:latest
|
|
build-args: |
|
|
GIT_REVISION=${{ github.sha }}
|
|
BUILD_TIME=${{ steps.build_time.outputs.value }}
|
|
cache-from: type=gha,scope=${{ github.ref_name }}-bot
|
|
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-bot
|
|
|
|
dispatch-deploy:
|
|
# See server.yml for rationale — deploy logs live in the private server-ceres repo.
|
|
runs-on: ubuntu-latest
|
|
needs: [test, docker-push]
|
|
if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
destination: [boku, kamai]
|
|
steps:
|
|
- name: Dispatch deploy
|
|
env:
|
|
GH_TOKEN: ${{ secrets.DEPLOY_DISPATCH_TOKEN }}
|
|
DEST: ${{ matrix.destination }}
|
|
SHA: ${{ github.sha }}
|
|
IMAGE_TAG: ${{ needs.docker-push.outputs.image_tag }}
|
|
run: |
|
|
gh api repos/zkldi/server-ceres/dispatches \
|
|
-f event_type=deploy \
|
|
-F "client_payload[app]=bot" \
|
|
-F "client_payload[dest]=${DEST}" \
|
|
-F "client_payload[sha]=${SHA}" \
|
|
-F "client_payload[image_tag]=${IMAGE_TAG}"
|
|
echo "::notice::Dispatched bot@${DEST} ${IMAGE_TAG} (${SHA}) — logs: https://github.com/zkldi/server-ceres/actions/workflows/tachi-deploy.yml"
|