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 #189 from wagoid/chore/upgrade-deps

chore: upgrade dependencies
This commit is contained in:
Wagner Santos 2021-07-15 05:35:03 -03:00 committed by GitHub
commit 711b4f40aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 17587 additions and 11528 deletions

View file

@ -1,10 +1,29 @@
{ {
"extends": ["airbnb-base", "prettier", "plugin:node/recommended"], "extends": ["airbnb-base", "prettier", "plugin:node/recommended"],
"plugins": ["prettier"], "plugins": ["prettier"],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js"]
}
}
},
"rules": { "rules": {
"prettier/prettier": "error", "prettier/prettier": "error",
"no-console": "off", "no-console": "off",
"no-process-exit": "off", "no-process-exit": "off",
"node/no-unpublished-require": "off" "node/no-unpublished-require": "off",
"node/no-unpublished-import": "off",
"node/no-unsupported-features/es-syntax": "off",
"import/extensions": [
"error",
{
"js": "always"
}
]
} }
} }

2
.husky/.gitignore vendored
View file

@ -1 +1 @@
_ _

View file

@ -1,15 +0,0 @@
const actionYamlUpdater = require.resolve('./.github/tasks/actionYamlUpdater')
module.exports = {
packageFiles: ['package.json'],
bumpFiles: [
'package.json',
'package-lock.json',
{
filename: 'action.yml',
updater: actionYamlUpdater,
},
],
releaseCommitMessageFormat:
'chore(release): publish {{currentTag}} [skip-ci]',
}

12
.versionrc.json Normal file
View file

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

View file

@ -1,4 +1,4 @@
FROM node:12-alpine3.9 FROM node:16-alpine3.13
RUN apk --no-cache add git RUN apk --no-cache add git

View file

@ -1,5 +1,6 @@
module.exports = { export default {
// Automatically clear mock calls and instances between every test // Automatically clear mock calls and instances between every test
clearMocks: true, clearMocks: true,
testEnvironment: '@commitlint/test-environment', testEnvironment: '@commitlint/test-environment',
transform: {},
} }

