-
Notifications
You must be signed in to change notification settings - Fork 29
Cherry Pick Workflow To Ensure Consistent Cherry-Picking #438
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # This workflow validates commit messages in a pull request to ensure they follow a specific pattern. | ||
| # The pattern is defined as follows: | ||
| # - The commit message must contain the string "[cherry-pick/XXX]" where XXX is a valid label. | ||
Flickdm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # - The commit message must also contain "(cherry picked from commit <commit_hash>)" where <commit_hash> is a 40-character SHA-1 hash. | ||
| # - Merge commits are ignored. | ||
| # | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: BSD-2-Clause-Patent | ||
|
|
||
| name: Cherry-Pick Workflow | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: | ||
| - edited | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| cherry-pick-job: | ||
| if: contains(github.event.pull_request.title, '[cherry pick]') || contains(github.event.pull_request.title, '[cherry-pick]') | ||
Flickdm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| fetch-depth: 0 # Fetch the full history to ensure all commits are available | ||
|
|
||
| - name: Validate commit messages | ||
| run: | | ||
| base_branch="${{ github.event.pull_request.base.ref }}" | ||
|
|
||
| # Ensure the base branch is fetched | ||
| git fetch origin $base_branch | ||
|
|
||
| # Get the commits included in the PR | ||
| commits=$(git log --pretty=format:%H origin/$base_branch..HEAD) | ||
|
|
||
| echo "Number of commits being reviewed: $(echo "$commits" | wc -w)" | ||
|
|
||
| for commit in $commits; do | ||
| commit_message=$(git log --format=%B -n 1 "$commit") | ||
|
|
||
| if [[ "$commit_message" =~ ^Merge ]]; then | ||
| echo "Warning: Commit $commit is a merge commit and will be ignored." | ||
| continue | ||
| fi | ||
|
|
||
| if [[ ! $(echo "$commit_message" | tr '[:upper:]' '[:lower:]') =~ \[cherry-pick\/.+\] ]] || [[ ! "$commit_message" =~ \(cherry\ picked\ from\ commit\ [0-9a-f]{40}\) ]]; then | ||
|
||
| echo "Commit $commit does not meet the required pattern." | ||
| echo "Commit message: $commit_message" | ||
| echo "Please use 'git cherry-pick -x <commit_hash>' to cherry-pick the commit." | ||
| exit 1 | ||
| else | ||
| echo "Commit $commit meets the required pattern." | ||
| fi | ||
| done | ||
|
|
||
| echo "All commit messages meet the required pattern."; | ||
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.
Can this just be added to Pull Request Formatting Validator?
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.
Do you think it makes sense to add this to the general pull request formatter? I'm happy to add it there if you think it's worth it. I was just trying to create it as a separate workflow to separate the logic
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.
That's meant to be a collection of checks for formatting. You can still conditionalize this on a "cherry-pick trigger".