5
0
Fork 0
mirror of https://github.com/wagoid/commitlint-github-action.git synced 2025-11-07 00:06:54 +00:00

feat: upgrade to commitlint v19

BREAKING CHANGE: `commitlint.config.js` is not supported anymore, please use `.mjs` extension
This commit is contained in:
Wagner Santos 2024-03-28 11:38:50 -03:00
parent 9763196e10
commit 732f0ad7d5
24 changed files with 2431 additions and 13465 deletions

View file

@ -1,5 +1,5 @@
node_modules
commitlint.config.js
commitlint.config.mjs
action.yml
.github
CHANGELOG.md

View file

@ -19,5 +19,10 @@
"node/no-unpublished-require": "off",
"node/no-unpublished-import": "off",
"node/no-unsupported-features/es-syntax": "off"
}
},
"ignorePatterns": [
".github/tasks/actionYamlUpdater.js",
"rollup.config.js",
"fixtures"
]
}

View file

@ -3,10 +3,10 @@ const yaml = require('yaml')
const versionRegex = /\d+\.\d+\.\d+/
module.exports.readVersion = (contents) =>
exports.readVersion = (contents) =>
yaml.parse(contents).runs.image.match(versionRegex)[0]
module.exports.writeVersion = (contents, version) => {
exports.writeVersion = (contents, version) => {
const actionFile = yaml.parse(contents)
actionFile.runs.image = actionFile.runs.image.replace(versionRegex, version)

View file

@ -55,7 +55,13 @@ jobs:
git config user.email 'github-action@users.noreply.github.com'
git config user.name 'GitHub Action'
- name: Update versions and changelog
run: npx commit-and-tag-version
run: |
# remove `"type": "module"` from package.json since `commit-and-tag-version` doesn't support it
sed -i '/"type": "module",/c\' package.json
npx commit-and-tag-version
# bring back `"type": "module"`
sed -i 's/"private": true,/"private": true,\n "type": "module",/' package.json
git commit --amend --no-edit
- name: Set VERSION env var
run: |
version=`node -p "require('./package.json').version"`

View file

@ -1,4 +1,4 @@
module.exports = {
export default {
'*.{ts,tsx,vue,css,less,scss,html,htm,md,markdown}': 'prettier --write',
'*.{json,yml,yaml}': ['prettier --write', () => 'npm run test'],
'*.{js,jsx}': ['eslint --fix', () => 'npm run test'],

View file

@ -1,4 +1,4 @@
FROM node:16.14.2-alpine3.14 as build
FROM node:20.9.0-alpine3.17 as build
COPY package*.json /
@ -12,7 +12,7 @@ FROM node:20.9.0-alpine3.17
RUN apk --no-cache add git
COPY --from=build dist/run.js /run.js
COPY --from=build dist/run.mjs /run.mjs
COPY package*.json /

View file

@ -19,25 +19,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: wagoid/commitlint-github-action@v5
- uses: wagoid/commitlint-github-action@v6
```
Alternatively, you can run on other event types such as `on: [push]`. In that case the action will lint the push event's commit(s) instead of linting commits from a pull request. You can also combine `push` and `pull_request` together in the same workflow.
## Inputs
You can supply these inputs to the `wagoid/commitlint-github-action@v5` step.
You can supply these inputs to the `wagoid/commitlint-github-action@v6` step.
### `configFile`
The path to your commitlint config file.
Default: `commitlint.config.js`
Default: `commitlint.config.mjs`
If the config file doesn't exist, [config-conventional](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional) settings will be loaded as a default fallback.
Details on the configuration file can be found on [the commitlint website](https://commitlint.js.org/#/reference-configuration).
Note: `commitlint.config.js` doesn't work with this action. If you use a JS config file, it's required to be an ES Module (`.mjs` extension)
### `failOnWarnings`
Whether you want to fail on warnings or not.
@ -149,7 +151,7 @@ jobs:
- run: npm install
# Run the commitlint action, considering its own dependencies and yours as well 🚀
# `github.workspace` is the path to your repository.
- uses: wagoid/commitlint-github-action@v5
- uses: wagoid/commitlint-github-action@v6
env:
NODE_PATH: ${{ github.workspace }}/node_modules
```

View file

@ -5,7 +5,7 @@ inputs:
configFile:
description: Commitlint config file. If the file doesn't exist, config-conventional settings will be
loaded as a fallback.
default: ./commitlint.config.js
default: ./commitlint.config.mjs
required: false
failOnWarnings:
description: Whether you want to fail on warnings or not

View file

@ -1,5 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */
const { maxLineLength } = require('@commitlint/ensure')
import { maxLineLength } from '@commitlint/ensure'
const bodyMaxLineLength = 100
@ -14,7 +14,7 @@ const validateBodyMaxLengthIgnoringDeps = (parsedCommit) => {
]
}
module.exports = {
export default {
extends: ['@commitlint/config-conventional'],
plugins: ['commitlint-plugin-function-rules'],
rules: {

View file

@ -5,11 +5,13 @@ set -e
if [ -z "$NODE_PATH" ]; then
export NODE_PATH=/node_modules
else
export NODE_PATH=$NODE_PATH:/node_modules
export NODE_PATH="$NODE_PATH":/node_modules
fi
# Since actions/checkout can be setup with a different user ID, we need to set the workspace as safe inside this action
# Info about the vunlerability: https://github.blog/2022-04-12-git-security-vulnerability-announced/
git config --global --add safe.directory "$GITHUB_WORKSPACE"
node /run.js
export NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules"
node /run.mjs

View file

@ -1,3 +1,3 @@
module.exports = {
export default {
extends: ['@commitlint/config-conventional'],
}

View file

@ -1,4 +1,4 @@
module.exports = {
export default {
extends: ['@commitlint/config-conventional'],
helpUrl: 'https://example.org',
}

View file

@ -1,4 +1,4 @@
module.exports = {
export default {
plugins: ['commitlint-plugin-jira-rules'],
extends: ['jira'],
}

View file

@ -1,4 +1,4 @@
module.exports = {
export default {
extends: ['@commitlint/config-conventional'],
rules: {
'signed-off-by': [2, 'always', 'Signed-off-by:'],

View file

@ -1,10 +1,12 @@
module.exports = {
export default {
// Automatically clear mock calls and instances between every test
// preset: 'rollup-jest',
clearMocks: true,
testEnvironment: '@commitlint/test-environment',
testMatch: [
'**/__tests__/**/*.?(m)[jt]s?(x)',
'**/?(*.)+(spec|test).?(m)[tj]s?(x)',
],
transform: {
'\\.[jt]sx?$': 'babel-jest',
},
transformIgnorePatterns: ['node_modules/(?!dargs)'],
}

15549
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,16 +3,17 @@
"version": "5.5.1",
"description": "commitlint github action",
"private": true,
"main": "./dist/run.js",
"type": "module",
"module": "./dist/run.mjs",
"scripts": {
"postinstall": "husky install",
"test": "NODE_PATH=./node_modules jest",
"test": "NODE_PATH=./node_modules NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"lint": "eslint .",
"build": "rollup -c"
},
"engines": {
"node": "^v16.14.2"
"node": "20.9.0"
},
"repository": {
"type": "git",
@ -24,16 +25,16 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@commitlint/config-angular": "^18.6.1",
"@commitlint/config-conventional": "^18.6.3",
"@commitlint/config-lerna-scopes": "^18.6.1",
"@commitlint/config-patternplate": "^18.6.1",
"@commitlint/ensure": "^18.6.1",
"@commitlint/format": "^18.6.1",
"@commitlint/lint": "^18.6.1",
"@commitlint/load": "^18.6.1",
"@commitlint/config-angular": "^19.1.0",
"@commitlint/config-conventional": "^19.1.0",
"@commitlint/config-lerna-scopes": "^19.0.0",
"@commitlint/config-patternplate": "^19.1.0",
"@commitlint/ensure": "^19.0.3",
"@commitlint/format": "^19.0.3",
"@commitlint/lint": "^19.1.0",
"@commitlint/load": "^19.2.0",
"commitlint-config-jira": "^1.6.4",
"commitlint-plugin-function-rules": "^2.0.2",
"commitlint-plugin-function-rules": "^4.0.0",
"commitlint-plugin-jira-rules": "^1.6.4",
"conventional-changelog-conventionalcommits": "^7.0.2",
"conventional-changelog-lint-config-canonical": "^1.0.0",
@ -43,15 +44,15 @@
"devDependencies": {
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.19.3",
"@commitlint/cli": "^18.6.1",
"@commitlint/cli": "^19.2.1",
"@commitlint/test": "^9.0.1",
"@commitlint/test-environment": "^9.0.1",
"@jest/globals": "^29.4.2",
"@jest/globals": "^29.7.0",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-node-resolve": "^14.1.0",
"babel-jest": "^29.4.3",
"commit-and-tag-version": "^12.0.0",
"babel-jest": "^29.7.0",
"commit-and-tag-version": "^12.2.0",
"conventional-changelog-cli": "^4.1.0",
"eslint": "^8.34.0",
"eslint-config-airbnb-base": "^15.0.0",
@ -61,14 +62,11 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"jest": "^29.4.3",
"jest": "^29.7.0",
"lint-staged": "^13.1.1",
"prettier": "^2.8.4",
"rollup": "^2.79.1",
"testdouble": "^3.16.8",
"testdouble": "^3.20.2",
"yaml": "^2.1.3"
},
"overrides": {
"@commitlint/lint": "^18.6.1"
}
}

View file

@ -5,10 +5,10 @@ import { babel } from '@rollup/plugin-babel'
import pkg from './package.json'
export default {
input: 'run.js',
input: 'run.mjs',
external: (depName) =>
depName.includes('node_modules') && !depName.includes('node_modules/dargs'),
output: [{ file: pkg.main, format: 'cjs' }],
output: [{ file: pkg.module, format: 'es' }],
plugins: [
babel({
babelHelpers: 'bundled',

3
run.js
View file

@ -1,3 +0,0 @@
import action from './src/action'
action()

3
run.mjs Normal file
View file

@ -0,0 +1,3 @@
import action from './src/action.mjs'
action()

View file

@ -5,7 +5,7 @@ import { context as eventContext, getOctokit } from '@actions/github'
import lint from '@commitlint/lint'
import { format } from '@commitlint/format'
import load from '@commitlint/load'
import generateOutputs from './generateOutputs'
import generateOutputs from './generateOutputs.mjs'
const pullRequestEvent = 'pull_request'
const pullRequestTargetEvent = 'pull_request_target'
@ -102,6 +102,13 @@ const showLintResults = async (eventCommits) => {
if (commitDepth) {
commits = commits?.slice(0, commitDepth)
}
if (configPath?.endsWith('.js')) {
throw new Error(
'.js extension is not allowed for the `configFile`, please use .mjs instead',
)
}
const config = existsSync(configPath)
? await load({}, { file: configPath })
: await load({ extends: ['@commitlint/config-conventional'] })

View file

@ -1,14 +1,15 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-env jest */
import { git } from '@commitlint/test'
import { describe } from '@jest/globals'
import td from 'testdouble'
import { jest, describe, it } from '@jest/globals'
import * as td from 'testdouble'
import {
updatePushEnvVars,
createPushEventPayload,
createPullRequestEventPayload,
updatePullRequestEnvVars,
buildResponseCommit,
} from './testUtils'
} from './testUtils.mjs'
const resultsOutputId = 'results'
@ -18,39 +19,44 @@ const {
const initialEnv = { ...process.env }
const listCommits = td.func('listCommits')
const mockListCommits = td.func('listCommits')
const runAction = async () => {
const github = await import('@actions/github')
const mockCore = td.object(['getInput', 'setFailed', 'setOutput'])
jest.unstable_mockModule('@actions/core', () => mockCore)
jest.unstable_mockModule('@actions/github', () => {
class MockOctokit {
constructor() {
this.rest = {
pulls: {
listCommits,
listCommits: mockListCommits,
},
}
}
}
td.replace(github, 'getOctokit', () => new MockOctokit())
return {
...jest.requireActual('@actions/github'),
getOctokit: () => new MockOctokit(),
}
})
const action = (await import('./action')).default
const runAction = async () => {
const action = (await import('./action.mjs')).default
return action()
}
describe('Commit Linter action', () => {
let core
let cwd
beforeEach(async () => {
core = await import('@actions/core')
td.replace(core, 'getInput')
td.replace(core, 'setFailed')
td.replace(core, 'setOutput')
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
td.when(core.getInput('failOnWarnings')).thenReturn('false')
td.when(core.getInput('helpURL')).thenReturn(
td.when(mockCore.getInput('configFile')).thenReturn(
'./commitlint.config.mjs',
)
td.when(mockCore.getInput('failOnWarnings')).thenReturn('false')
td.when(mockCore.getInput('helpURL')).thenReturn(
'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
)
})
@ -62,8 +68,10 @@ describe('Commit Linter action', () => {
})
it('should use default config when config file does not exist', async () => {
td.when(core.getInput('configFile')).thenReturn('./not-existing-config.js')
cwd = await git.bootstrap('fixtures/conventional')
td.when(mockCore.getInput('configFile')).thenReturn(
'./not-existing-config.mjs',
)
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, {
commits: [
{
@ -77,9 +85,11 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(contains('You have commit messages with errors')))
td.verify(
core.setFailed(
mockCore.setFailed(contains('You have commit messages with errors')),
)
td.verify(
mockCore.setFailed(
contains(
'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
),
@ -87,8 +97,11 @@ describe('Commit Linter action', () => {
)
})
it('should fail for single push with incorrect message', async () => {
cwd = await git.bootstrap('fixtures/conventional')
it('should fail when using js extension', async () => {
td.when(mockCore.getInput('configFile')).thenReturn(
'./commitlint.config.js',
)
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, {
commits: [
{
@ -102,11 +115,31 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(contains('You have commit messages with errors')))
td.verify(mockCore.setFailed(contains('.js extension is not allowed')))
})
it('should fail for single push with incorrect message', async () => {
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, {
commits: [
{
id: 'wrong-message',
message: 'wrong message',
},
],
})
updatePushEnvVars(cwd)
td.replace(process, 'cwd', () => cwd)
await runAction()
td.verify(
mockCore.setFailed(contains('You have commit messages with errors')),
)
})
it('should fail for push range with wrong messages', async () => {
cwd = await git.bootstrap('fixtures/conventional')
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, {
commits: [
{
@ -123,13 +156,13 @@ describe('Commit Linter action', () => {
td.replace(process, 'cwd', () => cwd)
await runAction()
td.verify(core.setFailed(contains('wrong message 1')))
td.verify(core.setFailed(contains('wrong message 2')))
td.verify(mockCore.setFailed(contains('wrong message 1')))
td.verify(mockCore.setFailed(contains('wrong message 2')))
})
it('should pass for push range with wrong messages with failOnErrors set to false', async () => {
td.when(core.getInput('failOnErrors')).thenReturn('false')
cwd = await git.bootstrap('fixtures/conventional')
td.when(mockCore.getInput('failOnErrors')).thenReturn('false')
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, {
commits: [
{
@ -148,15 +181,15 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(mockCore.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log(contains('wrong message 1')))
td.verify(console.log(contains('wrong message 2')))
td.verify(console.log(contains('Passing despite errors ✅')))
})
it('should pass for push range with correct messages with failOnErrors set to false', async () => {
td.when(core.getInput('failOnErrors')).thenReturn('false')
cwd = await git.bootstrap('fixtures/conventional')
td.when(mockCore.getInput('failOnErrors')).thenReturn('false')
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, {
commits: [
{
@ -175,12 +208,12 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(mockCore.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log('Lint free! 🎉'))
})
it('should pass for push range with correct messages', async () => {
cwd = await git.bootstrap('fixtures/conventional')
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, {
commits: [
{
@ -199,13 +232,15 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(mockCore.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log('Lint free! 🎉'))
})
it('should fail for commit with scope that is not a lerna package', async () => {
cwd = await git.bootstrap('fixtures/lerna-scopes')
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.yml')
cwd = await git.bootstrap('fixtures/lerna-scopes', process.cwd())
td.when(mockCore.getInput('configFile')).thenReturn(
'./commitlint.config.yml',
)
await createPushEventPayload(cwd, {
commits: [
{
@ -219,13 +254,15 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(
core.setFailed(contains('chore(wrong): not including package scope')),
mockCore.setFailed(contains('chore(wrong): not including package scope')),
)
})
it('should pass for scope that is a lerna package', async () => {
cwd = await git.bootstrap('fixtures/lerna-scopes')
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.yml')
cwd = await git.bootstrap('fixtures/lerna-scopes', process.cwd())
td.when(mockCore.getInput('configFile')).thenReturn(
'./commitlint.config.yml',
)
await createPushEventPayload(cwd, {
commits: [
{
@ -244,8 +281,10 @@ describe('Commit Linter action', () => {
})
it("should fail for commit that doesn't comply with jira rules", async () => {
cwd = await git.bootstrap('fixtures/jira')
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
cwd = await git.bootstrap('fixtures/jira', process.cwd())
td.when(mockCore.getInput('configFile')).thenReturn(
'./commitlint.config.mjs',
)
await createPushEventPayload(cwd, {
commits: [
{
@ -260,30 +299,32 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(
core.setFailed(contains('ib-21212121212121: without jira ticket')),
mockCore.setFailed(contains('ib-21212121212121: without jira ticket')),
)
td.verify(
core.setFailed(
mockCore.setFailed(
contains(
'ib-21212121212121 taskId must not be longer than 9 characters',
),
),
)
td.verify(
core.setFailed(
mockCore.setFailed(
contains('ib-21212121212121 taskId must be uppercase case'),
),
)
td.verify(
core.setFailed(
mockCore.setFailed(
contains('ib-21212121212121 commitStatus must be uppercase case'),
),
)
})
it('should pass when commits are not available', async () => {
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
cwd = await git.bootstrap('fixtures/conventional')
td.when(mockCore.getInput('configFile')).thenReturn(
'./commitlint.config.mjs',
)
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, {})
updatePushEnvVars(cwd)
td.replace(process, 'cwd', () => cwd)
@ -291,7 +332,7 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(mockCore.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log('Lint free! 🎉'))
})
@ -306,14 +347,14 @@ describe('Commit Linter action', () => {
)
beforeEach(async () => {
cwd = await git.bootstrap('fixtures/conventional')
td.when(core.getInput('configFile')).thenReturn(
'./commitlint.config.js',
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
td.when(mockCore.getInput('configFile')).thenReturn(
'./commitlint.config.mjs',
)
await createPullRequestEventPayload(cwd)
updatePullRequestEnvVars(cwd, { eventName })
td.when(
listCommits({
mockListCommits({
owner: 'wagoid',
repo: 'commitlint-github-action',
pull_number: '1',
@ -345,7 +386,7 @@ describe('Commit Linter action', () => {
it('should NOT show errors for a message from before the push', async () => {
await runAction()
td.verify(core.setFailed(contains('message from before push')), {
td.verify(mockCore.setFailed(contains('message from before push')), {
times: 0,
})
})
@ -353,31 +394,33 @@ describe('Commit Linter action', () => {
it('should show errors for the first wrong message', async () => {
await runAction()
td.verify(core.setFailed(contains(firstCommit.commit.message)))
td.verify(mockCore.setFailed(contains(firstCommit.commit.message)))
})
it('should show errors for the second wrong message', async () => {
await runAction()
td.verify(core.setFailed(contains(secondCommit.commit.message)))
td.verify(mockCore.setFailed(contains(secondCommit.commit.message)))
})
it('should generate a JSON output of the errors', async () => {
await runAction()
td.verify(core.setOutput(resultsOutputId, expectedResultsOutput))
td.verify(mockCore.setOutput(resultsOutputId, expectedResultsOutput))
})
},
)
describe('when it fails to fetch commits', () => {
beforeEach(async () => {
cwd = await git.bootstrap('fixtures/conventional')
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
td.when(mockCore.getInput('configFile')).thenReturn(
'./commitlint.config.mjs',
)
await createPullRequestEventPayload(cwd)
updatePullRequestEnvVars(cwd)
td.when(
listCommits({
mockListCommits({
owner: 'wagoid',
repo: 'commitlint-github-action',
pull_number: '1',
@ -391,7 +434,7 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(
core.setFailed(
mockCore.setFailed(
contains("error trying to get list of pull request's commits"),
),
)
@ -400,7 +443,7 @@ describe('Commit Linter action', () => {
it('should show the original error message', async () => {
await runAction()
td.verify(core.setFailed(contains('HttpError: Bad credentials')))
td.verify(mockCore.setFailed(contains('HttpError: Bad credentials')))
})
})
@ -411,7 +454,7 @@ describe('Commit Linter action', () => {
}
beforeEach(async () => {
cwd = await git.bootstrap('fixtures/conventional')
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, { commits: [commit] })
updatePushEnvVars(cwd)
td.replace(process, 'cwd', () => cwd)
@ -421,7 +464,7 @@ describe('Commit Linter action', () => {
it('should pass', async () => {
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(mockCore.setFailed(), { times: 0, ignoreExtraArgs: true })
})
it('should show success message', async () => {
@ -443,7 +486,7 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setOutput(resultsOutputId, expectedResultsOutput))
td.verify(mockCore.setOutput(resultsOutputId, expectedResultsOutput))
})
})
@ -460,7 +503,7 @@ describe('Commit Linter action', () => {
message:
'chore: correct message\nsome context without leading blank line',
}
cwd = await git.bootstrap('fixtures/conventional')
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, {
commits: [commitWithWarning, correctCommit],
})
@ -490,33 +533,33 @@ describe('Commit Linter action', () => {
it('should pass and show that warnings exist', async () => {
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(mockCore.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log(contains('You have commit messages with warnings')))
})
it('should show the results in an output', async () => {
await runAction()
td.verify(core.setOutput(resultsOutputId, expectedResultsOutput))
td.verify(mockCore.setOutput(resultsOutputId, expectedResultsOutput))
})
describe('and failOnWarnings is set to true', () => {
beforeEach(() => {
td.when(core.getInput('failOnWarnings')).thenReturn('true')
td.when(mockCore.getInput('failOnWarnings')).thenReturn('true')
})
it('should fail', async () => {
await runAction()
td.verify(
core.setFailed(contains('You have commit messages with errors')),
mockCore.setFailed(contains('You have commit messages with errors')),
)
})
it('should show the results in an output', async () => {
await runAction()
td.verify(core.setOutput(resultsOutputId, expectedResultsOutput))
td.verify(mockCore.setOutput(resultsOutputId, expectedResultsOutput))
})
})
})
@ -533,7 +576,7 @@ describe('Commit Linter action', () => {
}
beforeEach(async () => {
cwd = await git.bootstrap('fixtures/conventional')
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, {
commits: [wrongCommit, commitWithWarning],
})
@ -546,7 +589,7 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(
core.setFailed(contains('You have commit messages with errors')),
mockCore.setFailed(contains('You have commit messages with errors')),
)
})
@ -571,19 +614,19 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setOutput(resultsOutputId, expectedResultsOutput))
td.verify(mockCore.setOutput(resultsOutputId, expectedResultsOutput))
})
describe('and failOnWarnings is set to true', () => {
beforeEach(() => {
td.when(core.getInput('failOnWarnings')).thenReturn('true')
td.when(mockCore.getInput('failOnWarnings')).thenReturn('true')
})
it('should fail', async () => {
await runAction()
td.verify(
core.setFailed(contains('You have commit messages with errors')),
mockCore.setFailed(contains('You have commit messages with errors')),
)
})
})
@ -591,7 +634,7 @@ describe('Commit Linter action', () => {
describe('when commit contains required signed-off-by message', () => {
beforeEach(async () => {
cwd = await git.bootstrap('fixtures/signed-off-by')
cwd = await git.bootstrap('fixtures/signed-off-by', process.cwd())
await createPushEventPayload(cwd, {
commits: [
{
@ -609,14 +652,14 @@ describe('Commit Linter action', () => {
it('should pass', async () => {
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(mockCore.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log('Lint free! 🎉'))
})
})
describe('when a different helpUrl is provided in the config', () => {
beforeEach(async () => {
cwd = await git.bootstrap('fixtures/custom-help-url')
cwd = await git.bootstrap('fixtures/custom-help-url', process.cwd())
await createPushEventPayload(cwd, {
commits: [
{
@ -634,9 +677,9 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(
core.setFailed(contains('You have commit messages with errors')),
mockCore.setFailed(contains('You have commit messages with errors')),
)
td.verify(core.setFailed(contains(' https://example.org')))
td.verify(mockCore.setFailed(contains(' https://example.org')))
})
})
@ -647,7 +690,7 @@ describe('Commit Linter action', () => {
}
beforeEach(async () => {
cwd = await git.bootstrap('fixtures/conventional')
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
await createPushEventPayload(cwd, {
commits: [
{ id: 'correct-commit', message: 'chore: correct message 2' },
@ -660,25 +703,25 @@ describe('Commit Linter action', () => {
})
it('should pass when only considering messages defined by commitDepth', async () => {
td.when(core.getInput('commitDepth')).thenReturn('1')
td.when(mockCore.getInput('commitDepth')).thenReturn('1')
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(mockCore.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log('Lint free! 🎉'))
})
it('should fail when older commits have lint errors', async () => {
td.when(core.getInput('commitDepth')).thenReturn('2')
td.when(mockCore.getInput('commitDepth')).thenReturn('2')
await runAction()
td.verify(core.setFailed(contains(incorrectCommit.message)))
td.verify(mockCore.setFailed(contains(incorrectCommit.message)))
})
it('should consider all commits when an invalid commit depth is passed in config', async () => {
td.when(core.getInput('commitDepth')).thenReturn('xzy')
td.when(mockCore.getInput('commitDepth')).thenReturn('xzy')
await runAction()
td.verify(core.setFailed(contains(incorrectCommit.message)))
td.verify(mockCore.setFailed(contains(incorrectCommit.message)))
})
})
})