diff --git a/.github/actions/commit-message-validator/action.yaml b/.github/actions/commit-message-validator/action.yaml new file mode 100644 index 00000000000000..8bc7a11d29fcdf --- /dev/null +++ b/.github/actions/commit-message-validator/action.yaml @@ -0,0 +1,65 @@ +name: Check commit message +description: Check git commit messages complying CONTRIBUTING.rst +inputs: + failCondition: + description: Controls whether failed checks also fail the workflow run. + required: false + default: never + unknownModuleLevel: + description: Controls whether failed checks at unknown module name. Set "error" to fail. + required: false + default: warning + workingDirectory: + description: Working directory for checks. + required: false + default: ${{ github.workspace }} +runs: + using: composite + steps: + - name: Check Runner Operating System 🏃‍♂️ + if: runner.os == 'Windows' + shell: bash + run: | + : Check Runner Operating System 🏃‍♂️ + echo "::notice::services-validation action requires a macOS-based or Linux-based runner." + exit 2 + + - name: Run log message checker 🕵️ + shell: bash + working-directory: ${{ inputs.workingDirectory }} + run: | + : Run log message checker 🕵️ + if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi + + echo ::group::Configure criteria + SUBJECT_RE='^\([A-Za-z0-9/., -]\+: [A-Z].\+[^. ]\|Revert .\+\|Merge pull request .\+\)$' + BODY_IGNORE_LINE_RE='\(^Co-Authored-By:\|\$t ; then + exit_code=1 + echo 'Error: invalid subject:' + cat $t + echo + fi + echo ::endgroup:: + + echo ::group::Validate body + if git log --format='%B' "${COMMIT_RANGE}" | grep -v "${BODY_IGNORE_LINE_RE}" | \ + grep "${BODY_EXCEED_LIMIT_RE}" >$t; then + exit_code=1 + echo 'Error: too long line:' + cat $t + echo + fi + echo ::endgroup:: + + exit "$exit_code" diff --git a/.github/workflows/check-format.yaml b/.github/workflows/check-format.yaml index cdd05070e50017..59554064f59b37 100644 --- a/.github/workflows/check-format.yaml +++ b/.github/workflows/check-format.yaml @@ -61,3 +61,15 @@ jobs: uses: ./.github/actions/qt-xml-validator with: failCondition: error + + commit-message-validator: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Commit message check + id: commit-message-check + uses: ./.github/actions/commit-message-validator + with: + failCondition: error