-
Notifications
You must be signed in to change notification settings - Fork 0
ci: align release-plz with the standard fg-labs publish workflow #35
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
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| name: Manage Release PRs and Publish Crates | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| concurrency: | ||
| group: release-plz-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| release-pr: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.repository_owner == 'fg-labs' }} | ||
| permissions: | ||
| # release-plz authenticates with the app token (GITHUB_TOKEN env below), | ||
| # so the default token only needs read access plus PR write to open the | ||
| # release PR. | ||
| contents: read | ||
| pull-requests: write | ||
| steps: | ||
| - name: Generate app token | ||
| id: app-token | ||
| uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1 | ||
| with: | ||
| app-id: ${{ secrets.FG_LABS_BOT_APP_ID }} | ||
| private-key: ${{ secrets.FG_LABS_BOT_PRIVATE_KEY }} | ||
| - name: Checkout code | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ steps.app-token.outputs.token }} | ||
| # release-plz uses the app token via GITHUB_TOKEN, so the checkout | ||
| # credential does not need to persist in git config. | ||
| persist-credentials: false | ||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable | ||
| - name: Create or update release PR | ||
| uses: release-plz/action@064f4d1e36c843611ddf013be726beaa4ad804db # v0.5.129 | ||
| with: | ||
| command: release-pr | ||
| env: | ||
| GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | ||
|
|
||
| publish: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.repository_owner == 'fg-labs' }} | ||
| permissions: | ||
| id-token: write | ||
| contents: write | ||
| steps: | ||
| - name: Generate app token | ||
| id: app-token | ||
| uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1 | ||
| with: | ||
| app-id: ${{ secrets.FG_LABS_BOT_APP_ID }} | ||
| private-key: ${{ secrets.FG_LABS_BOT_PRIVATE_KEY }} | ||
| - name: Checkout code | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ steps.app-token.outputs.token }} | ||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable | ||
| - name: Authenticate to crates.io via Trusted Publishing | ||
| id: crates-auth | ||
| uses: rust-lang/crates-io-auth-action@bbd81622f20ce9e2dd9622e3218b975523e45bbe # v1.0.4 | ||
| - name: Publish crate | ||
| id: publish | ||
| env: | ||
| CARGO_REGISTRY_TOKEN: ${{ steps.crates-auth.outputs.token }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r \ | ||
| '.packages[] | select(.name == "redskull") | .version') | ||
|
|
||
| PUBLISHED_VERSION=$(curl -sS \ | ||
| -H "User-Agent: redskull-ci (https://github.com/fg-labs/redskull)" \ | ||
| "https://crates.io/api/v1/crates/redskull" | jq -r \ | ||
| '.crate.max_version // "0.0.0"') | ||
|
|
||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
|
|
||
| if [ "$VERSION" = "$PUBLISHED_VERSION" ]; then | ||
| echo "redskull v$VERSION already on crates.io -- nothing to publish" | ||
| echo "published=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Publishing redskull v$VERSION..." | ||
| cargo publish -p redskull | ||
| echo "Published redskull v$VERSION" | ||
| echo "published=true" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Create GitHub release | ||
| # Gate on `version` rather than `published` so a re-run can still create | ||
| # the GitHub release idempotently if a prior run published the crate but | ||
| # failed before tagging/releasing. | ||
| if: steps.publish.outputs.version != '' | ||
| env: | ||
| GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | ||
| VERSION: ${{ steps.publish.outputs.version }} | ||
| run: | | ||
| set -euo pipefail | ||
| TAG="v${VERSION}" | ||
|
|
||
| # Idempotent: skip if tag/release already exist | ||
| if ! git rev-parse "$TAG" >/dev/null 2>&1; then | ||
| git tag "$TAG" | ||
| fi | ||
| if ! git ls-remote --tags origin "$TAG" | grep -q "$TAG"; then | ||
| git push origin "$TAG" | ||
| fi | ||
| if ! gh release view "$TAG" >/dev/null 2>&1; then | ||
| gh release create "$TAG" \ | ||
| --title "v${VERSION}" \ | ||
| --generate-notes \ | ||
| --latest | ||
| else | ||
| echo "Release $TAG already exists -- skipping" | ||
| fi | ||
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,19 +1,16 @@ | ||
| [workspace] | ||
| # Enable changelog generation driven by Conventional Commits. | ||
| # Update the changelog from Conventional Commits when preparing a release. | ||
| changelog_update = true | ||
| # Create a GitHub release when a release PR is merged. | ||
| git_release_enable = true | ||
| # Tag each release in git. | ||
| git_tag_enable = true | ||
| # Publish the crate to crates.io on release. | ||
| publish = true | ||
| # Verify the package builds before publishing. | ||
| publish_allow_dirty = false | ||
| # Use semver-compatible version bumps. | ||
| # Update dependencies with `cargo update` in the release PR. | ||
| dependencies_update = true | ||
| # Label applied to the release PR. | ||
| pr_labels = ["release"] | ||
| # Verify semver compatibility with cargo-semver-checks before releasing. | ||
| semver_check = true | ||
|
|
||
| [[package]] | ||
| name = "redskull" | ||
| # Group pre-1.0 releases under a single major so breaking changes | ||
| # can still bump the minor version appropriately. | ||
| changelog_include = ["redskull"] | ||
| # Publishing (crates.io upload, git tag, and GitHub release) is handled by the | ||
| # `publish` job in .github/workflows/publish.yml so that we publish via | ||
| # crates.io Trusted Publishing (OIDC). release-plz only opens and maintains the | ||
| # release PR, so disable the release-side actions here. | ||
| publish = false | ||
| git_tag_enable = false | ||
| git_release_enable = false |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: fg-labs/redskull
Length of output: 121
🌐 Web query:
actions/create-github-app-token v3.1.1 input parameters permission-contents permission-pull-requests💡 Result:
In version 3.1.1 of the actions/create-github-app-token action, permissions are managed via optional input parameters prefixed with
permission-[1][2]. These inputs allow you to explicitly define the scopes granted to the generated token, which is a recommended practice to follow the principle of least privilege [1][2]. Regarding your specific inquiries: - permission-contents: This input allows you to specify the 'contents' permission scope [3][4]. It accepts 'read' or 'write' as values [5][6]. When provided, it controls the token's ability to access repository contents, commits, and branches [6]. - permission-pull-requests: This input allows you to specify the 'pull-requests' permission scope [3][4]. It accepts 'read' or 'write' as values [5][6]. When provided, it controls the token's ability to interact with pull requests, reviews, and merges [6]. Key points regarding these permissions: - Default Behavior: If nopermission-*inputs are specified, the generated token defaults to inheriting all permissions granted to the GitHub App's installation [1][2][6]. - Validation: You must ensure that any permission requested via these inputs has already been granted to the GitHub App installation [2]. Requesting a permission that the app does not possess will result in an error [5][2]. - Normalization: The action internally maps these input keys (e.g.,permission-pull-requests) to the corresponding GitHub API permission format (e.g.,pull_requests) [6].Citations:
🏁 Script executed:
Repository: fg-labs/redskull
Length of output: 109
🏁 Script executed:
Repository: fg-labs/redskull
Length of output: 90
🏁 Script executed:
Repository: fg-labs/redskull
Length of output: 5483
Scope GitHub App tokens to least privilege per job.
Both token-generation steps mint installation tokens without explicit permission narrowing, so each token inherits the app installation's full repo permission set. Constrain token scopes with
permission-*inputs (and optionally explicit repo scoping) to reduce blast radius if a downstream step is compromised.Suggested hardening diff
- name: Generate app token id: app-token uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1 with: app-id: ${{ secrets.FG_LABS_BOT_APP_ID }} private-key: ${{ secrets.FG_LABS_BOT_PRIVATE_KEY }} + owner: fg-labs + repositories: redskull + permission-contents: write + permission-pull-requests: write @@ - name: Generate app token id: app-token uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1 with: app-id: ${{ secrets.FG_LABS_BOT_APP_ID }} private-key: ${{ secrets.FG_LABS_BOT_PRIVATE_KEY }} + owner: fg-labs + repositories: redskull + permission-contents: writeAlso applies to: 53-58
🧰 Tools
🪛 zizmor (1.25.2)
[error] 25-25: dangerous use of GitHub App tokens (github-app): app token inherits blanket installation permissions
(github-app)
🤖 Prompt for AI Agents
Source: Linters/SAST tools