Skip to content

Commit

Permalink
feat: require actionlint version
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Nov 16, 2024
1 parent db7cfde commit ef4da1c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions cfg/_cnst.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ module.exports = {
eslintExtensions: 'ts,tsx,cts,mts,vue,html',
stylelintExtensions: 'css,scss',
lintExclude: ['./**/__exclude/**', './**/dist/**', './**/cache/**', './CHANGELOG.md'],
minActionlintVersion: '1.7.4',
}
29 changes: 29 additions & 0 deletions cfg/lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ console.log(`lint-staged.config.js runs on node ${node} ${platform} ${arch}`)
const fs = require('node:fs')
const micromatch = require('micromatch')
const { execSync } = require('node:child_process')
const { _assert, semver2 } = require('@naturalcycles/js-lib')
const { exec2 } = require('@naturalcycles/nodejs-lib')

const {
prettierDirs,
prettierExtensionsExclusive,
prettierExtensionsAll,
stylelintExtensions,
lintExclude,
minActionlintVersion,
} = require('./_cnst')

const prettierConfigPath = [`prettier.config.js`].find(fs.existsSync)
Expand Down Expand Up @@ -129,6 +133,8 @@ const linters = {
return []
}

requireActionlintVersion()

// run actionlint on all files at once, as it's fast anyway
return [`actionlint`]
},
Expand Down Expand Up @@ -192,4 +198,27 @@ function canRunBinary(name) {
}
}

function requireActionlintVersion() {
const version = getActionLintVersion()
if (!version) {
return
}

console.log(`actionlint version: ${version}`)

_assert(
semver2(version).isSameOrAfter(minActionlintVersion),
`actionlint needs to be updated. Min accepted version: ${minActionlintVersion}, local version: ${version}\nThis is how to install/update it: https://github.com/rhysd/actionlint/blob/main/docs/install.md`,
)
}

function getActionLintVersion() {
try {
return exec2.exec('actionlint --version').split('\n')[0]
} catch (err) {
console.log(err)
return undefined
}
}

module.exports = linters
29 changes: 28 additions & 1 deletion src/lint.util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import cp from 'node:child_process'
import fs from 'node:fs'
import { _isTruthy, _since, _truncate, UnixTimestampMillis } from '@naturalcycles/js-lib'
import {
_assert,
_isTruthy,
_since,
_truncate,
semver2,
SemVerString,
UnixTimestampMillis,
} from '@naturalcycles/js-lib'
import { boldGrey, dimGrey, exec2, git2 } from '@naturalcycles/nodejs-lib'
import yargs from 'yargs'
import { cfgDir, scriptsDir } from './paths'
Expand All @@ -10,6 +18,7 @@ const {
stylelintExtensions,
eslintExtensions,
lintExclude,
minActionlintVersion,
} = require('../cfg/_cnst')

/**
Expand Down Expand Up @@ -283,6 +292,7 @@ function runActionLint(): void {
if (!fs.existsSync('.github/workflows')) return

if (canRunBinary('actionlint')) {
requireActionlintVersion()
exec2.spawn(`actionlint`)
} else {
console.log(
Expand All @@ -291,6 +301,23 @@ function runActionLint(): void {
}
}

export function requireActionlintVersion(): void {
const version = getActionLintVersion()
if (!version) {
return
}

_assert(
semver2(version).isSameOrAfter(minActionlintVersion),
`actionlint needs to be updated. Min accepted version: ${minActionlintVersion}, local version: ${version}\nThis is how to install/update it: https://github.com/rhysd/actionlint/blob/main/docs/install.md`,
)
}

export function getActionLintVersion(): SemVerString | undefined {
if (!canRunBinary('actionlint')) return
return exec2.exec('actionlint --version').split('\n')[0]
}

export function runBiome(fix = true): void {
// if (!fs.existsSync(`node_modules/@biomejs/biome`)) {
// if (verbose) {
Expand Down

0 comments on commit ef4da1c

Please sign in to comment.