Skip to content

chore: align optionals repository guardrails #135

chore: align optionals repository guardrails

chore: align optionals repository guardrails #135

Workflow file for this run

name: Commitlint
on:
workflow_dispatch:
inputs:
pr_title:
description: Pull request title to lint.
required: true
type: string
base_ref:
description: Base branch to compare against.
required: false
default: main
type: string
pull_request:
branches:
- main
types: [opened, reopened, synchronize, ready_for_review, edited]
permissions:
contents: read
pull-requests: read
concurrency:
group: commitlint-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
commitlint:
name: Commitlint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: "24"
- name: Prepare commitlint
run: |
set -euo pipefail
commitlint_home="$RUNNER_TEMP/commitlint"
mkdir -p "$commitlint_home"
printf '{"private":true}\n' > "$commitlint_home/package.json"
cp commitlint.config.cjs "$commitlint_home/commitlint.config.cjs"
npm --prefix "$commitlint_home" install --silent --ignore-scripts \
@commitlint/cli@21.0.2 \
@commitlint/config-conventional@21.0.2
echo "COMMITLINT_BIN=$commitlint_home/node_modules/.bin/commitlint" >> "$GITHUB_ENV"
echo "COMMITLINT_CONFIG=$commitlint_home/commitlint.config.cjs" >> "$GITHUB_ENV"
- name: Lint pull request title
env:
PR_TITLE: ${{ github.event_name == 'pull_request' && github.event.pull_request.title || inputs.pr_title }}
run: printf '%s\n' "$PR_TITLE" | "$COMMITLINT_BIN" --config "$COMMITLINT_CONFIG"
- name: Lint pull request commits
env:
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_REF: ${{ inputs.base_ref || 'main' }}
EVENT_NAME: ${{ github.event_name }}
run: |
if [ "$EVENT_NAME" = "pull_request" ]; then
"$COMMITLINT_BIN" --config "$COMMITLINT_CONFIG" \
--from "$PR_BASE_SHA" --to "$PR_HEAD_SHA" --verbose
else
git fetch origin "$BASE_REF"
"$COMMITLINT_BIN" --config "$COMMITLINT_CONFIG" \
--from "origin/$BASE_REF" --to HEAD --verbose
fi