Code Issues Pull Requests Actions Packages Projects Releases 15 Wiki Activity Security Code Quality
Files
global-workflow/.gitea/scoped_workflows/commits-validation.yaml
T

65 lines
2.4 KiB
YAML

name: Conventional Commits Check
on:
pull_request:
types: [opened, edited, synchronize, reopened]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint-commits-and-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
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 Bun
uses: oven-sh/setup-bun@v2
- name: Install commitlint
run: bun add --no-save @commitlint/cli @commitlint/config-conventional
- name: Validate PR Title & Description (<= 500 chars)
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BODY: ${{ github.event.pull_request.body }}
COMMITLINT_CONFIG: ${{ steps.commitlint-config.outputs.config }}
run: |
if [ -z "$PR_BODY" ]; then
printf "%s\n" "$PR_TITLE" | bunx commitlint --config "$COMMITLINT_CONFIG"
else
printf "%s\n\n%s\n" "$PR_TITLE" "$PR_BODY" | bunx commitlint --config "$COMMITLINT_CONFIG"
fi
- name: Validate All Commits in PR
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
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"