mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2026-04-03 16:26:53 +00:00
fix: build the action with rollup
On v4, we used the default nodejs resolution logic to allow ES modules in dependencies. This created a breaking change of forcing users of this action to use the .cjs extension instead of .js in config files. With this fix, we now bundle the action with rollup to allow ES modules in dependencies, while keeping the support for .js config files. With this change, the default config file was returned back to .js instead of .cjs. Fixes #194
This commit is contained in:
parent
0cb522abbc
commit
2e578124a5
23 changed files with 15924 additions and 93 deletions
|
|
@ -1,15 +1,12 @@
|
|||
import { existsSync } from 'fs'
|
||||
import { resolve } from 'path'
|
||||
import core from '@actions/core'
|
||||
import github from '@actions/github'
|
||||
import lintModule from '@commitlint/lint'
|
||||
import { getInput, setFailed } from '@actions/core'
|
||||
import { context as eventContext, getOctokit } from '@actions/github'
|
||||
import lint from '@commitlint/lint'
|
||||
import { format } from '@commitlint/format'
|
||||
import loadModule from '@commitlint/load'
|
||||
import gitCommits from './gitCommits.js'
|
||||
import generateOutputs from './generateOutputs.js'
|
||||
|
||||
const load = loadModule.default
|
||||
const lint = lintModule.default
|
||||
import load from '@commitlint/load'
|
||||
import gitCommits from './gitCommits'
|
||||
import generateOutputs from './generateOutputs'
|
||||
|
||||
const pullRequestEvent = 'pull_request'
|
||||
const pullRequestTargetEvent = 'pull_request_target'
|
||||
|
|
@ -17,12 +14,7 @@ const pullRequestEvents = [pullRequestEvent, pullRequestTargetEvent]
|
|||
|
||||
const { GITHUB_EVENT_NAME, GITHUB_SHA } = process.env
|
||||
|
||||
const configPath = resolve(
|
||||
process.env.GITHUB_WORKSPACE,
|
||||
core.getInput('configFile'),
|
||||
)
|
||||
|
||||
const { context: eventContext } = github
|
||||
const configPath = resolve(process.env.GITHUB_WORKSPACE, getInput('configFile'))
|
||||
|
||||
const pushEventHasOnlyOneCommit = (from) => {
|
||||
const gitEmptySha = '0000000000000000000000000000000000000000'
|
||||
|
|
@ -53,7 +45,7 @@ const getRangeForEvent = async () => {
|
|||
if (!pullRequestEvents.includes(GITHUB_EVENT_NAME))
|
||||
return getRangeForPushEvent()
|
||||
|
||||
const octokit = github.getOctokit(core.getInput('token'))
|
||||
const octokit = getOctokit(getInput('token'))
|
||||
const { owner, repo, number } = eventContext.issue
|
||||
const { data: commits } = await octokit.pulls.listCommits({
|
||||
owner,
|
||||
|
|
@ -75,7 +67,7 @@ function getHistoryCommits(from, to) {
|
|||
to,
|
||||
}
|
||||
|
||||
if (core.getInput('firstParent') === 'true') {
|
||||
if (getInput('firstParent') === 'true') {
|
||||
options.firstParent = true
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +96,7 @@ const formatErrors = (lintedCommits) =>
|
|||
{ results: lintedCommits.map((commit) => commit.lintResult) },
|
||||
{
|
||||
color: true,
|
||||
helpUrl: core.getInput('helpURL'),
|
||||
helpUrl: getInput('helpURL'),
|
||||
},
|
||||
)
|
||||
|
||||
|
|
@ -113,13 +105,13 @@ const hasOnlyWarnings = (lintedCommits) =>
|
|||
lintedCommits.every(({ lintResult }) => lintResult.valid) &&
|
||||
lintedCommits.some(({ lintResult }) => lintResult.warnings.length)
|
||||
|
||||
const setFailed = (formattedResults) => {
|
||||
core.setFailed(`You have commit messages with errors\n\n${formattedResults}`)
|
||||
const setFailedAction = (formattedResults) => {
|
||||
setFailed(`You have commit messages with errors\n\n${formattedResults}`)
|
||||
}
|
||||
|
||||
const handleOnlyWarnings = (formattedResults) => {
|
||||
if (core.getInput('failOnWarnings') === 'true') {
|
||||
setFailed(formattedResults)
|
||||
if (getInput('failOnWarnings') === 'true') {
|
||||
setFailedAction(formattedResults)
|
||||
} else {
|
||||
console.log(`You have commit messages with warnings\n\n${formattedResults}`)
|
||||
}
|
||||
|
|
@ -144,14 +136,14 @@ const showLintResults = async ([from, to]) => {
|
|||
if (hasOnlyWarnings(lintedCommits)) {
|
||||
handleOnlyWarnings(formattedResults)
|
||||
} else if (formattedResults) {
|
||||
setFailed(formattedResults)
|
||||
setFailedAction(formattedResults)
|
||||
} else {
|
||||
console.log('Lint free! 🎉')
|
||||
}
|
||||
}
|
||||
|
||||
const exitWithMessage = (message) => (error) => {
|
||||
core.setFailed(`${message}\n${error.message}\n${error.stack}`)
|
||||
setFailedAction(`${message}\n${error.message}\n${error.stack}`)
|
||||
}
|
||||
|
||||
const commitLinterAction = () =>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
/* eslint-env jest */
|
||||
import { jest } from '@jest/globals'
|
||||
import { git } from '@commitlint/test'
|
||||
import execa from 'execa'
|
||||
import td from 'testdouble'
|
||||
|
|
@ -10,7 +9,7 @@ import {
|
|||
createPushEventPayload,
|
||||
createPullRequestEventPayload,
|
||||
updatePullRequestEnvVars,
|
||||
} from './testUtils.js'
|
||||
} from './testUtils'
|
||||
|
||||
const resultsOutputId = 'results'
|
||||
|
||||
|
|
@ -23,7 +22,7 @@ const initialEnv = { ...process.env }
|
|||
const listCommits = td.func('listCommits')
|
||||
|
||||
const runAction = async () => {
|
||||
const github = (await import('@actions/github')).default
|
||||
const github = await import('@actions/github')
|
||||
class MockOctokit {
|
||||
constructor() {
|
||||
this.pulls = {
|
||||
|
|
@ -34,7 +33,7 @@ const runAction = async () => {
|
|||
|
||||
td.replace(github, 'getOctokit', () => new MockOctokit())
|
||||
|
||||
const action = (await import('./action.js')).default
|
||||
const action = (await import('./action')).default
|
||||
|
||||
return action()
|
||||
}
|
||||
|
|
@ -44,11 +43,11 @@ describe('Commit Linter action', () => {
|
|||
let cwd
|
||||
|
||||
beforeEach(async () => {
|
||||
core = (await import('@actions/core')).default
|
||||
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.cjs')
|
||||
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
|
||||
td.when(core.getInput('firstParent')).thenReturn('true')
|
||||
td.when(core.getInput('failOnWarnings')).thenReturn('false')
|
||||
td.when(core.getInput('helpURL')).thenReturn(
|
||||
|
|
@ -194,7 +193,7 @@ 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.cjs')
|
||||
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
|
||||
await gitEmptyCommit(cwd, 'ib-21212121212121: without jira ticket')
|
||||
const [to] = await getCommitHashes(cwd)
|
||||
await createPushEventPayload(cwd, { to })
|
||||
|
|
@ -273,7 +272,7 @@ describe('Commit Linter action', () => {
|
|||
beforeEach(async () => {
|
||||
cwd = await git.bootstrap('fixtures/conventional')
|
||||
td.when(core.getInput('configFile')).thenReturn(
|
||||
'./commitlint.config.cjs',
|
||||
'./commitlint.config.js',
|
||||
)
|
||||
await gitEmptyCommit(cwd, 'message from before push')
|
||||
await gitEmptyCommit(cwd, firstMessage)
|
||||
|
|
@ -341,7 +340,7 @@ describe('Commit Linter action', () => {
|
|||
describe('when it fails to fetch commits', () => {
|
||||
beforeEach(async () => {
|
||||
cwd = await git.bootstrap('fixtures/conventional')
|
||||
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.cjs')
|
||||
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
|
||||
await gitEmptyCommit(cwd, 'commit message')
|
||||
await createPullRequestEventPayload(cwd)
|
||||
const [to] = await getCommitHashes(cwd)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import core from '@actions/core'
|
||||
import { setOutput } from '@actions/core'
|
||||
|
||||
const resultsOutputId = 'results'
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ const mapResultOutput = ({
|
|||
const generateOutputs = (lintedCommits) => {
|
||||
const resultsOutput = lintedCommits.map(mapResultOutput)
|
||||
|
||||
core.setOutput(resultsOutputId, resultsOutput)
|
||||
setOutput(resultsOutputId, resultsOutput)
|
||||
}
|
||||
|
||||
export default generateOutputs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue