Skip to content

Commit 429699f

Browse files
authored
BREAKING CHANGE: Require cache_key input (#1792)
Fixes github/continuous-ai-for-accessibility#39 (Hubber access only) It’s common for someone to scan one site, then edit their workflow to scan a different site. When this happens, if `cache_key` is not provided, the results of the second site’s scan overwrite the first’s. To avoid data loss, this PR makes `cache_key` a required input. Allowed characters are `A-Za-z0-9._/-`, so these are all valid example `cache_key` values: - `cached_findings-main` - `cached_findings-github.com-main.json` - `github.com/settings-pages/cached_findings.json` (this creates directories) `cache_key` doesn’t need to be a hardcoded string. It can be generated in an earlier workflow step, e.g.: ```YAML - name: Generate cache key id: generate_cache_key shell: bash run: | CACHE_KEY=$(printf 'cached_findings-%s-%s.json' "${{ matrix.id }}" "${{ github.ref_name }}" | tr -cs 'A-Za-z0-9._-' '_') echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT ```
2 parents bb236a4 + 9bbc457 commit 429699f

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Trigger the workflow manually or automatically based on your configuration. The
9696
| `urls` | Yes | Newline-delimited list of URLs to scan | `https://primer.style`<br>`https://primer.style/octicons` |
9797
| `repository` | Yes | Repository (with owner) for issues and PRs | `primer/primer-docs` |
9898
| `token` | Yes | PAT with write permissions (see above) | `${{ secrets.GH_TOKEN }}` |
99-
| `cache_key` | No | Custom key for caching findings across runs<br>Allowed: `A-Za-z0-9._/-` | `cached_findings-main-primer.style.json` |
99+
| `cache_key` | Yes | Key for caching findings across runs<br>Allowed: `A-Za-z0-9._/-` | `cached_findings-main-primer.style.json` |
100100
| `login_url` | No | If scanned pages require authentication, the URL of the login page | `https://github.com/login` |
101101
| `username` | No | If scanned pages require authentication, the username to use for login | `some-user` |
102102
| `password` | No | If scanned pages require authentication, the password to use for login | `correct-horse-battery-staple` |

action.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ inputs:
1313
description: "Personal access token (PAT) with fine-grained permissions 'contents: write', 'issues: write', and 'pull_requests: write'"
1414
required: true
1515
cache_key:
16-
description: "Custom key for caching findings across runs"
17-
required: false
16+
description: "Key for caching findings across runs"
17+
required: true
1818
login_url:
1919
description: "If scanned pages require authentication, the URL of the login page"
2020
required: false
@@ -35,21 +35,11 @@ inputs:
3535
runs:
3636
using: "composite"
3737
steps:
38-
- name: Generate cache key
39-
id: cache_key
40-
shell: bash
41-
run: |
42-
CACHE_KEY="${{ inputs.cache_key }}"
43-
if [[ -z "$CACHE_KEY" ]]; then
44-
# If cache_key is not provided, generate a default one using the branch name, replacing characters (e.g. `/`) which would create unexpected paths.
45-
CACHE_KEY=$(printf 'cached_findings-%s' "${{ github.ref_name }}" | tr -cs 'A-Za-z0-9._-' '_')
46-
fi
47-
echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT
4838
- name: Restore cached_findings
4939
id: restore
5040
uses: ./.github/actions/gh-cache/cache
5141
with:
52-
key: ${{ steps.cache_key.outputs.cache_key }}
42+
key: ${{ inputs.cache_key }}
5343
token: ${{ inputs.token }}
5444
- if: ${{ inputs.login_url && inputs.username && inputs.password && !inputs.auth_context }}
5545
name: Authenticate
@@ -84,7 +74,7 @@ runs:
8474
- name: Save cached_findings
8575
uses: ./.github/actions/gh-cache/cache
8676
with:
87-
key: ${{ steps.cache_key.outputs.cache_key }}
77+
key: ${{ inputs.cache_key }}
8878
value: ${{ steps.file.outputs.findings }}
8979
token: ${{ inputs.token }}
9080

0 commit comments

Comments
 (0)