28897
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,16 +3,17 @@
"version": "3.1.4", "version": "3.1.4",
"description": "commitlint github action", "description": "commitlint github action",
"private": true, "private": true,
"main": "run.js", "exports": "./run.js",
"scripts": { "scripts": {
"postinstall": "husky install", "postinstall": "husky install",
"test": "NODE_PATH=./node_modules jest", "test": "NODE_PATH=./node_modules node --experimental-vm-modules node_modules/.bin/jest",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"lint": "eslint ." "lint": "eslint ."
}, },
"engines": { "engines": {
"node": ">=12.0.0" "node": ">=16.0.0"
}, },
"type": "module",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/wagoid/commitlint-github-action.git" "url": "git+https://github.com/wagoid/commitlint-github-action.git"
@ -23,39 +24,40 @@
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.2.6",
"@actions/github": "^4.0.0", "@actions/github": "^4.0.0",
"@commitlint/config-angular": "^12.0.0", "@commitlint/config-angular": "^12.1.4",
"@commitlint/config-conventional": "^12.0.0", "@commitlint/config-conventional": "^12.1.4",
"@commitlint/config-lerna-scopes": "^12.0.0", "@commitlint/config-lerna-scopes": "^12.1.4",
"@commitlint/config-patternplate": "^12.0.0", "@commitlint/config-patternplate": "^12.1.4",
"@commitlint/format": "^12.0.0", "@commitlint/format": "^12.1.4",
"@commitlint/lint": "^12.0.0", "@commitlint/lint": "^12.1.4",
"@commitlint/load": "^12.0.0", "@commitlint/load": "^12.1.4",
"commitlint-config-jira": "^1.4.1", "commitlint-config-jira": "^1.5.1",
"commitlint-plugin-jira-rules": "^1.4.0", "commitlint-plugin-jira-rules": "^1.5.1",
"conventional-changelog-lint-config-canonical": "^1.0.0", "conventional-changelog-lint-config-canonical": "^1.0.0",
"dargs": "^7.0.0", "dargs": "^8.1.0",
"execa": "^5.0.0", "execa": "^5.1.1",
"lerna": "^3.22.1" "lerna": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^12.0.0", "@commitlint/cli": "^12.1.4",
"@commitlint/ensure": "^12.0.0", "@commitlint/ensure": "^12.1.4",
"@commitlint/test": "^9.0.1", "@commitlint/test": "^9.0.1",
"@commitlint/test-environment": "^9.0.1", "@commitlint/test-environment": "^9.0.1",
"@jest/globals": "^27.0.6",
"commitlint-plugin-function-rules": "^1.3.2", "commitlint-plugin-function-rules": "^1.3.2",
"conventional-changelog-cli": "^2.1.1", "conventional-changelog-cli": "^2.1.1",
"eslint": "^7.23.0", "eslint": "^7.29.0",
"eslint-config-airbnb-base": "^14.2.1", "eslint-config-airbnb-base": "^14.2.1",
"eslint-config-node": "^4.1.0", "eslint-config-node": "^4.1.0",
"eslint-config-prettier": "^7.2.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1", "eslint-plugin-import": "^2.23.4",
"eslint-plugin-node": "^11.1.0", "eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1", "eslint-plugin-prettier": "^3.4.0",
"husky": "^6.0.0", "husky": "^6.0.0",
"jest": "^26.6.3", "jest": "^27.0.6",
"lint-staged": "^10.5.4", "lint-staged": "^11.0.0",
"prettier": "^2.2.1", "prettier": "^2.3.2",
"standard-version": "^9.1.1", "standard-version": "^9.3.0",
"testdouble": "^3.16.1", "testdouble": "^3.16.1",
"yaml": "^1.10.2" "yaml": "^1.10.2"
} }

2
run.js
View file

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

View file

@ -1,12 +1,15 @@
const { existsSync } = require('fs') import { existsSync } from 'fs'
const { resolve } = require('path') import { resolve } from 'path'
const core = require('@actions/core') import core from '@actions/core'
const github = require('@actions/github') import github from '@actions/github'
const lint = require('@commitlint/lint').default import lintModule from '@commitlint/lint'
const { format } = require('@commitlint/format') import { format } from '@commitlint/format'
const load = require('@commitlint/load').default import loadModule from '@commitlint/load'
const gitCommits = require('./gitCommits') import gitCommits from './gitCommits.js'
const generateOutputs = require('./generateOutputs') import generateOutputs from './generateOutputs.js'
const load = loadModule.default
const lint = lintModule.default
const pullRequestEvent = 'pull_request' const pullRequestEvent = 'pull_request'
const pullRequestTargetEvent = 'pull_request_target' const pullRequestTargetEvent = 'pull_request_target'
@ -159,4 +162,4 @@ const commitLinterAction = () =>
.then(showLintResults) .then(showLintResults)
.catch(exitWithMessage('error running commitlint')) .catch(exitWithMessage('error running commitlint'))
module.exports = commitLinterAction export default commitLinterAction

View file

