Skip to content

Commit

Permalink
Try refreshing cache entries from workflow dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
JunTaoLuo committed Dec 22, 2023
1 parent 5545d7f commit a7dbb39
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/tugboat-refresh-cache-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


name: Refresh Tugboat Preview ID Cache - Dispatch
on:
workflow_dispatch:
inputs:
key:
description: 'Cache key of the entry to be refreshed'
required: false
type: string
jobs:
# Refresh cache for given keys
refresh_cache:
name: Refresh cache for given keys
runs-on: ubuntu-latest
steps:
- name: Refresh Preview ID
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: .tugboat_preview.txt
key: ${{ inputs.key }}
- name: Cleanup temporary file
run: rm .tugboat_preview.txt
34 changes: 10 additions & 24 deletions .github/workflows/tugboat-refresh-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ jobs:
# Collects the cache keys that need to be refreshed
collect_cache_keys:
name: Collect Tugboat Preview ID cache keys that need to be refreshed
outputs:
matrix: ${{ steps.cache-keys.outputs.result }}
runs-on: ubuntu-latest
steps:
- name: Cross reference open PRs against cache keys in repo
Expand Down Expand Up @@ -48,27 +46,15 @@ jobs:
if (cacheKeys.includes(`${{ runner.os }}-tugboat-preview-id-pr-${pr}`)) {
console.log(`Need to refresh: ${pr}`)
toRefresh.push(pr)
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'tugboat-refresh-cache-dispatch.yml',
ref: `refs/pull/${pr}/merge`,
inputs: {
key: `${{ runner.os }}-tugboat-preview-id-pr-${pr}`
},
})
}
}
const result = JSON.stringify(toRefresh)
console.log(`Refresh Keys: ${result}`)
return result
result-encoding: string

# Refresh cache for given keys
refresh_cache:
name: Refresh cache for given keys
needs: [ collect_cache_keys ]
runs-on: ubuntu-latest
strategy:
matrix:
value: ${{fromJSON(needs.collect_cache_keys.outputs.matrix)}}
steps:
- name: Refresh Preview ID
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: .tugboat_preview.txt
key: ${{ runner.os }}-tugboat-preview-id-pr-${{ matrix.value }}
- name: Cleanup temporary file
run: rm .tugboat_preview.txt

0 comments on commit a7dbb39

Please sign in to comment.