-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ci(repo-hygiene): isolate release write permissions #2384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Yuxin-Qiao
wants to merge
8
commits into
steipete:main
from
Yuxin-Qiao:codex/release-permission-split
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9df28f7
ci(release): isolate write permissions
Yuxin-Qiao 5f4357b
Fix release asset publication ordering
Yuxin-Qiao f383844
test(spend): serialize dashboard controller cases
Yuxin-Qiao 3eafbb4
test(spend): isolate dashboard date range
Yuxin-Qiao 322f529
Stabilize dashboard token provenance tests
Yuxin-Qiao 1bd8549
Fix localized session equivalents
Yuxin-Qiao 863ca1b
Cover localized stringsdict formatting
Yuxin-Qiao 500bac0
Merge test baseline repair
Yuxin-Qiao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
| WORKFLOW="${ROOT_DIR}/.github/workflows/release-cli.yml" | ||
|
|
||
| python3 - "$WORKFLOW" <<'PY' | ||
| import pathlib | ||
| import re | ||
| import sys | ||
|
|
||
| workflow = pathlib.Path(sys.argv[1]).read_text() | ||
|
|
||
| if not re.search(r"(?ms)^permissions:\n contents: read\n", workflow): | ||
| raise SystemExit("release workflow must default to read-only repository contents") | ||
|
|
||
|
|
||
| def job(name: str) -> str: | ||
| match = re.search(rf"(?ms)^ {re.escape(name)}:\n(?P<body>.*?)(?=^ [A-Za-z0-9_-]+:|\Z)", workflow) | ||
| if match is None: | ||
| raise SystemExit(f"missing {name} job") | ||
| return match.group("body") | ||
|
|
||
|
|
||
| build = job("build-cli") | ||
| if not re.search(r"(?ms)^ permissions:\n contents: read\n", build): | ||
| raise SystemExit("build-cli must receive only read access to repository contents") | ||
| if "contents: write" in build: | ||
| raise SystemExit("build-cli must not receive repository write access") | ||
| if "Upload packaged artifact" not in build or "if: github.event_name" in build.split("Upload packaged artifact", 1)[1].split("\n ", 1)[0]: | ||
| raise SystemExit("build-cli must upload its packaged artifact for every run") | ||
|
|
||
| publisher = job("publish-release-assets") | ||
| for required in ( | ||
| "needs: build-cli", | ||
| "if: github.event_name == 'release'", | ||
| "actions: read", | ||
| "contents: write", | ||
| "actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093", | ||
| "pattern: codexbar-cli-*", | ||
| "merge-multiple: true", | ||
| 'gh release upload "$RELEASE_TAG" "${assets[@]}" --clobber', | ||
| ): | ||
| if required not in publisher: | ||
| raise SystemExit(f"release publisher is missing: {required}") | ||
|
|
||
| tap = job("update-homebrew-tap") | ||
| if "permissions: {}" not in tap: | ||
| raise SystemExit("tap updater must not receive the repository token") | ||
|
|
||
| print("Release CLI permissions workflow tests passed.") | ||
| PY |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.