From 297597cf23e6c4f29c902124e3d3759f41260e7e Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Mon, 12 Feb 2024 16:43:24 +0100 Subject: [PATCH 1/3] fix: add necessary permissions to example workflow Uses the diff from https://github.com/github/docs/pull/31322/ but adds explicit permissions as well which allows it to be tested with `workflow_dispatch:` if users desire so Also use `github.ref_name` instead of the pull_request.number to query the branch I couldn't get the original to work in local tests but with `ref_name` it works flawlessly. --- .../caching-dependencies-to-speed-up-workflows.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md b/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md index 5dab35fb60a1..31c7f60badce 100644 --- a/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md +++ b/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md @@ -343,13 +343,15 @@ This example workflow uses `gh-actions-cache` to delete up to 100 caches created ```yaml name: cleanup caches by a branch on: - pull_request: + pull_request_target: types: - closed jobs: cleanup: runs-on: ubuntu-latest + permissions: + actions: write steps: - name: Cleanup run: | @@ -369,7 +371,7 @@ jobs: env: GH_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} REPO: {% raw %}${{ github.repository }}{% endraw %} - BRANCH: refs/pull/{% raw %}${{ github.event.pull_request.number }}{% endraw %}/merge + BRANCH: {% raw %}${{ github.ref_name }}{% endraw %} ``` Alternatively, you can use the API to automatically list or delete all caches on your own cadence. For more information, see "[AUTOTITLE](/rest/actions/cache#about-the-cache-in-github-actions)." From e92787bdde288681f50f8403a64340549a118ed9 Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Mon, 12 Feb 2024 16:45:41 +0100 Subject: [PATCH 2/3] Update content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md --- .../caching-dependencies-to-speed-up-workflows.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md b/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md index 31c7f60badce..16f3e6d99de5 100644 --- a/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md +++ b/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md @@ -371,7 +371,7 @@ jobs: env: GH_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} REPO: {% raw %}${{ github.repository }}{% endraw %} - BRANCH: {% raw %}${{ github.ref_name }}{% endraw %} + BRANCH: {% raw %}${{ github.ref_name }}{% endraw %} ``` Alternatively, you can use the API to automatically list or delete all caches on your own cadence. For more information, see "[AUTOTITLE](/rest/actions/cache#about-the-cache-in-github-actions)." From 48e5a20f41e2f6bfb507658651a37f2492d5ccad Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Mon, 12 Feb 2024 19:07:24 +0100 Subject: [PATCH 3/3] Update content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md --- .../caching-dependencies-to-speed-up-workflows.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md b/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md index 16f3e6d99de5..c57a1034ec8c 100644 --- a/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md +++ b/content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md @@ -371,7 +371,7 @@ jobs: env: GH_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} REPO: {% raw %}${{ github.repository }}{% endraw %} - BRANCH: {% raw %}${{ github.ref_name }}{% endraw %} + BRANCH: {% raw %}${{ github.head_ref }}{% endraw %} ``` Alternatively, you can use the API to automatically list or delete all caches on your own cadence. For more information, see "[AUTOTITLE](/rest/actions/cache#about-the-cache-in-github-actions)."