Skip to content

Commit

Permalink
Try refreshing cache entries from PR labels
Browse files Browse the repository at this point in the history
  • Loading branch information
JunTaoLuo committed Dec 22, 2023
1 parent e1e1b76 commit 4cdfb1e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
21 changes: 14 additions & 7 deletions .github/workflows/tugboat-refresh-cache-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@

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
pull_request:
types: [ labeled ]
jobs:
# Refresh cache for given keys
refresh_cache:
name: Refresh cache for given keys
runs-on: ubuntu-latest
if: ${{ github.event.label.name == 'refresh-tugboat-cache' }}
steps:
- name: Refresh Preview ID
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: .tugboat_preview.txt
key: ${{ inputs.key }}
key: ${{ runner.os }}-tugboat-preview-id-pr-${{ github.event.pull_request.number }}
- name: Cleanup temporary file
run: rm .tugboat_preview.txt
- name: Remove refresh label
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
script: |
await octokit.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.pull_request.number }},
name: 'refresh-tugboat-cache',
});
9 changes: 6 additions & 3 deletions .github/workflows/tugboat-refresh-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Cross reference open PRs against cache keys in repo
id: cache-keys
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
script: |
Expand Down Expand Up @@ -41,10 +40,14 @@ jobs:
console.log(`Key: ${key}`)
}
const toRefresh = []
for (const pr of prs) {
if (cacheKeys.includes(`${{ runner.os }}-tugboat-preview-id-pr-${pr}`)) {
console.log(`Need to refresh: ${pr}`)
toRefresh.push(pr)
await octokit.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: `${pr}`,
labels: ['refresh-tugboat-cache'],
});
}
}

0 comments on commit 4cdfb1e

Please sign in to comment.