Archive Maintenance #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Archive Maintenance | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| schedule: | |
| description: Schedule metadata for this maintenance run. | |
| required: true | |
| default: manual | |
| type: choice | |
| options: | |
| - nightly | |
| - weekly | |
| - manual | |
| include_benchmark: | |
| description: Run benchmark regeneration during this run. | |
| required: true | |
| default: false | |
| type: boolean | |
| schedule: | |
| - cron: "17 2 * * *" | |
| - cron: "23 4 * * 1" | |
| permissions: | |
| contents: read | |
| issues: write | |
| concurrency: | |
| group: archive-maintenance | |
| cancel-in-progress: false | |
| jobs: | |
| archive-maintenance: | |
| name: Archive Maintenance | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: pgvector/pgvector:pg16 | |
| env: | |
| POSTGRES_PASSWORD: postgres | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd "pg_isready -U postgres -d postgres" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 10 | |
| env: | |
| DATABASE_URL: postgresql://postgres:postgres@localhost:5432/alicebot | |
| ALICEBOT_AUTH_USER_ID: 00000000-0000-0000-0000-000000000001 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install -e '.[dev]' | |
| - name: Prepare database | |
| env: | |
| PGPASSWORD: postgres | |
| run: | | |
| psql -h localhost -U postgres -d postgres -c "CREATE DATABASE alicebot;" | |
| psql -h localhost -U postgres -d alicebot -f infra/postgres/init/001_roles.sql | |
| python -m alembic -c apps/api/alembic.ini upgrade head | |
| - name: Resolve schedule mode | |
| id: schedule | |
| run: | | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| resolved_schedule="${{ inputs.schedule }}" | |
| include_benchmark="${{ inputs.include_benchmark }}" | |
| elif [[ "${{ github.event.schedule }}" == "23 4 * * 1" ]]; then | |
| resolved_schedule="weekly" | |
| include_benchmark="true" | |
| else | |
| resolved_schedule="nightly" | |
| include_benchmark="false" | |
| fi | |
| echo "schedule=${resolved_schedule}" >> "$GITHUB_OUTPUT" | |
| echo "include_benchmark=${include_benchmark}" >> "$GITHUB_OUTPUT" | |
| - name: Run archive maintenance | |
| run: | | |
| args=( | |
| --schedule "${{ steps.schedule.outputs.schedule }}" | |
| --database-url "$DATABASE_URL" | |
| --user-id "$ALICEBOT_AUTH_USER_ID" | |
| ) | |
| if [[ "${{ steps.schedule.outputs.include_benchmark }}" == "true" ]]; then | |
| args+=(--include-benchmark) | |
| fi | |
| python scripts/run_archive_maintenance.py "${args[@]}" | |
| - name: Publish maintenance summary | |
| if: always() | |
| run: | | |
| if [[ -f artifacts/ops/maintenance_status_latest.json ]]; then | |
| { | |
| echo "### Archive maintenance" | |
| echo | |
| echo '```json' | |
| cat artifacts/ops/maintenance_status_latest.json | |
| echo '```' | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| echo "maintenance report not found" >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| - name: Upload maintenance artifacts | |
| if: always() | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | |
| with: | |
| name: archive-maintenance-${{ github.run_id }} | |
| if-no-files-found: warn | |
| path: | | |
| artifacts/ops/maintenance_status_latest.json | |
| artifacts/ops/archive_checksum_manifest.json | |
| artifacts/ops/stale_fact_markers_latest.json | |
| artifacts/ops/history/*.json | |
| eval/reports/phase9_eval_latest.json | |
| - name: Create failure alert issue | |
| if: failure() | |
| uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7 | |
| with: | |
| script: | | |
| const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; | |
| const schedule = `${{ steps.schedule.outputs.schedule }}`; | |
| const title = `[ops] archive maintenance failure (${schedule})`; | |
| const body = [ | |
| 'Archive maintenance job failed.', | |
| '', | |
| `- schedule: ${schedule}`, | |
| `- workflow run: ${runUrl}`, | |
| `- commit: ${context.sha}`, | |
| '', | |
| 'Please inspect the uploaded maintenance artifacts and logs.' | |
| ].join('\n'); | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title, | |
| body, | |
| }); |