Skip to content

Validate necessary branches for the workflow release-commits-and-contributors.yml exist #59768

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

Merged
merged 2 commits into from
Jul 21, 2025

Conversation

albarin
Copy link
Contributor

@albarin albarin commented Jul 18, 2025

Submission Review Guidelines:

Changes proposed in this Pull Request:

Closes #59742

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Fork the woocommerce/woocommerce repo with all branches into your GH account.
  2. In your forked repo, go to Settings > Secrets and variables > Actions and create 3 new repository secrets:
  • CODE_FREEZE_BOT_TOKEN, get the token value from the Test Assistant bot from the secret store.
  • WOO_RELEASE_SLACK_NOTIFICATION_CHANNEL: You can use the test channel test-woo-core-release-notifications.
  1. In the forked repo, create a PR with the branch 59742/validate-branch and merge it (to get this new workflow into trunk).
  2. In the forked repo, go to Actions and manually run the Release: Generate Number of Commits and Contributors with a version without a corresponding branch in your fork, for example: 12.1.
  3. Make sure the workflow fails with Error: Branch 'release/12.1' for the 12.1 version does not exist.
  4. Create the release/12.1 branch, run the workflow again with the same version.
  5. Make sure the workflow fails with Error: Branch 'release/12.0' for the 12.0 version does not exist.
  6. Create the release/12.0 branch, run the workflow again with the same version.
  7. Make sure this time it passes the validation. You can cancel the rest of the workflow since it takes a while,
    and we don't need to check any more changes.

Testing that has already taken place:

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

@github-actions github-actions bot added the focus: monorepo infrastructure Issues and PRs related to monorepo tooling. label Jul 18, 2025
@albarin albarin marked this pull request as ready for review July 18, 2025 10:16
@albarin albarin requested a review from a team as a code owner July 18, 2025 10:16
@albarin albarin requested review from prettyboymp and removed request for a team July 18, 2025 10:16
@woocommercebot woocommercebot requested a review from a team July 18, 2025 10:16
Copy link
Contributor

github-actions bot commented Jul 18, 2025

Testing Guidelines

Hi @prettyboymp @woocommerce/flux,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

Copy link
Contributor

coderabbitai bot commented Jul 18, 2025

📝 Walkthrough

Walkthrough

A new validation step was added to the GitHub Actions workflow for releases. This step checks if the current and previous release branches exist in the remote repository before proceeding, ensuring that the workflow only continues if both branches are present.

Changes

File(s) Change Summary
.github/workflows/release-commits-and-contributors.yml Added a step to the extract-versions job to verify the existence of current and previous release branches.

Possibly related PRs


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/release-commits-and-contributors.yml (1)

82-90: Minor nit: prefer quoting branch variables in git ls-remote

Quoting prevents word-splitting should a branch name ever contain special characters (unlikely but free safety). No functional change otherwise.

-          if ! git ls-remote --exit-code --heads https://github.com/${GITHUB_REPOSITORY} ${CURRENT_BRANCH} > /dev/null; then
+          if ! git ls-remote --exit-code --heads "https://github.com/${GITHUB_REPOSITORY}" "${CURRENT_BRANCH}" > /dev/null; then

Repeat for the previous-branch check below.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c183a34 and 50b0ca3.

