Skip to content

semantic release can't push to master - #2358

Merged
MichaelMraka merged 1 commit into
RedHatInsights:masterfrom
MichaelMraka:pr1
Oct 9, 2026
Merged

MichaelMraka merged 1 commit into
RedHatInsights:masterfrom
MichaelMraka:pr1

Conversation

@MichaelMraka

@MichaelMraka MichaelMraka commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Secure Coding Practices Checklist GitHub Link

Secure Coding Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

Summary by Sourcery

Make semantic release reliably publish version updates to master while preventing concurrent or duplicate release operations.

Bug Fixes:

  • Enable semantic release to publish version changes to master through pull requests with the required repository permissions.

Enhancements:

  • Serialize versioning workflows and make reruns safely tag already-created releases instead of creating duplicate changes.

CI:

  • Update the semantic-release workflow to create, auto-merge, and clean up version update pull requests using the GitHub App token.

@sourcery-ai

sourcery-ai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Updates semantic release to avoid direct master pushes by serializing runs, using an appropriately permissioned GitHub App token, and merging version changes through an automatically created pull request; adds a branch-aware build-version update helper.

File-Level Changes

Change Details Files
Serialize semantic-release workflows and grant the release GitHub App permissions needed to modify repository contents and pull requests.
  • Allow only one versioning workflow at a time without canceling queued runs.
  • Request contents and pull-request write permissions and use the generated app token for checkout and GitHub CLI operations.
.github/workflows/semantic-release.yml
Replace direct pushes to master with an automated version-update branch and pull request flow, while separating tag publication from version commits.
  • Detect an untagged automatic version-update commit and publish its tag directly.
  • Create and push a version branch, open a PR against master, and enable squash auto-merge.
  • Make the release script fail fast and avoid duplicate tags or no-op version updates.
.github/workflows/semantic-release.yml
Add a reusable script for deriving build versions from the latest reachable tag and branch context.
  • Increment the patch/release version on master and append the short commit hash on other branches.
  • Update OpenAPI documents and VERSION consistently with the computed build version.
scripts/update_build_version.sh

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

@MichaelMraka
MichaelMraka requested a review from a team as a code owner October 8, 2026 15:12

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 5 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="scripts/update_build_version.sh" line_range="21" />
<code_context>
+fi
+
+DOC_FILE="docs/v3/openapi.json docs/admin/openapi.json"
+sed -i 's|\("version": "\)[^"]*\("\)$|'"\1$VERSION\2|;" $DOC_FILE
+echo $VERSION >VERSION
+echo "$VERSION"
</code_context>
<issue_to_address>
**Tags execute build commands**

When a tag pusher creates a reachable tag containing sed metacharacters and a build invokes this script, `VERSION` comes from the latest reachable Git tag without validation, then is interpolated into a GNU `sed` program without escaping. A tag containing sed syntax can alter that program and use its `e` flag to execute a command on the runner.

Validate the tag-derived version against the expected version format and safely escape it before using it in the `sed` replacement.
</issue_to_address>

### Comment 2
<location path=".github/workflows/semantic-release.yml" line_range="9-11" />
<code_context>
     - master

+# one job at a time, concurrent jobs will wait
+concurrency:
+  group: version-inc
+  cancel-in-progress: false
+
 jobs:
</code_context>
<issue_to_address>
**Queued release requests are lost**

When multiple master pushes arrive while a run is active and another run is pending, gitHub keeps only one pending run in the concurrency group, so a newer push replaces the queued run. The workflow examines only the surviving run’s latest commit, leaving release directives or automatic version commits on displaced pushes unprocessed and their version increments or tags lost.

Ensure every master push is processed instead of relying on a concurrency group that retains only one pending run.

Also at `.github/workflows/semantic-release.yml:48`.
</issue_to_address>

### Comment 3
<location path=".github/workflows/semantic-release.yml" line_range="65" />
<code_context>
+        VERSION_NEXT=$(./scripts/increment_version.sh ${VERSION} ${RELEASE_TYPE})
+
+        BRANCH="version/${VERSION_NEXT}"
+        BODY=$(printf '%s\n\n%s\n' "${VERSION_NEXT}" "[automatic version update]")
+        git checkout -B "${BRANCH}"
+
</code_context>
<issue_to_address>
**Version PR retries fail**

When another master push arrives before the version PR merges, or the workflow is retried after pushing the branch but before completing PR setup, `VERSION_NEXT` stays the same, and `git checkout -B` creates a different commit on the existing `version/${VERSION_NEXT}` branch. The non-force push is rejected, so the workflow exits without creating or updating the PR.

Reuse or update the existing version branch and PR on subsequent runs instead of pushing a divergent branch.

Also at `.github/workflows/semantic-release.yml:72-73`.
</issue_to_address>

### Comment 4
<location path="scripts/update_build_version.sh" line_range="12-13" />
<code_context>
     branches:
     - master

+# one job at a time, concurrent jobs will wait
+concurrency:
</code_context>
<issue_to_address>
**Master builds get development versions**

When the script runs on master from a detached checkout, `git rev-parse --abbrev-ref HEAD` returns `HEAD`, so the master check fails and `update_build_version.sh` appends a commit hash instead of incrementing the release version. Master builds receive development-style versions.

Determine whether the checkout is for master without relying on the current branch name in a detached checkout.
</issue_to_address>

### Comment 5
<location path="scripts/update_build_version.sh" line_range="14" />
<code_context>
+BRANCH=$(git rev-parse --abbrev-ref HEAD)
+
+if [[ "$BRANCH" == "master" ]]; then
+    VERSION=$("${SCRIPT_DIR}/increment_version.sh" "$VERSION" "$1")
+else
+    COMMIT=$(git rev-parse --short=7 HEAD)
</code_context>
<issue_to_address>
**Version update aborts without an argument**

When the script runs on master without a release-type argument, with `set -u`, expanding `$1` in `update_build_version.sh` raises an unbound-variable error, so the increment script does not run and the version is not updated.

Pass a default patch release type when `$1` is omitted.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 5 findings to address first, and this grants the release workflow write access to repository contents and pull requests, then uses that authority to create, auto-merge, and tag release changes. If the permission or automation is wrong, it can immediately modify the protected branch or repository history; reverting the workflow cannot undo a merge or tag already created.

Blocking findings: scripts/update_build_version.sh:21, .github/workflows/semantic-release.yml:11, .github/workflows/semantic-release.yml:65, scripts/update_build_version.sh:13, scripts/update_build_version.sh:14


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread scripts/update_build_version.sh Outdated
Comment thread .github/workflows/semantic-release.yml
Comment thread .github/workflows/semantic-release.yml
Comment thread scripts/update_build_version.sh Outdated
Comment thread scripts/update_build_version.sh Outdated
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.95%. Comparing base (3c8b4a3) to head (3e112b0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2358      +/-   ##
==========================================
+ Coverage   58.92%   58.95%   +0.03%     
==========================================
  Files         150      150              
  Lines        9626     9626              
==========================================
+ Hits         5672     5675       +3     
+ Misses       3355     3352       -3     
  Partials      599      599              
Flag Coverage Δ
unittests 58.95% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MichaelMraka
MichaelMraka merged commit 4d456a5 into RedHatInsights:master Oct 9, 2026
8 checks passed
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.

3 participants