Skip to content

Commit

Permalink
feat: allow action to work without commitlint config
Browse files Browse the repository at this point in the history
  • Loading branch information
Dafnik committed Jul 5, 2024
1 parent f22afb6 commit 2d52485
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
with:
fetch-depth: 0

- uses: dafnik/commitlint@main
- uses: dafnik/commitlint@main
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
A simple GitHub action to run [`@commitlint/cli`](https://www.npmjs.com/package/@commitlint/cli) checks.

Following commits are linted based on the action `event_name`.

- `push`: The last commit
- from `HEAD~1` to `HEAD`
- `pull_request`
Expand All @@ -20,14 +21,17 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-depth: 0

- name: Run commitlint
uses: dafnik/commitlint@v1
with:
#with:
#commitlint_version: 'latest'
```

If the action doesn't find a `commitlint.config.js` it's going to install
[`@commitlint/config-conventional`](https://www.npmjs.com/package/@commitlint/config-conventional) and create a pre-generated `commitlint.config.js`.

<!-- prettier-ignore-start -->
| Inputs | Default value | Description |
|----------------------|---------------|------------------------------|
Expand Down Expand Up @@ -57,4 +61,4 @@ The scripts and documentation in this project are released under the [MIT Licens
[release-list]: https://github.com/dafnik/commitlint/releases
[draft-release]: .github/workflows/draft-release.yml
[release]: .github/workflows/release.yml
[release-workflow-runs]: https://github.com/dafnik/commitlint/actions/workflows/release.yml
[release-workflow-runs]: https://github.com/dafnik/commitlint/actions/workflows/release.yml
25 changes: 25 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ runs:
shell: bash
run: npm install --global commitlint@${{ inputs.commitlint_version }} @commitlint/config-conventional

- name: Check if commitlint.config.js exists
shell: bash
id: check-file
run: |
if [ -f commitlint.config.js ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Installing @commitlint/config-conventional
shell: bash
if: steps.check-file.outputs.exists == 'false'
run: npm install --global @commitlint/config-conventional

- name: Creating commitlint.config.js
shell: bash
if: steps.check-file.outputs.exists == 'false'
run: |
echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
- name: Verify commitlint.config.js content
shell: bash
run: cat commitlint.config.js

- name: Validate current commit (last commit) with commitlint
shell: bash
if: github.event_name == 'push'
Expand Down
1 change: 0 additions & 1 deletion commitlint.config.js

This file was deleted.

0 comments on commit 2d52485

Please # to comment.