diff options
| author | nessita <124304+nessita@users.noreply.github.com> | 2025-07-16 08:38:13 -0300 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2025-07-16 08:38:50 -0300 |
| commit | c1883c3b20cf4d9d086f37adff9670f2f5424629 (patch) | |
| tree | 7535497582335a2b23d8d65879769c197b542ece /.github | |
| parent | 1c2e11c7f4b07fb854a58645ba25633c8fe56310 (diff) | |
[5.2.x] Added GitHub Action to enforce stable branch commit message prefix.
Backport of 10386fac00be55e73279459f00f1959c3ef30a1c from main.
Diffstat (limited to '.github')
| -rw-r--r-- | .github/workflows/check-commit-messages.yml | 63 |
1 files changed, 63 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..c7c7bd0760 --- /dev/null +++ b/.github/workflows/check-commit-messages.yml @@ -0,0 +1,63 @@ +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 }}" + HEAD="${{ github.event.pull_request.head.ref }}" + echo "BASE=$BASE" >> $GITHUB_ENV + echo "HEAD=$HEAD" >> $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 base and head branches + run: | + git fetch origin $BASE + git fetch origin $HEAD + + - name: Check commit messages prefix + run: | + PREFIX="${{ steps.vars.outputs.prefix }}" + COMMITS=$(git rev-list origin/${BASE}..origin/${HEAD}) + 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." |
