From 48de27e4b43c79826053fb63c09bf2986fc87b8c Mon Sep 17 00:00:00 2001 From: John Luo Date: Fri, 22 Dec 2023 18:45:20 -0500 Subject: [PATCH] Refresh Tugboat Preview ID cache from PR cache scope (#16562) --- ...yml => tugboat-refresh-cache-dispatch.yml} | 38 +++++-------------- .../tugboat-refresh-cache-responder.yml | 29 ++++++++++++++ 2 files changed, 38 insertions(+), 29 deletions(-) rename .github/workflows/{tugboat-refresh-cache.yml => tugboat-refresh-cache-dispatch.yml} (58%) create mode 100644 .github/workflows/tugboat-refresh-cache-responder.yml diff --git a/.github/workflows/tugboat-refresh-cache.yml b/.github/workflows/tugboat-refresh-cache-dispatch.yml similarity index 58% rename from .github/workflows/tugboat-refresh-cache.yml rename to .github/workflows/tugboat-refresh-cache-dispatch.yml index bd1167fa11..efba64d672 100644 --- a/.github/workflows/tugboat-refresh-cache.yml +++ b/.github/workflows/tugboat-refresh-cache-dispatch.yml @@ -5,16 +5,14 @@ on: - cron: '0 */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 }} + dispatch_cache_keys: + name: Dispatch Tugboat Preview ID cache keys that need to be refreshed 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: + github-token: ${{ secrets.LABEL_API_TOKEN }} script: | const prs = await github.paginate( github.rest.pulls.list, @@ -43,32 +41,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 github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: `${pr}`, + labels: ['refresh-tugboat-cache'], + }); } } - - 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 diff --git a/.github/workflows/tugboat-refresh-cache-responder.yml b/.github/workflows/tugboat-refresh-cache-responder.yml new file mode 100644 index 0000000000..fce9d5f14a --- /dev/null +++ b/.github/workflows/tugboat-refresh-cache-responder.yml @@ -0,0 +1,29 @@ + + +name: Refresh Tugboat Preview ID Cache +on: + pull_request: + types: [ labeled ] +jobs: + refresh_cache: + name: Refresh Tugboat Preview ID Cache + 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: ${{ 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 github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{ github.event.pull_request.number }}, + name: 'refresh-tugboat-cache', + });