Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/actions/commitlint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,23 @@ steps:
config-file: '.commitlintrc.js'
```

### Lint a pull request title

```yaml
steps:
- uses: actions/checkout@v4
- name: Lint PR Title
uses: dsx-ai-factory/dsx-github-actions/.github/actions/commitlint@main
with:
pr-title: ${{ github.event.pull_request.title }}
```

## Inputs

| Input | Description | Required | Default |
| :--- | :--- | :--- | :--- |
| `config-file` | Path to commitlint config file. If empty, uses default discovery. | `false` | `''` |
| `pr-title` | Lint this pull request title instead of a commit range. When set, `from` and `to` are ignored. | `false` | `''` |
| `from` | Lint commits starting from this ref (exclusive). | `false` | `''` |
| `to` | Lint commits up to this ref (inclusive). | `false` | `HEAD` |
| `node-version` | Node.js version to use. | `false` | `20` |
Expand All @@ -44,9 +56,9 @@ steps:
- In PR context: lints commits from the base branch (`origin/$GITHUB_BASE_REF`).
- In push context: lints only the latest commit (`HEAD~1..HEAD`).
- On initial commits or shallow clones: lints `HEAD` only.
4. **Run commitlint** with verbose output.
4. **Run commitlint** with verbose output. If `pr-title` is set, the title is linted on standard input and the commit range is not used.

## Notes

- The calling workflow must use `actions/checkout` with `fetch-depth: 0` (or at least enough depth to cover all commits in the PR) for commitlint to access the full commit range.
- In range mode the calling workflow must use `actions/checkout` with `fetch-depth: 0` (or at least enough depth to cover all commits in the PR) for commitlint to access the full commit range. Linting a `pr-title` needs no history, only a checkout so commitlint can discover its config.
- npm packages are installed with `--ignore-scripts` for supply chain safety.
14 changes: 14 additions & 0 deletions .github/actions/commitlint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ inputs:
description: 'Path to commitlint config file. If empty, uses default discovery (commitlint.config.js, .commitlintrc.js, etc.)'
required: false
default: ''
pr-title:
description: 'Lint this pull request title instead of a commit range. When set, `from` and `to` are ignored.'
required: false
default: ''
from:
description: 'Lint commits starting from this ref (exclusive). Defaults to the base of the PR or the parent of HEAD.'
required: false
Expand Down Expand Up @@ -70,12 +74,22 @@ runs:
COMMITLINT_FROM: ${{ steps.range.outputs.from }}
COMMITLINT_TO: ${{ inputs.to }}
COMMITLINT_CONFIG: ${{ inputs.config-file }}
COMMITLINT_PR_TITLE: ${{ inputs.pr-title }}
run: |
CONFIG_FLAG=""
if [ -n "$COMMITLINT_CONFIG" ]; then
CONFIG_FLAG="--config $COMMITLINT_CONFIG"
fi

if [ -n "$COMMITLINT_PR_TITLE" ]; then
echo "Linting pull request title"
# commitlint reads stdin only when --edit, --env, --from and --to are
# all omitted, so this branch must not pass a range.
# shellcheck disable=SC2086
printf '%s\n' "$COMMITLINT_PR_TITLE" | npx commitlint $CONFIG_FLAG --verbose
exit 0
fi

FROM_FLAG=""
if [ -n "$COMMITLINT_FROM" ]; then
FROM_FLAG="--from $COMMITLINT_FROM"
Expand Down
Loading