update #9428
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: update | |
| on: | |
| schedule: | |
| - cron: "0 0 * * *" | |
| defaults: | |
| run: | |
| # GitHub Actions run without a TTY device. This is a workaround to get one, | |
| # based on https://github.com/actions/runner/issues/241#issuecomment-2019042651 | |
| shell: 'script --return --quiet --log-out /dev/null --command "bash -e {0}"' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_OWNER: ${{ github.repository_owner }} | |
| GITHUB_REPO: ${{ github.event.repository.name }} | |
| GITHUB_BRANCH: ${{ github.head_ref || github.ref_name }} | |
| BKG_HANDOFF_CONTROL_REF: refs/heads/bkg-control | |
| BKG_HANDOFF_POLL_SECONDS: 60 | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| outputs: | |
| handoff_baseline: ${{ steps.handoff.outputs.sha }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@main | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version-file: ".python-version" | |
| - name: Capture queue handoff baseline | |
| id: handoff | |
| run: | | |
| baseline=$(PYTHONPATH=src python -m bkg_py handoff baseline) | |
| echo "sha=$baseline" >> "$GITHUB_OUTPUT" | |
| update: | |
| needs: prepare | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: ${{ github.repository }}-database-publication | |
| cancel-in-progress: false | |
| queue: max | |
| permissions: | |
| actions: read | |
| contents: write | |
| packages: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@main | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version-file: ".python-version" | |
| - name: Check queued update freshness | |
| id: gate | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| QUEUED_HANDOFF_BASELINE: ${{ needs.prepare.outputs.handoff_baseline }} | |
| run: | | |
| if ! current_baseline=$(PYTHONPATH=src python -m bkg_py handoff baseline); then | |
| echo "Could not refresh the handoff baseline; allowing this serialized update" >&2 | |
| current_baseline=$QUEUED_HANDOFF_BASELINE | |
| fi | |
| latest_scheduled_run_id= | |
| active_manual_run_id= | |
| if runs=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs?per_page=100"); then | |
| if freshness=$(PYTHONPATH=src python -m bkg_py handoff workflow-runs <<<"$runs"); then | |
| IFS='|' read -r latest_scheduled_run_id active_manual_run_id \ | |
| <<<"$freshness" | |
| else | |
| echo "Could not parse workflow freshness; allowing this serialized update" >&2 | |
| latest_scheduled_run_id= | |
| active_manual_run_id= | |
| fi | |
| else | |
| echo "Could not read workflow freshness; allowing this serialized update" >&2 | |
| fi | |
| run_update=false | |
| if PYTHONPATH=src python -m bkg_py handoff should-run \ | |
| "$QUEUED_HANDOFF_BASELINE" \ | |
| "$current_baseline" \ | |
| "$GITHUB_RUN_ID" \ | |
| "$latest_scheduled_run_id" \ | |
| "$active_manual_run_id"; then | |
| run_update=true | |
| fi | |
| echo "run=$run_update" >> "$GITHUB_OUTPUT" | |
| - name: Check for release | |
| if: ${{ steps.gate.outputs.run == 'true' }} | |
| id: release | |
| continue-on-error: true | |
| uses: cardinalby/git-get-release-action@v1 | |
| with: | |
| latest: true | |
| - name: Fetch all data | |
| if: ${{ steps.gate.outputs.run == 'true' && steps.release.outcome == 'success' }} | |
| continue-on-error: true | |
| uses: robinraju/release-downloader@v1 | |
| with: | |
| latest: true | |
| fileName: "*.db" | |
| tarBall: false | |
| zipBall: false | |
| out-file-path: ".bkg/.snapshot" | |
| - name: Update | |
| if: ${{ steps.gate.outputs.run == 'true' }} | |
| id: update | |
| run: | | |
| set +e | |
| docker run -v $PWD:/app --env-file <(env | grep -E '^(GITHUB|BKG_HANDOFF_)') \ | |
| ghcr.io/ipitio/backage:master \ | |
| bkg workflow-update -C /app | |
| code=$? | |
| echo "updated=$code" >> "$GITHUB_OUTPUT" | |
| exit "$code" | |
| - name: Get date | |
| if: ${{ steps.gate.outputs.run == 'true' }} | |
| id: date | |
| run: echo "tag=$(date -u +%-Y.%-m).$((($(date -u +%-d)-1)/14))" >> "$GITHUB_OUTPUT" | |
| - name: Save database | |
| if: ${{ steps.gate.outputs.run == 'true' && steps.update.outputs.updated == '0' }} | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| artifacts: "bkg/.snapshot/*" | |
| bodyFile: "bkg/CHANGELOG.md" | |
| tag: "v${{ steps.date.outputs.tag }}" | |
| commit: "master" | |
| allowUpdates: true |