From 4cdfb1ec460334a7d4aabb722ed9d65ce673c898 Mon Sep 17 00:00:00 2001 From: John Luo Date: Fri, 22 Dec 2023 13:43:29 -0600 Subject: [PATCH] Try refreshing cache entries from PR labels --- .../tugboat-refresh-cache-dispatch.yml | 21 ++++++++++++------- .github/workflows/tugboat-refresh-cache.yml | 9 +++++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tugboat-refresh-cache-dispatch.yml b/.github/workflows/tugboat-refresh-cache-dispatch.yml index f281e1071..5148ff8aa 100644 --- a/.github/workflows/tugboat-refresh-cache-dispatch.yml +++ b/.github/workflows/tugboat-refresh-cache-dispatch.yml @@ -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', + }); diff --git a/.github/workflows/tugboat-refresh-cache.yml b/.github/workflows/tugboat-refresh-cache.yml index c9fd0f42f..08e09daaf 100644 --- a/.github/workflows/tugboat-refresh-cache.yml +++ b/.github/workflows/tugboat-refresh-cache.yml @@ -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: | @@ -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'], + }); } }