Skip to content

Commit

Permalink
feat: Add support for custom configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
kevintyj committed Nov 24, 2023
1 parent 43be185 commit cc68c63
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-beers-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kevintyj/prlint": minor
---

Add support for custom configuration files
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
pnpm commitlint --version
- name: 📝Validate PR commits with commitlint
if: github.event_name == 'push'
if: ${{ github.event_name == 'push' }}
run: pnpm commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose

- name: 🤞Run CI command
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ jobs:
- name: 📝Validate PR title with commitlint
uses: ./
with:
cl-config: commitlint.config.js
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,37 @@ jobs:
cache: pnpm
- name: 🛠️Install dependencies for prlint
run: pnpm install @commitlint/config-conventional
- name: 🧾Print versions
run: |
git --version
node --version
pnpm --version
pnpm commitlint --version
- name: 📝Validate PR title with commitlint
uses: kevintyj/prlint@v1
# Optional
with:
cl-config: commitlint-cjs.config.cjs
```
The above action only check's out the current repository to fetch the commitlint configuration file.
PNPM and node is used to install necessary dependencies, then config-conventional is used as a default config.
When using the above configuration, `pnpm-lock.yaml` is required. Please use npm and node if `package-lock.json` is used.

### Inputs
#### `cl-config`
**Optional** Path to commit lint config. Default : `'commitlint.config.js'`

### Outputs
#### `lint-status`
Status of the lint result. Returns `✅ Commitlint tests passed!` if successful and `❌ Commitlint tests failed` if
linter tests fail.
#### `lint-details`
Output of the commitlint result.

### Limitations
The current action of Prlint only accepts `commitlint.config.js` based configurations on commitlint.
`v1.0.1` introduced support for ESM based configuration files. However, currently there is no support for configuration
files of different name in the repository such as `commitlintrc` files especially of different file types.
Future support for an `js` file input will be enabled through an optional action input. However, no support for `json`
or `yaml` files are currently planned. Please feel free to contribute to add aditional features!
The current action of Prlint only accepts javascript based configurations on commitlint.
`v1.0.1` introduced support for ESM based configuration files. `v1.1.0` introduced support for custom config file names.
However, due to ESM support added in `v1.0.1` non `js` config files such as `yaml` or `json` is not supported.

Even if the project does not use `config-conventional`, the Prlint uses the configuration as a fallback, therefore the
project must contain the `config-conventional` package as a development dependency.
project must contain the `config-conventional` package as a development dependency.

## Changelog
See [CHANGELOG](CHANGELOG.md) for the release details

## License

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ description: Ensure PR title match commitlint config
runs:
using: node20
main: dist/index.js
inputs:
cl-config:
description: Path to commit lint config (commitlint.config.js)
default: commitlint.config.js
required: false
outputs:
lint-status:
description: The status of the PR lint
Expand Down
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253076,18 +253076,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const github = __importStar(__nccwpck_require__(75942));
const core = __importStar(__nccwpck_require__(19093));
const errHandle_1 = __importDefault(__nccwpck_require__(44592));
const lint_1 = __nccwpck_require__(97969);
function run() {
return __awaiter(this, void 0, void 0, function* () {
const pullRequestPayload = github.context.payload.pull_request;
const configPayload = core.getInput('cl-config');
if (!(pullRequestPayload === null || pullRequestPayload === void 0 ? void 0 : pullRequestPayload.title))
throw new Error('Pull Request or Title not found!');
const pullRequestObject = {
title: pullRequestPayload.title,
number: pullRequestPayload.number,
};
yield (0, lint_1.verifyTitle)(pullRequestObject.title, 'commitlint.config.js');
yield (0, lint_1.verifyTitle)(pullRequestObject.title, configPayload);
});
}
run().catch(errHandle_1.default);
Expand Down Expand Up @@ -253214,6 +253216,8 @@ function verifyTitle(title, configPath = '') {
return true;
}
else {
(0, core_1.setOutput)('lint-status', '❌ Commitlint tests failed\n');
(0, core_1.setOutput)('lint-details', linterResult);
const errors = linterResult.errors.map((error) => {
return `${error.name}: ${error.message}`;
}).join('\n');
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as github from '@actions/github';
import * as core from '@actions/core';
import handleError from './errHandle';
import { verifyTitle } from './lint';

Expand All @@ -9,6 +10,7 @@ type pullRequest = {

async function run(): Promise<void> {
const pullRequestPayload = github.context.payload.pull_request;
const configPayload = core.getInput('cl-config');

if (!pullRequestPayload?.title)
throw new Error('Pull Request or Title not found!');
Expand All @@ -18,7 +20,7 @@ async function run(): Promise<void> {
number: pullRequestPayload.number,
};

await verifyTitle(pullRequestObject.title, 'commitlint.config.js');
await verifyTitle(pullRequestObject.title, configPayload);
}

run().catch(handleError);
2 changes: 2 additions & 0 deletions src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export async function verifyTitle(title: string, configPath: string = ''): Promi
return true;
}
else {
setOutput('lint-status', '❌ Commitlint tests failed\n');
setOutput('lint-details', linterResult);
const errors = linterResult.errors.map((error) => {
return `${error.name}: ${error.message}`;
}).join('\n');
Expand Down

0 comments on commit cc68c63

Please sign in to comment.