Restrict release workflows to primary rtk-ai/rtk repository - #3
Merged
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR tightens CI release workflows so they only run in the canonical upstream repository and adds repository guards to all release-related jobs. Flow diagram for guarded CI release workflowsflowchart TD
A[GitHub_event] --> B{github.repository == rtk-ai/rtk}
B -->|false| X[Skip_release_jobs]
B -->|true| C{Branch_and_event_check}
C -->|pre-release: develop or workflow_dispatch on non-master| D[pre-release_job]
D --> E{needs.pre-release.outputs.tag != ''}
E -->|true and repo_match| F[build-prerelease_job]
E -->|false| X
C -->|release-please: master and push or workflow_dispatch| G[release-please_job]
G --> H{needs.release-please.outputs.release_created == 'true'}
H -->|true and repo_match| I[build-release_job]
H -->|true and repo_match| J[update-latest-tag_job]
H -->|false| X
A --> K{PR_merged}
K -->|true and repo_match| L[update-next-release_job]
K -->|false| X
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Owner
Author
|
@sourcery-ai title |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
github.repository == 'rtk-ai/rtk'guard is repeated in several jobs; consider extracting it into a single reusable condition (e.g., via a top-levelifon the workflow or a composite expression) to avoid duplication and keep future updates simpler. - If you want to allow workflows to run on forks of
rtk-ai/rtk, you might want to relax the repository check (e.g., usingstartsWith(github.repository, 'rtk-ai/rtk')) or a configurable list of allowed repositories instead of a strict equality.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `github.repository == 'rtk-ai/rtk'` guard is repeated in several jobs; consider extracting it into a single reusable condition (e.g., via a top-level `if` on the workflow or a composite expression) to avoid duplication and keep future updates simpler.
- If you want to allow workflows to run on forks of `rtk-ai/rtk`, you might want to relax the repository check (e.g., using `startsWith(github.repository, 'rtk-ai/rtk')`) or a configurable list of allowed repositories instead of a strict equality.
## Individual Comments
### Comment 1
<location path=".github/workflows/cd.yml" line_range="23-24" />
<code_context>
if: >-
- github.ref == 'refs/heads/develop'
- || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master')
+ github.repository == 'rtk-ai/rtk'
+ && (
+ github.ref == 'refs/heads/develop'
+ || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master')
+ )
runs-on: ubuntu-latest
</code_context>
<issue_to_address>
**suggestion:** Consider centralizing the `github.repository == 'rtk-ai/rtk'` check to avoid duplication and future drift.
The same repository guard now appears in several `if:` conditions in this workflow and others (`build-prerelease`, `release-please`, `build-release`, `update-latest-tag`). Repeating it increases the risk that one instance is updated while others are missed. Consider defining a single canonical repo value (e.g., via `env` or `vars`) or constraining the workflow at a higher level, and then referencing that in all conditions so future changes only need to be made in one place.
Suggested implementation:
```
pre-release:
if: >-
github.repository == env.CANONICAL_REPO
&& (
github.ref == 'refs/heads/develop'
|| (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master')
)
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.tag }}
build-prerelease:
name: Build pre-release
needs: pre-release
if: github.repository == env.CANONICAL_REPO && needs.pre-release.outputs.tag != ''
uses: ./.github/workflows/release.yml
with:
tag: ${{ needs.pre-release.outputs.tag }}
```
1. At the top of `.github/workflows/cd.yml` (workflow root), define a canonical repo env, for example:
```yaml
env:
CANONICAL_REPO: rtk-ai/rtk
```
so that `env.CANONICAL_REPO` is available to all jobs.
2. In the other workflows you mentioned (`build-prerelease`, `release-please`, `build-release`, `update-latest-tag`) update any `if: github.repository == 'rtk-ai/rtk'` conditions to instead use `github.repository == env.CANONICAL_REPO` (or whatever name you choose), and ensure the same `env` definition is present at the workflow or job level.
3. If you prefer to constrain at a higher level, you can also add a top-level job `if: github.repository == env.CANONICAL_REPO` and remove per-job repository checks where appropriate.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary by Sourcery
Guard release and pre-release workflows so they only run in the main rtk-ai/rtk repository.
CI: