diff options
| author | nessita <124304+nessita@users.noreply.github.com> | 2025-07-16 15:36:33 -0300 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2025-07-16 15:38:07 -0300 |
| commit | 591b23a11b099081fc39d00171f5dc9efbd67e13 (patch) | |
| tree | dfb0128a394f053451aff4c7c6b8c9aa66ddda17 /.github/workflows/check_commit_messages.yml | |
| parent | 0c9ab357b7559a1676ace17e469848739b525d79 (diff) | |
[4.2.x] Fixed GitHub Action that checks commit prefixes to fetch PR head correctly.
Backport of 8499fba0e18826a77fe32cbc13a3d951d9ca8924 from main.
Diffstat (limited to '.github/workflows/check_commit_messages.yml')
| -rw-r--r-- | .github/workflows/check_commit_messages.yml | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/.github/workflows/check_commit_messages.yml b/.github/workflows/check_commit_messages.yml new file mode 100644 index 0000000000..ee9536f482 --- /dev/null +++ b/.github/workflows/check_commit_messages.yml @@ -0,0 +1,61 @@ +name: Check commit prefix + +on: + pull_request: + types: [edited, opened, synchronize, reopened, ready_for_review] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check-commit-prefix: + if: startsWith(github.event.pull_request.base.ref, 'stable/') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Calculate commit prefix + id: vars + run: | + BASE="${{ github.event.pull_request.base.ref }}" + echo "BASE=$BASE" >> $GITHUB_ENV + VERSION="${BASE#stable/}" + echo "prefix=[$VERSION]" >> $GITHUB_OUTPUT + + - name: Check PR title prefix + run: | + TITLE="${{ github.event.pull_request.title }}" + PREFIX="${{ steps.vars.outputs.prefix }}" + if [[ "$TITLE" != "$PREFIX"* ]]; then + echo "❌ PR title must start with the required prefix: $PREFIX" + exit 1 + fi + echo "✅ PR title has the required prefix." + + - name: Fetch relevant branches + run: | + git fetch origin $BASE:base + git fetch origin pull/${{ github.event.pull_request.number }}/head:pr + + - name: Check commit messages prefix + run: | + PREFIX="${{ steps.vars.outputs.prefix }}" + COMMITS=$(git rev-list base..pr) + echo "Checking commit messages for required prefix: $PREFIX" + FAIL=0 + for SHA in $COMMITS; do + MSG=$(git log -1 --pretty=%s $SHA) + echo "Checking commit $SHA: $MSG" + if [[ "$MSG" != "$PREFIX"* ]]; then + echo "❌ Commit $SHA must start with the required prefix: $PREFIX" + FAIL=1 + fi + done + + if [[ $FAIL -eq 1 ]]; then + echo "One or more commit messages are missing the required prefix." + exit 1 + fi + + echo "✅ All commits have the required prefix." |
