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

fix: rollback update of commitlint to support configs that use commonjs

This commit is contained in:
Wagner Santos 2024-03-28 16:29:46 -03:00
parent e15adf3661
commit 06143b235b
17 changed files with 3576 additions and 5435 deletions

View file

@ -19,10 +19,5 @@
"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+/
exports.readVersion = (contents) =>
module.exports.readVersion = (contents) =>
yaml.parse(contents).runs.image.match(versionRegex)[0]
exports.writeVersion = (contents, version) => {
module.exports.writeVersion = (contents, version) => {
const actionFile = yaml.parse(contents)
actionFile.runs.image = actionFile.runs.image.replace(versionRegex, version)

View file

@ -53,11 +53,7 @@ jobs:
git config user.email 'github-action@users.noreply.github.com'
git config user.name 'GitHub Action'
- name: Update versions and changelog
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
git checkout package.json
run: npx commit-and-tag-version
- name: Set VERSION env var
run: |
version=`node -p "require('./package.json').version"`

View file

@ -1,4 +1,4 @@
export default {
module.exports = {
'*.{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:20.9.0-alpine3.17 as build
FROM node:16.14.2-alpine3.14 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.mjs /run.mjs
COPY --from=build dist/run.js /run.js
COPY package*.json /

View file

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

View file

@ -5,13 +5,11 @@ 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"
export NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules"
node /run.mjs
node /run.js

View file

@ -1,12 +1,10 @@
export default {
module.exports = {
// 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)'],
}

8721
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

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

View file

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

3
run.js Normal file
View file

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

View file

@ -1,3 +0,0 @@
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.mjs'
import generateOutputs from './generateOutputs'
const pullRequestEvent = 'pull_request'
const pullRequestTargetEvent = 'pull_request_target'

View file

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