Compare commits
No files matched your search
@@ -0,0 +1,118 @@
|
||||
name: Conventional Commits Check
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, edited, synchronize, reopened]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
BUN_VERSION: 1.4.5
|
||||
SKIP_AUTHORS: renovate renovatebot
|
||||
|
||||
jobs:
|
||||
lint-commits-and-pr:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Skip bot authors
|
||||
id: author
|
||||
env:
|
||||
AUTHOR: ${{ github.event.pull_request.user.login }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
author=$(printf '%s' "$AUTHOR" | tr '[:upper:]' '[:lower:]')
|
||||
skip=false
|
||||
for name in $SKIP_AUTHORS; do
|
||||
name=$(printf '%s' "$name" | tr '[:upper:]' '[:lower:]')
|
||||
if [[ "$author" == "$name" ]]; then
|
||||
skip=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ "$skip" == true || "$author" == *bot || "$author" == *'[bot]' ]]; then
|
||||
echo "skip=true" >> "$GITHUB_OUTPUT"
|
||||
echo "Skipping commitlint for ${AUTHOR}"
|
||||
else
|
||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Checkout code
|
||||
if: steps.author.outputs.skip != 'true'
|
||||
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
|
||||
if: steps.author.outputs.skip != 'true'
|
||||
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
|
||||
if: steps.author.outputs.skip != 'true'
|
||||
uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: ${{ env.BUN_VERSION }}
|
||||
|
||||
# Install outside the repo so bun does not migrate its lockfile or install its dependencies.
|
||||
- name: Install commitlint
|
||||
if: steps.author.outputs.skip != 'true'
|
||||
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)
|
||||
if: steps.author.outputs.skip != 'true'
|
||||
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" | "$COMMITLINT_BIN" --config "$COMMITLINT_CONFIG"
|
||||
else
|
||||
printf "%s\n\n%s\n" "$PR_TITLE" "$PR_BODY" | "$COMMITLINT_BIN" --config "$COMMITLINT_CONFIG"
|
||||
fi
|
||||
|
||||
- name: Validate All Commits in PR
|
||||
if: steps.author.outputs.skip != 'true'
|
||||
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: |
|
||||
set -euo pipefail
|
||||
mapfile -t shas < <(git rev-list --no-merges "$BASE_SHA...$HEAD_SHA")
|
||||
if [[ ${#shas[@]} -eq 0 ]]; then
|
||||
echo "No non-merge commits to lint"
|
||||
exit 0
|
||||
fi
|
||||
for sha in "${shas[@]}"; do
|
||||
echo "Linting ${sha}"
|
||||
git log -1 --format=%B "$sha" | "$COMMITLINT_BIN" --verbose --config "$COMMITLINT_CONFIG"
|
||||
done
|
||||
@@ -7,6 +7,10 @@ on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
sbom-upload:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
module.exports = {
|
||||
extends: ['@commitlint/config-conventional'],
|
||||
rules: {
|
||||
// Allow all types (following the Conventional Commits specification)
|
||||
'type-enum': [
|
||||
2,
|
||||
'always',
|
||||
['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test'],
|
||||
],
|
||||
// Require type and description (cannot be empty)
|
||||
'type-empty': [2, 'never'],
|
||||
'subject-empty': [2, 'never'],
|
||||
// Limit the length of the Title (header) to 72 characters
|
||||
'header-max-length': [2, 'always', 72],
|
||||
// Require a blank line between title and body/footer (following the Conventional Commits specification)
|
||||
'body-leading-blank': [2, 'always'],
|
||||
'footer-leading-blank': [2, 'always'],
|
||||
// Limit the length of each line in body/description to 500 characters (optional)
|
||||
'body-max-line-length': [2, 'always', 500],
|
||||
},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user