@ -1,16 +1,16 @@
/* eslint-disable global-require */
/* eslint-env jest */ /* eslint-env jest */
const { git } = require('@commitlint/test') import { jest } from '@jest/globals'
const execa = require('execa') import { git } from '@commitlint/test'
const td = require('testdouble') import execa from 'execa'
const { import td from 'testdouble'
import {
gitEmptyCommit, gitEmptyCommit,
getCommitHashes, getCommitHashes,
updatePushEnvVars, updatePushEnvVars,
createPushEventPayload, createPushEventPayload,
createPullRequestEventPayload, createPullRequestEventPayload,
updatePullRequestEnvVars, updatePullRequestEnvVars,
} = require('./testUtils') } from './testUtils.js'
const resultsOutputId = 'results' const resultsOutputId = 'results'
@ -22,8 +22,8 @@ const initialEnv = { ...process.env }
const listCommits = td.func('listCommits') const listCommits = td.func('listCommits')
const runAction = () => { const runAction = async () => {
const github = require('@actions/github') const github = (await import('@actions/github')).default
class MockOctokit { class MockOctokit {
constructor() { constructor() {
this.pulls = { this.pulls = {
@ -34,15 +34,17 @@ const runAction = () => {
td.replace(github, 'getOctokit', () => new MockOctokit()) td.replace(github, 'getOctokit', () => new MockOctokit())
return require('./action')() const action = (await import('./action.js')).default
return action()
} }
describe('Commit Linter action', () => { describe('Commit Linter action', () => {
let core let core
let cwd let cwd
beforeEach(() => { beforeEach(async () => {
core = require('@actions/core') core = (await import('@actions/core')).default
td.replace(core, 'getInput') td.replace(core, 'getInput')
td.replace(core, 'setFailed') td.replace(core, 'setFailed')
td.replace(core, 'setOutput') td.replace(core, 'setOutput')
@ -147,7 +149,7 @@ describe('Commit Linter action', () => {
cwd = await git.bootstrap('fixtures/conventional') cwd = await git.bootstrap('fixtures/conventional')
await gitEmptyCommit(cwd, 'message from before push') await gitEmptyCommit(cwd, 'message from before push')
await gitEmptyCommit(cwd, 'wrong message 1') await gitEmptyCommit(cwd, 'wrong message 1')
await gitEmptyCommit(cwd, 'chore(WRONG): message 2') await gitEmptyCommit(cwd, 'wrong message 2')
const [, , to] = await getCommitHashes(cwd) const [, , to] = await getCommitHashes(cwd)
await createPushEventPayload(cwd, { before: gitEmptySha, to }) await createPushEventPayload(cwd, { before: gitEmptySha, to })
updatePushEnvVars(cwd, to) updatePushEnvVars(cwd, to)
@ -156,7 +158,7 @@ describe('Commit Linter action', () => {
await runAction() await runAction()
td.verify(core.setFailed(contains('wrong message 1')), { times: 0 }) td.verify(core.setFailed(contains('wrong message 1')), { times: 0 })
td.verify(core.setFailed(contains('chore(WRONG): message 2'))) td.verify(core.setFailed(contains('wrong message 2')))
}) })
it('should fail for commit with scope that is not a lerna package', async () => { it('should fail for commit with scope that is not a lerna package', async () => {
@ -192,7 +194,7 @@ describe('Commit Linter action', () => {
it("should fail for commit that doesn't comply with jira rules", async () => { it("should fail for commit that doesn't comply with jira rules", async () => {
cwd = await git.bootstrap('fixtures/jira') cwd = await git.bootstrap('fixtures/jira')
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js') td.when(core.getInput('configFile')).thenReturn('./commitlint.config.cjs')
await gitEmptyCommit(cwd, 'ib-21212121212121: without jira ticket') await gitEmptyCommit(cwd, 'ib-21212121212121: without jira ticket')
const [to] = await getCommitHashes(cwd) const [to] = await getCommitHashes(cwd)
await createPushEventPayload(cwd, { to }) await createPushEventPayload(cwd, { to })
@ -551,4 +553,26 @@ describe('Commit Linter action', () => {
}) })
}) })
}) })
describe('when commit contains signed-off-by message', () => {
beforeEach(async () => {
cwd = await git.bootstrap('fixtures/conventional')
await gitEmptyCommit(
cwd,
'chore: correct message\n\nsome context without leading blank line\nSigned-off-by: John Doe <john.doe@example.com>',
)
const [to] = await getCommitHashes(cwd)
await createPushEventPayload(cwd, { to })
updatePushEnvVars(cwd, to)
td.replace(process, 'cwd', () => cwd)
td.replace(console, 'log')
})
it('should pass', async () => {
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log('Lint free! 🎉'))
})
})
}) })

View file

@ -1,4 +1,4 @@
const core = require('@actions/core') import core from '@actions/core'
const resultsOutputId = 'results' const resultsOutputId = 'results'
@ -21,4 +21,4 @@ const generateOutputs = (lintedCommits) => {
core.setOutput(resultsOutputId, resultsOutput) core.setOutput(resultsOutputId, resultsOutput)
} }
module.exports = generateOutputs export default generateOutputs

View file

@ -1,5 +1,5 @@
const dargs = require('dargs') import dargs from 'dargs'
const execa = require('execa') import execa from 'execa'
const commitDelimiter = '--------->commit---------' const commitDelimiter = '--------->commit---------'
@ -40,4 +40,4 @@ const gitCommits = async (gitOpts) => {
return commits return commits
} }
module.exports = gitCommits export default gitCommits

View file

@ -1,29 +1,27 @@
const path = require('path') import path from 'path'
const fs = require('fs') import fs from 'fs'
const { promisify } = require('util') import { promisify } from 'util'
const execa = require('execa') import execa from 'execa'
const writeFile = promisify(fs.writeFile) const writeFile = promisify(fs.writeFile)
const updateEnvVars = (envVars) => { export const updateEnvVars = (envVars) => {
Object.keys(envVars).forEach((key) => { Object.keys(envVars).forEach((key) => {
process.env[key] = envVars[key] process.env[key] = envVars[key]
}) })
} }
exports.updateEnvVars = updateEnvVars export const gitEmptyCommit = (cwd, message) =>
exports.gitEmptyCommit = (cwd, message) =>
execa('git', ['commit', '--allow-empty', '-m', message], { cwd }) execa('git', ['commit', '--allow-empty', '-m', message], { cwd })
exports.getCommitHashes = async (cwd) => { export const getCommitHashes = async (cwd) => {
const { stdout } = await execa.command('git log --pretty=%H', { cwd }) const { stdout } = await execa.command('git log --pretty=%H', { cwd })
const hashes = stdout.split('\n').reverse() const hashes = stdout.split('\n').reverse()
return hashes return hashes
} }
exports.updatePushEnvVars = (cwd, to) => { export const updatePushEnvVars = (cwd, to) => {
updateEnvVars({ updateEnvVars({
GITHUB_WORKSPACE: cwd, GITHUB_WORKSPACE: cwd,
GITHUB_EVENT_NAME: 'push', GITHUB_EVENT_NAME: 'push',
@ -31,7 +29,7 @@ exports.updatePushEnvVars = (cwd, to) => {
}) })
} }
exports.createPushEventPayload = async ( export const createPushEventPayload = async (
cwd, cwd,
{ before = null, to, forced = false }, { before = null, to, forced = false },
) => { ) => {
@ -46,7 +44,7 @@ exports.createPushEventPayload = async (
await writeFile(eventPath, JSON.stringify(payload), 'utf8') await writeFile(eventPath, JSON.stringify(payload), 'utf8')
} }
exports.createPullRequestEventPayload = async (cwd) => { export const createPullRequestEventPayload = async (cwd) => {
const payload = { const payload = {
number: '1', number: '1',
repository: { repository: {
@ -66,7 +64,7 @@ exports.createPullRequestEventPayload = async (cwd) => {
await writeFile(eventPath, JSON.stringify(payload), 'utf8') await writeFile(eventPath, JSON.stringify(payload), 'utf8')
} }
exports.updatePullRequestEnvVars = (cwd, to, options = {}) => { export const updatePullRequestEnvVars = (cwd, to, options = {}) => {
const { eventName = 'pull_request' } = options const { eventName = 'pull_request' } = options
updateEnvVars({ updateEnvVars({