-
Notifications
You must be signed in to change notification settings - Fork 21
[drive-by][CI] Use a built-in ${GITHUB_REF_NAME} env var in CI instead of parsing complex values
#1489
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
base: main
Are you sure you want to change the base?
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR refactors the CI workflow to leverage the built-in GITHUB_REF_NAME environment variable instead of manually parsing github.ref, updating both branch-name echoes and matrix generation steps in main.yml. Flow diagram for CI matrix calculation with GITHUB_REF_NAMEflowchart TD
Start["Start CI job"] --> Step1["Echo Branch Name: ${GITHUB_REF_NAME}"]
Step1 --> Step2["Run jq with --arg branchName ${GITHUB_REF_NAME}"]
Step2 --> Step3["Select matrix entries where runOn matches GITHUB_REF_NAME or 'current'/'previous'"]
Step3 --> Step4["Set matrix output for subsequent steps"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `.github/workflows/main.yml:38` </location>
<code_context>
- branchName=$(echo '${{ github.ref }}' | sed 's,refs/heads/,,g')
- echo "Branch Name: $branchName"
- matrix=$(jq --arg branchName "$branchName" 'map(. | select((.runOn==$branchName) or (.runOn=="current")) )' .github/workflows/matrix_includes.json)
+ echo "Branch Name: ${GITHUB_REF_NAME}"
+ matrix=$(jq --arg branchName "${GITHUB_REF_NAME}" 'map(. | select((.runOn==$GITHUB_REF_NAME) or (.runOn=="current")) )' .github/workflows/matrix_includes.json)
echo "Matrix: $matrix"
</code_context>
<issue_to_address>
**suggestion:** Consider using consistent variable naming in jq filter.
Referencing $branchName in the jq filter would align with the argument name and improve clarity, reducing confusion if the environment variable changes.
Suggested implementation:
```
matrix=$(jq --arg branchName "${GITHUB_REF_NAME}" 'map(. | select((.runOn==$branchName) or (.runOn=="current")) )' .github/workflows/matrix_includes.json)
```
```
matrix=$(jq --arg branchName "${GITHUB_REF_NAME}" 'map(. | select((.runOn==$branchName) or (.runOn=="previous")) )' .github/workflows/matrix_includes.json)
```
</issue_to_address>
### Comment 2
<location> `.github/workflows/main.yml:39` </location>
<code_context>
- echo "Branch Name: $branchName"
- matrix=$(jq --arg branchName "$branchName" 'map(. | select((.runOn==$branchName) or (.runOn=="current")) )' .github/workflows/matrix_includes.json)
+ echo "Branch Name: ${GITHUB_REF_NAME}"
+ matrix=$(jq --arg branchName "${GITHUB_REF_NAME}" 'map(. | select((.runOn==$GITHUB_REF_NAME) or (.runOn=="current")) )' .github/workflows/matrix_includes.json)
echo "Matrix: $matrix"
echo "matrix={\"include\":$(echo $matrix)}" >> $GITHUB_OUTPUT
</code_context>
<issue_to_address>
**suggestion:** Directly referencing environment variables in jq filter may reduce portability.
Passing the branch name as --arg and using $branchName in the jq filter would make the code more reusable and easier to refactor.
Suggested implementation:
```
matrix=$(jq --arg branchName "${GITHUB_REF_NAME}" 'map(. | select((.runOn==$branchName) or (.runOn=="current")) )' .github/workflows/matrix_includes.json)
```
```
matrix=$(jq --arg branchName "${GITHUB_REF_NAME}" 'map(. | select((.runOn==$branchName) or (.runOn=="previous")) )' .github/workflows/matrix_includes.json)
```
</issue_to_address>
### Comment 3
<location> `.github/workflows/main.yml:63` </location>
<code_context>
- echo "Branch Name: $branchName"
- matrix=$(jq --arg branchName "$branchName" 'map(. | select((.runOn==$branchName) or (.runOn=="previous")) )' .github/workflows/matrix_includes.json)
+ echo "Branch Name: ${GITHUB_REF_NAME}"
+ matrix=$(jq --arg branchName "${GITHUB_REF_NAME}" 'map(. | select((.runOn==$GITHUB_REF_NAME) or (.runOn=="previous")) )' .github/workflows/matrix_includes.json)
echo "Matrix: $matrix"
echo "matrix={\"include\":$(echo $matrix)}" >> $GITHUB_OUTPUT
</code_context>
<issue_to_address>
**suggestion:** Potential for confusion between jq argument and environment variable.
Consider updating the jq filter to use $branchName instead of $GITHUB_REF_NAME for consistency with the argument name.
```suggestion
matrix=$(jq --arg branchName "${GITHUB_REF_NAME}" 'map(. | select((.runOn==$branchName) or (.runOn=="previous")) )' .github/workflows/matrix_includes.json)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
New security issues found
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Summary by Sourcery
Simplify branch name extraction in GitHub Actions by replacing manual parsing of
github.refwith the built-inGITHUB_REF_NAMEenvironment variable in test matrix jobsCI:
GITHUB_REF_NAMEinstead of sed-based parsing ofgithub.refin matrix calculationjqfilters to referenceGITHUB_REF_NAMEfor selecting appropriate test matrix entries