📒 Files selected for processing (1)
  • .github/workflows/release-commits-and-contributors.yml (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: prettyboymp
PR: woocommerce/woocommerce#59048
File: .github/workflows/cherry-pick-milestoned-prs.yml:118-131
Timestamp: 2025-07-11T13:05:08.430Z
Learning: In GitHub Actions workflows, when reviewing steps that access event data like `github.event.pull_request.milestone`, check the entire job dependency chain and conditional logic. If upstream jobs already validate the data exists (like checking `github.event.pull_request.milestone != null` in a prerequisite job), then downstream jobs don't need redundant null-checks since the data is guaranteed to exist by that point.
Learnt from: jorgeatorres
PR: woocommerce/woocommerce#59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.815Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in `plugins/woocommerce/changelog/` directory and are processed during releases, not at the repository root level.
Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/generate-pr-description.mdc:0-0
Timestamp: 2025-06-30T09:26:55.361Z
Learning: Provide clear, step-by-step instructions for how to test the changes in the PR description.
Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/generate-pr-description.mdc:0-0
Timestamp: 2025-06-30T09:26:55.361Z
Learning: Applies to .github/PULL_REQUEST_TEMPLATE.md : Do not remove or alter required markdown sections in the PR description, especially those used by automation (e.g., changelog entry details and comments).
Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/generate-pr-description.mdc:0-0
Timestamp: 2025-06-30T09:26:55.361Z
Learning: Applies to .github/PULL_REQUEST_TEMPLATE.md : The changelog section in the PR description must keep the markdown structure from the PR template exactly as-is, including all checkboxes, comments, and headings. Only the appropriate checkbox may be checked, and the changelog message must be placed under the `#### Comment` heading and before the closing `</details>` tag. Do not add, remove, or reformat any part of the changelog section except for checking the box and adding the message in the correct place.
Learnt from: albarin
PR: woocommerce/woocommerce#59445
File: .github/workflows/release-update-stable-tag.yml:81-108
Timestamp: 2025-07-08T12:03:29.871Z
Learning: In GitHub Actions workflows, when using matrix strategy with `fail-fast: false`, individual matrix jobs can fail without stopping the entire workflow or affecting other matrix jobs. This allows graceful handling of scenarios where some matrix entries may be invalid (like non-existent branches) while still processing valid entries successfully.
Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/git.mdc:0-0
Timestamp: 2025-06-30T09:27:06.883Z
Learning: Branch names should follow the structure: 'release/{version}' for release branches.
.github/workflows/release-commits-and-contributors.yml (2)
Learnt from: prettyboymp
PR: woocommerce/woocommerce#59048
File: .github/workflows/cherry-pick-milestoned-prs.yml:118-131
Timestamp: 2025-07-11T13:05:08.430Z
Learning: In GitHub Actions workflows, when reviewing steps that access event data like `github.event.pull_request.milestone`, check the entire job dependency chain and conditional logic. If upstream jobs already validate the data exists (like checking `github.event.pull_request.milestone != null` in a prerequisite job), then downstream jobs don't need redundant null-checks since the data is guaranteed to exist by that point.
Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/git.mdc:0-0
Timestamp: 2025-06-30T09:27:06.883Z
Learning: Branch names should follow the structure: 'release/{version}' for release branches.

Comment on lines +77 to +90
- name: Check the necessary branches exist
run: |
CURRENT_BRANCH="release/${{ steps.calculate-versions.outputs.current_version }}"
PREVIOUS_BRANCH="release/${{ steps.calculate-versions.outputs.previous_version }}"

if ! git ls-remote --exit-code --heads https://github.com/${GITHUB_REPOSITORY} ${CURRENT_BRANCH} > /dev/null; then
echo "::error::Branch '$CURRENT_BRANCH' for the ${{ steps.calculate-versions.outputs.current_version }} version does not exist."
exit 1
fi

if ! git ls-remote --exit-code --heads https://github.com/${GITHUB_REPOSITORY} ${PREVIOUS_BRANCH} > /dev/null; then
echo "::error::Branch '$PREVIOUS_BRANCH' for the ${{ steps.calculate-versions.outputs.previous_version }} version does not exist."
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use set -eo pipefail for more predictable failure handling

The step relies on early exits (exit 1) but still executes several shell commands that are piped to /dev/null.
Explicitly enabling set -eo pipefail at the top of the script guarantees that any non-zero status—including a failure inside a future multi-command pipeline—immediately aborts the step, mirroring the intent of an early-fail guard.

-      - name: Check the necessary branches exist
-        run: |
-          CURRENT_BRANCH="release/${{ steps.calculate-versions.outputs.current_version }}"
+      - name: Check the necessary branches exist
+        run: |
+          set -eo pipefail
+
+          CURRENT_BRANCH="release/${{ steps.calculate-versions.outputs.current_version }}"
           PREVIOUS_BRANCH="release/${{ steps.calculate-versions.outputs.previous_version }}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Check the necessary branches exist
run: |
CURRENT_BRANCH="release/${{ steps.calculate-versions.outputs.current_version }}"
PREVIOUS_BRANCH="release/${{ steps.calculate-versions.outputs.previous_version }}"
if ! git ls-remote --exit-code --heads https://github.com/${GITHUB_REPOSITORY} ${CURRENT_BRANCH} > /dev/null; then
echo "::error::Branch '$CURRENT_BRANCH' for the ${{ steps.calculate-versions.outputs.current_version }} version does not exist."
exit 1
fi
if ! git ls-remote --exit-code --heads https://github.com/${GITHUB_REPOSITORY} ${PREVIOUS_BRANCH} > /dev/null; then
echo "::error::Branch '$PREVIOUS_BRANCH' for the ${{ steps.calculate-versions.outputs.previous_version }} version does not exist."
exit 1
fi
- name: Check the necessary branches exist
run: |
set -eo pipefail
CURRENT_BRANCH="release/${{ steps.calculate-versions.outputs.current_version }}"
PREVIOUS_BRANCH="release/${{ steps.calculate-versions.outputs.previous_version }}"
if ! git ls-remote --exit-code --heads https://github.com/${GITHUB_REPOSITORY} ${CURRENT_BRANCH} > /dev/null; then
echo "::error::Branch '$CURRENT_BRANCH' for the ${{ steps.calculate-versions.outputs.current_version }} version does not exist."
exit 1
fi
if ! git ls-remote --exit-code --heads https://github.com/${GITHUB_REPOSITORY} ${PREVIOUS_BRANCH} > /dev/null; then
echo "::error::Branch '$PREVIOUS_BRANCH' for the ${{ steps.calculate-versions.outputs.previous_version }} version does not exist."
exit 1
fi
🤖 Prompt for AI Agents
In .github/workflows/release-commits-and-contributors.yml around lines 77 to 90,
add the line 'set -eo pipefail' at the very beginning of the run script block to
ensure that any command failure, including those in pipelines, causes the step
to exit immediately. This will make failure handling more robust and predictable
by stopping execution on any error without relying solely on explicit exit
calls.

Copy link
Contributor

@prettyboymp prettyboymp left a comment

Choose a reason for hiding this comment

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

Worked as expected.

@prettyboymp prettyboymp merged commit 051580e into trunk Jul 21, 2025
24 of 27 checks passed
@prettyboymp prettyboymp deleted the 59742/validate-branch branch July 21, 2025 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: monorepo infrastructure Issues and PRs related to monorepo tooling.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate that branches exists in release-commits-and-contributors.yml
2 participants