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

Merge pull request #197 from wagoid/fix/build-the-action-with-rollup

fix: build the action with rollup
This commit is contained in:
Wagner Santos 2021-07-17 12:22:08 -03:00 committed by GitHub
commit 974c6904bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 15924 additions and 93 deletions

View file

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

View file

@ -18,12 +18,6 @@
"no-process-exit": "off",
"node/no-unpublished-require": "off",
"node/no-unpublished-import": "off",
"node/no-unsupported-features/es-syntax": "off",
"import/extensions": [
"error",
{
"js": "always"
}
]
"node/no-unsupported-features/es-syntax": "off"
}
}

3
.gitignore vendored
View file

@ -59,3 +59,6 @@ typings/
# next.js build output
.next
# Dist files
dist

2
.nvmrc
View file

@ -1 +1 @@
16
16.5.0

View file

@ -5,7 +5,7 @@
"package-lock.json",
{
"filename": "action.yml",
"updater": "./.github/tasks/actionYamlUpdater.cjs"
"updater": "./.github/tasks/actionYamlUpdater.js"
}
],
"releaseCommitMessageFormat": "chore(release): publish {{currentTag}} [skip-ci]"

View file

@ -18,7 +18,6 @@ All notable changes to this project will be documented in this file. See [standa
* Node.js version used on the action updated from 12 to
16
* Config files now need to be renamed from .js to .cjs
### Features

View file

@ -1,11 +1,23 @@
FROM node:16-alpine3.13
FROM node:16.5.0-alpine3.14 as build
COPY package*.json /
RUN npm ci --ignore-scripts
COPY . .
RUN npm run build
FROM node:16.5.0-alpine3.14
RUN apk --no-cache add git
COPY --from=build dist/run.js /run.js
COPY package*.json /
RUN npm ci --production --ignore-scripts
COPY . .
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View file

@ -32,7 +32,7 @@ You can supply these inputs to the `wagoid/commitlint-github-action@v3` step.
The path to your commitlint config file.
Default: `commitlint.config.cjs`
Default: `commitlint.config.js`
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.

View file

@ -3,19 +3,20 @@ description: Lints Pull Request commit messages with commitlint
author: Wagner Santos
inputs:
configFile:
description: Commitlint config file. If the file doesn't exist, config-conventional settings will be
description:
Commitlint config file. If the file doesn't exist, config-conventional settings will be
loaded as a fallback.
default: ./commitlint.config.cjs
default: ./commitlint.config.js
required: false
firstParent:
description: >
When set to true, we follow only the first parent commit when seeing a merge commit. More info
in git-log docs https://git-scm.com/docs/git-log#Documentation/git-log.txt---first-parent
default: "true"
default: 'true'
required: false
failOnWarnings:
description: Whether you want to fail on warnings or not
default: "false"
default: 'false'
required: false
helpURL:
description: Link to a page explaining your commit message convention

6
babel.config.json Normal file
View file

@ -0,0 +1,6 @@
{
"presets": [["@babel/preset-env"]],
"targets": {
"node": "16.5.0"
}
}

View file

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

15855
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,17 +3,17 @@
"version": "4.0.2",
"description": "commitlint github action",
"private": true,
"exports": "./run.js",
"main": "./dist/run.js",
"scripts": {
"postinstall": "husky install",
"test": "NODE_PATH=./node_modules node --experimental-vm-modules node_modules/.bin/jest",
"test": "NODE_PATH=./node_modules jest",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"lint": "eslint ."
"lint": "eslint .",
"build": "rollup -c"
},
"engines": {
"node": ">=16.0.0"
"node": "16.5.0"
},
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/wagoid/commitlint-github-action.git"
@ -39,11 +39,17 @@
"lerna": "^4.0.0"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@commitlint/cli": "^12.1.4",
"@commitlint/ensure": "^12.1.4",
"@commitlint/test": "^9.0.1",
"@commitlint/test-environment": "^9.0.1",
"@jest/globals": "^27.0.6",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^19.0.1",
"@rollup/plugin-node-resolve": "^13.0.1",
"babel-jest": "^27.0.6",
"commitlint-plugin-function-rules": "^1.3.2",
"conventional-changelog-cli": "^2.1.1",
"eslint": "^7.29.0",
@ -57,6 +63,7 @@
"jest": "^27.0.6",
"lint-staged": "^11.0.1",
"prettier": "^2.3.2",
"rollup": "^2.53.2",
"standard-version": "^9.3.1",
"testdouble": "^3.16.1",
"yaml": "^1.10.2"

23
rollup.config.js Normal file
View file

@ -0,0 +1,23 @@
import path from 'path'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { babel } from '@rollup/plugin-babel'
import pkg from './package.json'
export default {
input: 'run.js',
external: (depName) =>
depName.includes('node_modules') && !depName.includes('node_modules/dargs'),
output: [{ file: pkg.main, format: 'cjs' }],
plugins: [
babel({
babelHelpers: 'bundled',
configFile: path.resolve(__dirname, 'babel.config.json'),
exclude: ['node_modules/(?!dargs)'],
}),
nodeResolve({
preferBuiltins: true,
}),
commonjs(),
],
}

2
run.js
View file

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

View file

@ -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 = () =>

View file

@ -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)

View file

@ -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