Skip to content

Conversation

@webknjaz
Copy link

@webknjaz webknjaz commented Oct 29, 2025

Summary by Sourcery

Simplify branch name extraction in GitHub Actions by replacing manual parsing of github.ref with the built-in GITHUB_REF_NAME environment variable in test matrix jobs

CI:

  • Use GITHUB_REF_NAME instead of sed-based parsing of github.ref in matrix calculation
  • Update jq filters to reference GITHUB_REF_NAME for selecting appropriate test matrix entries

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 29, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This 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_NAME

flowchart 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"]
Loading

File-Level Changes

Change Details Files
Use built-in GITHUB_REF_NAME for branch name retrieval
  • Removed sed-based parsing of github.ref
  • Replaced branchName variable with direct GITHUB_REF_NAME in echo
.github/workflows/main.yml
Update jq matrix filters to use GITHUB_REF_NAME variable
  • Replaced --arg branchName assignment with ${GITHUB_REF_NAME}
  • Adjusted select predicates to reference $GITHUB_REF_NAME
.github/workflows/main.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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

webknjaz and others added 2 commits November 26, 2025 17:24
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant