From 11e15762fb4b52f381d8dbe7bd57ebfcb07cdcd0 Mon Sep 17 00:00:00 2001 From: tienbh Date: Fri, 27 Nov 2026 11:14:57 +0700 Subject: [PATCH] ci: Refactor commitlint installation and execution in PR validation workflow for improved reliability --- .../scoped_workflows/commits-validation.yaml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.gitea/scoped_workflows/commits-validation.yaml b/.gitea/scoped_workflows/commits-validation.yaml index 5561182..77e46d8 100644 --- a/.gitea/scoped_workflows/commits-validation.yaml +++ b/.gitea/scoped_workflows/commits-validation.yaml @@ -45,8 +45,19 @@ jobs: with: bun-version: ${{ env.BUN_VERSION }} + # Install outside the repo so bun does not migrate its lockfile or install its dependencies. - name: Install commitlint - run: bun add --no-save @commitlint/cli @commitlint/config-conventional + run: | + set -euo pipefail + dir="${RUNNER_TEMP}/commitlint" + mkdir -p "$dir" + bun add --cwd "$dir" @commitlint/cli @commitlint/config-conventional + if [[ -e node_modules && ! -L node_modules ]]; then + ln -sfn "$dir/node_modules/@commitlint" node_modules/@commitlint + else + ln -sfn "$dir/node_modules" node_modules + fi + echo "COMMITLINT_BIN=${dir}/node_modules/.bin/commitlint" >> "$GITHUB_ENV" - name: Validate PR Title & Description (<= 500 chars) env: @@ -55,9 +66,9 @@ jobs: COMMITLINT_CONFIG: ${{ steps.commitlint-config.outputs.config }} run: | if [ -z "$PR_BODY" ]; then - printf "%s\n" "$PR_TITLE" | bunx commitlint --config "$COMMITLINT_CONFIG" + printf "%s\n" "$PR_TITLE" | "$COMMITLINT_BIN" --config "$COMMITLINT_CONFIG" else - printf "%s\n\n%s\n" "$PR_TITLE" "$PR_BODY" | bunx commitlint --config "$COMMITLINT_CONFIG" + printf "%s\n\n%s\n" "$PR_TITLE" "$PR_BODY" | "$COMMITLINT_BIN" --config "$COMMITLINT_CONFIG" fi - name: Validate All Commits in PR @@ -66,4 +77,4 @@ jobs: HEAD_SHA: ${{ github.event.pull_request.head.sha }} COMMITLINT_CONFIG: ${{ steps.commitlint-config.outputs.config }} run: | - bunx commitlint --from "$BASE_SHA" --to "$HEAD_SHA" --verbose --config "$COMMITLINT_CONFIG" + "$COMMITLINT_BIN" --from "$BASE_SHA" --to "$HEAD_SHA" --verbose --config "$COMMITLINT_CONFIG"