From 7612928ca1588e72a8fc71744e9d5e9e84979de6 Mon Sep 17 00:00:00 2001 From: Max Becker Date: Tue, 13 Oct 2026 10:38:45 +0200 Subject: [PATCH 1/3] Add commitlint workflow for testing --- .github/workflows/.commitlintrc.cjs | 38 +++++++++++++++++++++++++++++ .github/workflows/commitlint.yml | 35 ++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 .github/workflows/.commitlintrc.cjs create mode 100644 .github/workflows/commitlint.yml diff --git a/.github/workflows/.commitlintrc.cjs b/.github/workflows/.commitlintrc.cjs new file mode 100644 index 0000000000..39fcab6315 --- /dev/null +++ b/.github/workflows/.commitlintrc.cjs @@ -0,0 +1,38 @@ +// Parse UHD's area-prefixed subjects and apply repository message limits. +module.exports = { + parserPreset: { + parserOpts: { + headerPattern: /^(\S(?:.*\S)?): (\S(?:.*\S)?)$/, + headerCorrespondence: ['scope', 'subject'], + }, + }, + plugins: [ + { + rules: { + 'header-ideal-length': (parsed, when, value) => { + const isValid = parsed.header.length <= value; + return [ + when === 'never' ? !isValid : isValid, + `header should be ${value} characters or fewer`, + ]; + }, + 'no-fixup-commit': (parsed) => [ + !/^fixup!\s/i.test(parsed.header) + && !/:\s*fixup!\s/i.test(parsed.header), + 'fixup commits are not allowed', + ], + }, + }, + ], + defaultIgnores: false, + rules: { + 'scope-empty': [2, 'never'], + 'subject-empty': [2, 'never'], + 'header-ideal-length': [1, 'always', 50], + 'header-max-length': [2, 'always', 72], + 'body-empty': [2, 'never'], + 'body-leading-blank': [2, 'always'], + 'body-max-line-length': [2, 'always', 72], + 'no-fixup-commit': [2, 'always'], + }, +}; \ No newline at end of file diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml new file mode 100644 index 0000000000..d966fbb808 --- /dev/null +++ b/.github/workflows/commitlint.yml @@ -0,0 +1,35 @@ +name: Commit Message Lint + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +permissions: + contents: read + +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - name: Check out pull request head + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + persist-credentials: false + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Lint pull request commits + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + # Lint only commits introduced by this pull request. + npx --yes --package @commitlint/cli@19.8.1 -- commitlint \ + --config .github/workflows/.commitlintrc.cjs \ + --from="$BASE_SHA" \ + --to="$HEAD_SHA" \ No newline at end of file From 11af0afb1b7989b24844e3f6ef27aee379aab7e9 Mon Sep 17 00:00:00 2001 From: Max Becker Date: Tue, 13 Oct 2026 10:45:09 +0200 Subject: [PATCH 2/3] github: Still an invalid message no empty line --- .github/workflows/commitlint.yml | 49 ++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index d966fbb808..788a48231b 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -28,8 +28,47 @@ jobs: BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | - # Lint only commits introduced by this pull request. - npx --yes --package @commitlint/cli@19.8.1 -- commitlint \ - --config .github/workflows/.commitlintrc.cjs \ - --from="$BASE_SHA" \ - --to="$HEAD_SHA" \ No newline at end of file + printf '## Commit message lint\n\n' >> "$GITHUB_STEP_SUMMARY" + output_file="$(mktemp)" + trap 'rm -f "$output_file"' EXIT + failed=0 + commit_count=0 + + # Lint each introduced commit separately so diagnostics link to its SHA. + while IFS= read -r commit; do + commit_count=$((commit_count + 1)) + short_sha="${commit:0:7}" + commit_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$commit" + + if git show -s --format=%B "$commit" | \ + npx --yes --package @commitlint/cli@19.8.1 -- commitlint \ + --config .github/workflows/.commitlintrc.cjs \ + > "$output_file" 2>&1; then + if [[ -s "$output_file" ]]; then + printf -- '- **Passed with warnings** [`%s`](%s)\n\n' \ + "$short_sha" "$commit_url" >> "$GITHUB_STEP_SUMMARY" + while IFS= read -r line; do + printf ' %s\n' "$line" >> "$GITHUB_STEP_SUMMARY" + done < "$output_file" + printf '\n' >> "$GITHUB_STEP_SUMMARY" + else + printf -- '- **Passed** [`%s`](%s)\n' \ + "$short_sha" "$commit_url" >> "$GITHUB_STEP_SUMMARY" + fi + else + failed=1 + printf -- '- **Failed** [`%s`](%s)\n\n' \ + "$short_sha" "$commit_url" >> "$GITHUB_STEP_SUMMARY" + while IFS= read -r line; do + printf ' %s\n' "$line" >> "$GITHUB_STEP_SUMMARY" + done < "$output_file" + printf '\n' >> "$GITHUB_STEP_SUMMARY" + fi + done < <(git rev-list --reverse "$BASE_SHA..$HEAD_SHA") + + if [[ "$commit_count" -eq 0 ]]; then + printf 'No commits found in the pull request range.\n' \ + >> "$GITHUB_STEP_SUMMARY" + fi + + exit "$failed" \ No newline at end of file From 7234aa5108c44c6c47ac0b3fb2c606d2dd85ff64 Mon Sep 17 00:00:00 2001 From: Max Becker Date: Tue, 13 Oct 2026 10:48:45 +0200 Subject: [PATCH 3/3] github: This should be fine This is a correct message. --- .github/workflows/commitlint.yml | 58 +++++++++++--------------------- 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index 788a48231b..4aa1ad9adc 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -21,54 +21,36 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 24 - name: Lint pull request commits env: BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | + set -o pipefail printf '## Commit message lint\n\n' >> "$GITHUB_STEP_SUMMARY" output_file="$(mktemp)" trap 'rm -f "$output_file"' EXIT - failed=0 - commit_count=0 - - # Lint each introduced commit separately so diagnostics link to its SHA. - while IFS= read -r commit; do - commit_count=$((commit_count + 1)) - short_sha="${commit:0:7}" - commit_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$commit" - - if git show -s --format=%B "$commit" | \ - npx --yes --package @commitlint/cli@19.8.1 -- commitlint \ - --config .github/workflows/.commitlintrc.cjs \ - > "$output_file" 2>&1; then - if [[ -s "$output_file" ]]; then - printf -- '- **Passed with warnings** [`%s`](%s)\n\n' \ - "$short_sha" "$commit_url" >> "$GITHUB_STEP_SUMMARY" - while IFS= read -r line; do - printf ' %s\n' "$line" >> "$GITHUB_STEP_SUMMARY" - done < "$output_file" - printf '\n' >> "$GITHUB_STEP_SUMMARY" - else - printf -- '- **Passed** [`%s`](%s)\n' \ - "$short_sha" "$commit_url" >> "$GITHUB_STEP_SUMMARY" - fi - else - failed=1 - printf -- '- **Failed** [`%s`](%s)\n\n' \ - "$short_sha" "$commit_url" >> "$GITHUB_STEP_SUMMARY" + # Lint only commits introduced by this pull request. + if npx --yes --package @commitlint/cli@19.8.1 -- commitlint \ + --config .github/workflows/.commitlintrc.cjs \ + --from="$BASE_SHA" \ + --to="$HEAD_SHA" 2>&1 | tee "$output_file"; then + if [[ -s "$output_file" ]]; then + printf 'Commit message lint passed with warnings.\n\n' \ + >> "$GITHUB_STEP_SUMMARY" while IFS= read -r line; do printf ' %s\n' "$line" >> "$GITHUB_STEP_SUMMARY" done < "$output_file" - printf '\n' >> "$GITHUB_STEP_SUMMARY" + else + printf 'All pull request commit messages passed.\n' \ + >> "$GITHUB_STEP_SUMMARY" fi - done < <(git rev-list --reverse "$BASE_SHA..$HEAD_SHA") - - if [[ "$commit_count" -eq 0 ]]; then - printf 'No commits found in the pull request range.\n' \ - >> "$GITHUB_STEP_SUMMARY" - fi - - exit "$failed" \ No newline at end of file + else + printf 'Commit message lint failed.\n\n' >> "$GITHUB_STEP_SUMMARY" + while IFS= read -r line; do + printf ' %s\n' "$line" >> "$GITHUB_STEP_SUMMARY" + done < "$output_file" + exit 1 + fi \ No newline at end of file