mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 08:06:54 +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"],
|
||||
"plugins": ["prettier"],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2020,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"settings": {
|
||||
"import/resolver": {
|
||||
"node": {
|
||||
"extensions": [".js"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"prettier/prettier": "error",
|
||||
"no-console": "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
|
||||
clearMocks: true,
|
||||
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",
|
||||
"description": "commitlint github action",
|
||||
"private": true,
|
||||
"main": "run.js",
|
||||
"exports": "./run.js",
|
||||
"scripts": {
|
||||
"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",
|
||||
"lint": "eslint ."
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
},
|
||||
"type": "module",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/wagoid/commitlint-github-action.git"
|
||||
|
|
@ -30,18 +31,19 @@
|
|||
"@commitlint/format": "^12.1.4",
|
||||
"@commitlint/lint": "^12.1.4",
|
||||
"@commitlint/load": "^12.1.4",
|
||||
"commitlint-config-jira": "^1.4.1",
|
||||
"commitlint-plugin-jira-rules": "^1.4.0",
|
||||
"commitlint-config-jira": "^1.5.1",
|
||||
"commitlint-plugin-jira-rules": "^1.5.1",
|
||||
"conventional-changelog-lint-config-canonical": "^1.0.0",
|
||||
"dargs": "^7.0.0",
|
||||
"execa": "^5.0.0",
|
||||
"lerna": "^3.22.1"
|
||||
"dargs": "^8.1.0",
|
||||
"execa": "^5.1.1",
|
||||
"lerna": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@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",
|
||||
"commitlint-plugin-function-rules": "^1.3.2",
|
||||
"conventional-changelog-cli": "^2.1.1",
|
||||
"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()
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
const { existsSync } = require('fs')
|
||||
const { resolve } = require('path')
|
||||
const core = require('@actions/core')
|
||||
const github = require('@actions/github')
|
||||
const lint = require('@commitlint/lint').default
|
||||
const { format } = require('@commitlint/format')
|
||||
const load = require('@commitlint/load').default
|
||||
const gitCommits = require('./gitCommits')
|
||||
const generateOutputs = require('./generateOutputs')
|
||||
import { existsSync } from 'fs'
|
||||
import { resolve } from 'path'
|
||||
import core from '@actions/core'
|
||||
import github from '@actions/github'
|
||||
import lintModule 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
|
||||
|
||||
const pullRequestEvent = 'pull_request'
|
||||
const pullRequestTargetEvent = 'pull_request_target'
|
||||
|
|
@ -159,4 +162,4 @@ const commitLinterAction = () =>
|
|||
.then(showLintResults)
|
||||
.catch(exitWithMessage('error running commitlint'))
|
||||
|
||||
module.exports = commitLinterAction
|
||||
export default commitLinterAction
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
/* eslint-disable global-require */
|
||||
/* eslint-env jest */
|
||||
const { git } = require('@commitlint/test')
|
||||
const execa = require('execa')
|
||||
const td = require('testdouble')
|
||||
const {
|
||||
import { jest } from '@jest/globals'
|
||||
import { git } from '@commitlint/test'
|
||||
import execa from 'execa'
|
||||
import td from 'testdouble'
|
||||
import {
|
||||
gitEmptyCommit,
|
||||
getCommitHashes,
|
||||
updatePushEnvVars,
|
||||
createPushEventPayload,
|
||||
createPullRequestEventPayload,
|
||||
updatePullRequestEnvVars,
|
||||
} = require('./testUtils')
|
||||
} from './testUtils.js'
|
||||
|
||||
const resultsOutputId = 'results'
|
||||
|
||||
|
|
@ -22,8 +22,8 @@ const initialEnv = { ...process.env }
|
|||
|
||||
const listCommits = td.func('listCommits')
|
||||
|
||||
const runAction = () => {
|
||||
const github = require('@actions/github')
|
||||
const runAction = async () => {
|
||||
const github = (await import('@actions/github')).default
|
||||
class MockOctokit {
|
||||
constructor() {
|
||||
this.pulls = {
|
||||
|
|
@ -34,15 +34,17 @@ const runAction = () => {
|
|||
|
||||
td.replace(github, 'getOctokit', () => new MockOctokit())
|
||||
|
||||
return require('./action')()
|
||||
const action = (await import('./action.js')).default
|
||||
|
||||
return action()
|
||||
}
|
||||
|
||||
describe('Commit Linter action', () => {
|
||||
let core
|
||||
let cwd
|
||||
|
||||
beforeEach(() => {
|
||||
core = require('@actions/core')
|
||||
beforeEach(async () => {
|
||||
core = (await import('@actions/core')).default
|
||||
td.replace(core, 'getInput')
|
||||
td.replace(core, 'setFailed')
|
||||
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 () => {
|
||||
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')
|
||||
const [to] = await getCommitHashes(cwd)
|
||||
await createPushEventPayload(cwd, { to })
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const core = require('@actions/core')
|
||||
import core from '@actions/core'
|
||||
|
||||
const resultsOutputId = 'results'
|
||||
|
||||
|
|
@ -21,4 +21,4 @@ const generateOutputs = (lintedCommits) => {
|
|||
core.setOutput(resultsOutputId, resultsOutput)
|
||||
}
|
||||
|
||||
module.exports = generateOutputs
|
||||
export default generateOutputs
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const dargs = require('dargs')
|
||||
const execa = require('execa')
|
||||
import dargs from 'dargs'
|
||||
import execa from 'execa'
|
||||
|
||||
const commitDelimiter = '--------->commit---------'
|
||||
|
||||
|
|
@ -40,4 +40,4 @@ const gitCommits = async (gitOpts) => {
|
|||
return commits
|
||||
}
|
||||
|
||||
module.exports = gitCommits
|
||||
export default gitCommits
|
||||
|
|
|
|||
|
|
@ -1,29 +1,27 @@
|
|||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const { promisify } = require('util')
|
||||
const execa = require('execa')
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import { promisify } from 'util'
|
||||
import execa from 'execa'
|
||||
|
||||
const writeFile = promisify(fs.writeFile)
|
||||
|
||||
const updateEnvVars = (envVars) => {
|
||||
export const updateEnvVars = (envVars) => {
|
||||
Object.keys(envVars).forEach((key) => {
|
||||
process.env[key] = envVars[key]
|
||||
})
|
||||
}
|
||||
|
||||
exports.updateEnvVars = updateEnvVars
|
||||
|
||||
exports.gitEmptyCommit = (cwd, message) =>
|
||||
export const gitEmptyCommit = (cwd, message) =>
|
||||
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 hashes = stdout.split('\n').reverse()
|
||||
|
||||
return hashes
|
||||
}
|
||||
|
||||
exports.updatePushEnvVars = (cwd, to) => {
|
||||
export const updatePushEnvVars = (cwd, to) => {
|
||||
updateEnvVars({
|
||||
GITHUB_WORKSPACE: cwd,
|
||||
GITHUB_EVENT_NAME: 'push',
|
||||
|
|
@ -31,7 +29,7 @@ exports.updatePushEnvVars = (cwd, to) => {
|
|||
})
|
||||
}
|
||||
|
||||
exports.createPushEventPayload = async (
|
||||
export const createPushEventPayload = async (
|
||||
cwd,
|
||||
{ before = null, to, forced = false },
|
||||
) => {
|
||||
|
|
@ -46,7 +44,7 @@ exports.createPushEventPayload = async (
|
|||
await writeFile(eventPath, JSON.stringify(payload), 'utf8')
|
||||
}
|
||||
|
||||
exports.createPullRequestEventPayload = async (cwd) => {
|
||||
export const createPullRequestEventPayload = async (cwd) => {
|
||||
const payload = {
|
||||
number: '1',
|
||||
repository: {
|
||||
|
|
@ -66,7 +64,7 @@ exports.createPullRequestEventPayload = async (cwd) => {
|
|||
await writeFile(eventPath, JSON.stringify(payload), 'utf8')
|
||||
}
|
||||
|
||||
exports.updatePullRequestEnvVars = (cwd, to, options = {}) => {
|
||||
export const updatePullRequestEnvVars = (cwd, to, options = {}) => {
|
||||
const { eventName = 'pull_request' } = options
|
||||
|
||||
updateEnvVars({
|
||||
|
|
|
|||
Loading…
Reference in a new issue