diff --git a/cfg/_cnst.js b/cfg/_cnst.js index 6340530..5077724 100644 --- a/cfg/_cnst.js +++ b/cfg/_cnst.js @@ -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', } diff --git a/cfg/lint-staged.config.js b/cfg/lint-staged.config.js index 5fdf3b0..ee51029 100644 --- a/cfg/lint-staged.config.js +++ b/cfg/lint-staged.config.js @@ -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) @@ -129,6 +133,8 @@ const linters = { return [] } + requireActionlintVersion() + // run actionlint on all files at once, as it's fast anyway return [`actionlint`] }, @@ -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 diff --git a/src/lint.util.ts b/src/lint.util.ts index a940fd7..73d1d55 100644 --- a/src/lint.util.ts +++ b/src/lint.util.ts @@ -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' @@ -10,6 +18,7 @@ const { stylelintExtensions, eslintExtensions, lintExclude, + minActionlintVersion, } = require('../cfg/_cnst') /** @@ -283,6 +292,7 @@ function runActionLint(): void { if (!fs.existsSync('.github/workflows')) return if (canRunBinary('actionlint')) { + requireActionlintVersion() exec2.spawn(`actionlint`) } else { console.log( @@ -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) {