From ce09bba646a4a108b0b36208f5b15266426a22b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Wed, 27 Dec 2023 17:36:22 +0000 Subject: [PATCH] ci(commit-validation): use git to walk commits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PR event doesn't include the actual commits, just a count and a URL to fetch it. But we can checkout the entire git history, we don't have so many commits that we need to optimize this just yet. And then we might as well use `git` itself to walk the commit history. (Using the remote commits URL would be useful only if we'd want to do a shallow clone because we have too many commits) Signed-off-by: Edwin Török --- .github/workflows/commit-validation-pr.yml | 25 ++++++++++++++++++++++ .github/workflows/commit-validation.yml | 5 ++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/commit-validation-pr.yml diff --git a/.github/workflows/commit-validation-pr.yml b/.github/workflows/commit-validation-pr.yml new file mode 100644 index 000000000000..80311326cc18 --- /dev/null +++ b/.github/workflows/commit-validation-pr.yml @@ -0,0 +1,25 @@ +name: commit-validation-pr +on: [pull_request] + +permissions: + contents: read + +jobs: + check-commit-msg-length: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Check commit message length + run: | + git log ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | ( + longlines=0 + while IFS='' read -r line; do + if [ "${#line}" -gt 78 ]; then + echo "Overlong line: ${line}" >&2 + longlines=$(( longlines + 1 )) + fi + done + [ "${longlines}" -eq 0 ] + ) diff --git a/.github/workflows/commit-validation.yml b/.github/workflows/commit-validation.yml index 252e7bfdd865..46402f8630bd 100644 --- a/.github/workflows/commit-validation.yml +++ b/.github/workflows/commit-validation.yml @@ -1,5 +1,5 @@ name: commit-validation -on: [ push, pull_request ] +on: [ push ] permissions: contents: read @@ -16,8 +16,7 @@ jobs: result-encoding: json script: | var longlines = 0; - const pr = ${{ toJSON(github.event.pull_request) }}; - const commits = (pr && pr.commits) || ${{ toJSON(github.event.commits) }}; + const commits = ${{ toJSON(github.event.commits) }}; for (const commit of commits) { for (const line of commit.message.split('\n')) { if (line.length > 78) {