Skip to content

Commit 72de420

Browse files
authored
Merge pull request #4 from Dafnik/feature/optional-config
feat: allow action to work without commitlint config
2 parents f22afb6 + 2d52485 commit 72de420

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ jobs:
4343
with:
4444
fetch-depth: 0
4545

46-
- uses: dafnik/commitlint@main
46+
- uses: dafnik/commitlint@main

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
A simple GitHub action to run [`@commitlint/cli`](https://www.npmjs.com/package/@commitlint/cli) checks.
44

55
Following commits are linted based on the action `event_name`.
6+
67
- `push`: The last commit
78
- from `HEAD~1` to `HEAD`
89
- `pull_request`
@@ -20,14 +21,17 @@ jobs:
2021
- name: Checkout Repository
2122
uses: actions/checkout@v4
2223
with:
23-
fetch-depth: 0
24+
fetch-depth: 0
2425

2526
- name: Run commitlint
2627
uses: dafnik/commitlint@v1
27-
with:
28+
#with:
2829
#commitlint_version: 'latest'
2930
```
3031

32+
If the action doesn't find a `commitlint.config.js` it's going to install
33+
[`@commitlint/config-conventional`](https://www.npmjs.com/package/@commitlint/config-conventional) and create a pre-generated `commitlint.config.js`.
34+
3135
<!-- prettier-ignore-start -->
3236
| Inputs | Default value | Description |
3337
|----------------------|---------------|------------------------------|
@@ -57,4 +61,4 @@ The scripts and documentation in this project are released under the [MIT Licens
5761
[release-list]: https://github.com/dafnik/commitlint/releases
5862
[draft-release]: .github/workflows/draft-release.yml
5963
[release]: .github/workflows/release.yml
60-
[release-workflow-runs]: https://github.com/dafnik/commitlint/actions/workflows/release.yml
64+
[release-workflow-runs]: https://github.com/dafnik/commitlint/actions/workflows/release.yml

action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ runs:
2525
shell: bash
2626
run: npm install --global commitlint@${{ inputs.commitlint_version }} @commitlint/config-conventional
2727

28+
- name: Check if commitlint.config.js exists
29+
shell: bash
30+
id: check-file
31+
run: |
32+
if [ -f commitlint.config.js ]; then
33+
echo "exists=true" >> $GITHUB_OUTPUT
34+
else
35+
echo "exists=false" >> $GITHUB_OUTPUT
36+
fi
37+
38+
- name: Installing @commitlint/config-conventional
39+
shell: bash
40+
if: steps.check-file.outputs.exists == 'false'
41+
run: npm install --global @commitlint/config-conventional
42+
43+
- name: Creating commitlint.config.js
44+
shell: bash
45+
if: steps.check-file.outputs.exists == 'false'
46+
run: |
47+
echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
48+
49+
- name: Verify commitlint.config.js content
50+
shell: bash
51+
run: cat commitlint.config.js
52+
2853
- name: Validate current commit (last commit) with commitlint
2954
shell: bash
3055
if: github.event_name == 'push'

commitlint.config.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)