Repository navigation
chore(deps): update GitHub Actions #916
Workflow file for this run
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: Manage Cache | |
| on: | |
| pull_request: | |
| types: [closed] | |
| schedule: | |
| - cron: '0 0 * * 0' # Every Sunday at 00:00 | |
| workflow_dispatch: | |
| inputs: | |
| ref: | |
| description: The ref where cache entries should be deleted | |
| type: string | |
| permissions: | |
| contents: read | |
| env: | |
| REF: >- | |
| ${{ | |
| github.event_name == 'pull_request' && github.event.pull_request.merged && format('refs/pull/{0}/merge', github.event.pull_request.number) | |
| || inputs.ref | |
| || github.event_name != 'pull_request' && github.ref | |
| || '' | |
| }} | |
| jobs: | |
| cleanup-cache: | |
| name: Cleanup cache | |
| runs-on: ubuntu-latest | |
| steps: | |
| # actions: write covers `gh cache list` and `gh cache delete` on this repo. | |
| - if: env.REF != '' | |
| id: get-workflow-app-token | |
| name: Get Workflow Access Token | |
| uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 | |
| with: | |
| client-id: ${{ secrets.APPLICATION_ID }} | |
| private-key: ${{ secrets.APPLICATION_PRIVATE_KEY }} | |
| repositories: ${{ github.event.repository.name }} | |
| permission-actions: write | |
| - if: env.REF != '' | |
| name: Deleting workflow caches on ${{ env.REF }} | |
| env: | |
| GH_TOKEN: ${{ steps.get-workflow-app-token.outputs.token }} | |
| run: | | |
| CACHE_KEYS="$(gh cache list -R "${{ github.repository }}" --ref "${{ env.REF }}" --limit 100 --order asc --sort last_accessed_at | cut -f 2 | tr '\n' ' ')" | |
| for key in $CACHE_KEYS; do | |
| # Fro Bot's session history lives in opencode-storage-* caches on the default | |
| # branch; wiping them resets the agent's memory. GitHub's inactivity eviction and | |
| # repo size cap bound them. PR refs are dead after close, so they are still cleaned. | |
| if [ "$REF" = 'refs/heads/${{ github.event.repository.default_branch }}' ]; then | |
| case "$key" in | |
| opencode-storage-*) | |
| echo "::notice::keeping agent session cache: $key" | |
| continue | |
| ;; | |
| esac | |
| fi | |
| # A listed cache can be evicted or re-keyed before we delete it (a TOCTOU | |
| # race against GitHub's async cache eviction), making `gh cache delete` exit | |
| # non-zero with "Could not find a cache matching ...". That specific case is | |
| # benign and must not abort the loop. Any OTHER failure (auth, API, scope) is | |
| # unexpected and must fail the step loudly rather than silently delete nothing. | |
| if ! delete_output="$(gh cache delete "$key" -R "${{ github.repository }}" 2>&1)"; then | |
| # Matches gh's human-readable error text. If gh rewords this, the guard | |
| # flips to fail-loud on the benign race -- noisy but safe (never silent). | |
| if printf '%s' "$delete_output" | grep -q 'Could not find a cache matching'; then | |
| echo "::notice::cache key already evicted, skipping: $key" | |
| else | |
| printf '%s\n' "$delete_output" >&2 | |
| echo "::error::unexpected failure deleting cache key: $key" | |
| exit 1 | |
| fi | |
| fi | |
| done | |
| setup-cache: | |
| if: github.event_name != 'pull_request' | |
| name: Setup cache | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: ⤵ Checkout Branch | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| ref: ${{ env.REF }} | |
| - name: 📦 Setup | |
| uses: ./.github/actions/setup |