Code Issues Pull Requests Actions Packages Projects Releases 15 Wiki Activity Security Code Quality

ci: Enhance commitlint configuration resolution in PR workflow to prioritize local settings

This commit is contained in:
tienbh committed 2026-11-26 18:10:06 +07:00 Verified
1 parent b47068f081
commit a7f30525a3
1 file changed
+25 -3
@@ -16,6 +16,26 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
# Local config wins, in this order. Download the shared file only when none exist.
- name: Resolve commitlint config
id: commitlint-config
env:
COMMITLINT_REPO: ${{ vars.COMMITLINT_CONFIG_REPO || 'gitea/global-workflow' }}
COMMITLINT_CONFIGS: commitlint.config.js .github/commitlint.config.js .gitea/commitlint.config.js
run: |
set -euo pipefail
for candidate in $COMMITLINT_CONFIGS; do
if [[ -f "$candidate" ]]; then
echo "Using ${candidate} from this repository"
echo "config=${candidate}" >> "$GITHUB_OUTPUT"
exit 0
fi
done
url="${GITHUB_API_URL}/repos/${COMMITLINT_REPO}/raw/commitlint.config.js?ref=main"
echo "No local commitlint.config.js; fetching ${url}"
curl --silent --show-error --fail --location --output commitlint.config.js "$url"
echo "config=commitlint.config.js" >> "$GITHUB_OUTPUT"
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
@@ -28,16 +48,18 @@ jobs:
env: env:
PR_TITLE: ${{ github.event.pull_request.title }} PR_TITLE: ${{ github.event.pull_request.title }}
PR_BODY: ${{ github.event.pull_request.body }} PR_BODY: ${{ github.event.pull_request.body }}
COMMITLINT_CONFIG: ${{ steps.commitlint-config.outputs.config }}
run: | run: |
if [ -z "$PR_BODY" ]; then if [ -z "$PR_BODY" ]; then
printf "%s\n" "$PR_TITLE" | npx commitlint printf "%s\n" "$PR_TITLE" | npx commitlint --config "$COMMITLINT_CONFIG"
else else
printf "%s\n\n%s\n" "$PR_TITLE" "$PR_BODY" | npx commitlint printf "%s\n\n%s\n" "$PR_TITLE" "$PR_BODY" | npx commitlint --config "$COMMITLINT_CONFIG"
fi fi
- name: Validate All Commits in PR - name: Validate All Commits in PR
env: env:
BASE_SHA: ${{ github.event.pull_request.base.sha }} BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }}
COMMITLINT_CONFIG: ${{ steps.commitlint-config.outputs.config }}
run: | run: |
npx commitlint --from "$BASE_SHA" --to "$HEAD_SHA" --verbose npx commitlint --from "$BASE_SHA" --to "$HEAD_SHA" --verbose --config "$COMMITLINT_CONFIG"