diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8608703..651de94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,4 +43,4 @@ jobs: with: fetch-depth: 0 - - uses: dafnik/commitlint@main \ No newline at end of file + - uses: dafnik/commitlint@main diff --git a/README.md b/README.md index 856a7ac..4b88483 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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`. + | Inputs | Default value | Description | |----------------------|---------------|------------------------------| @@ -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 \ No newline at end of file +[release-workflow-runs]: https://github.com/dafnik/commitlint/actions/workflows/release.yml diff --git a/action.yml b/action.yml index a781c21..c0d0a74 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/commitlint.config.js b/commitlint.config.js deleted file mode 100644 index 422b194..0000000 --- a/commitlint.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { extends: ['@commitlint/config-conventional'] };