mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 16:06:56 +00:00
feat: update dependencies that needed to switch to ESM syntax
Some packages were updated to versions that now use ECMAScript modules, so this repo was updated to use ES modules using Node.js built-in support. Update was done using the great guide from @sindresorhus: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
This commit is contained in:
parent
9e5880e3f8
commit
5463926c07
17 changed files with 3076 additions and 12487 deletions
|
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
12
.versionrc.json
Normal 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]"
|
||||||
|
}
|
||||||
|
|
@ -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: {},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15411
package-lock.json
generated
15411
package-lock.json
generated
File diff suppressed because it is too large
Load diff
16
package.json
16
package.json
|
|
@ -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": ">=16.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"
|
||||||
|
|
@ -30,18 +31,19 @@
|
||||||
"@commitlint/format": "^12.1.4",
|
"@commitlint/format": "^12.1.4",
|
||||||
"@commitlint/lint": "^12.1.4",
|
"@commitlint/lint": "^12.1.4",
|
||||||
"@commitlint/load": "^12.1.4",
|
"@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.1.4",
|
"@commitlint/cli": "^12.1.4",
|
||||||
"@commitlint/ensure": "^12.1.4",
|
"@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.29.0",
|
"eslint": "^7.29.0",
|
||||||
|
|
|
||||||
2
run.js
2
run.js
|
|
@ -1,3 +1,3 @@
|
||||||
const action = require('./src/action')
|
import action from './src/action.js'
|
||||||
|
|
||||||
action()
|
action()
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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')
|
||||||
|
|
@ -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 })
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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({
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue