Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08aa4bab47 |
@@ -6,7 +6,7 @@
|
|||||||
"+^v[4-9]+(\\.[0-9]+){0,2}$"
|
"+^v[4-9]+(\\.[0-9]+){0,2}$"
|
||||||
],
|
],
|
||||||
"branches": {
|
"branches": {
|
||||||
"main": "bbbca2ddaa5d8feaa63e36b76fdaad77386f024f"
|
"main": "043fb46d1a93c77aae656e7c1c64a875d1fc6a0a"
|
||||||
},
|
},
|
||||||
"defaultBranch": "main",
|
"defaultBranch": "main",
|
||||||
"tags": {
|
"tags": {
|
||||||
@@ -80,10 +80,13 @@
|
|||||||
"commit": "b7c566a772e6b6bfb58ed0dc250532a479d7789f"
|
"commit": "b7c566a772e6b6bfb58ed0dc250532a479d7789f"
|
||||||
},
|
},
|
||||||
"v7": {
|
"v7": {
|
||||||
"commit": "bbbca2ddaa5d8feaa63e36b76fdaad77386f024f"
|
"commit": "043fb46d1a93c77aae656e7c1c64a875d1fc6a0a"
|
||||||
},
|
},
|
||||||
"v7.0.0": {
|
"v7.0.0": {
|
||||||
"commit": "bbbca2ddaa5d8feaa63e36b76fdaad77386f024f"
|
"commit": "bbbca2ddaa5d8feaa63e36b76fdaad77386f024f"
|
||||||
|
},
|
||||||
|
"v7.0.1": {
|
||||||
|
"commit": "043fb46d1a93c77aae656e7c1c64a875d1fc6a0a"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"owner": "github",
|
|
||||||
"repo": "gh-aw-actions",
|
|
||||||
"patterns": [
|
|
||||||
"+^master$",
|
|
||||||
"+^v[0-9]+(\\.[0-9]+){0,2}$"
|
|
||||||
],
|
|
||||||
"branches": {},
|
|
||||||
"defaultBranch": "master",
|
|
||||||
"latestMajorVersions": 1,
|
|
||||||
"latestVersionsPerMajor": 3,
|
|
||||||
"tags": {
|
|
||||||
"v0.67.4": {
|
|
||||||
"commit": "2b3c275b3652caa01c2ebe31cbab50ec2df0f927",
|
|
||||||
"tag": "9d6ae06250fc0ec536a0e5f35de313b35bad7246"
|
|
||||||
},
|
|
||||||
"v0.68.0": {
|
|
||||||
"commit": "6715c81fe97e4bcbfa0734c3422491672ebda34f",
|
|
||||||
"tag": "0acfb4a691fe207cd8bc982ea5cb9d750d57a702"
|
|
||||||
},
|
|
||||||
"v0.68.1": {
|
|
||||||
"commit": "ea222e359276c0702a5f5203547ff9d88d0ddd76",
|
|
||||||
"tag": "2fe53acc038ba01c3bbdc767d4b25df31ca5bdfc"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
mkdir actions_upload-artifact
|
mkdir actions_upload-artifact
|
||||||
pushd actions_upload-artifact
|
pushd actions_upload-artifact
|
||||||
curl -s -S -L -o 'bbbca2ddaa5d8feaa63e36b76fdaad77386f024f.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/bbbca2ddaa5d8feaa63e36b76fdaad77386f024f'
|
curl -s -S -L -o '043fb46d1a93c77aae656e7c1c64a875d1fc6a0a.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/043fb46d1a93c77aae656e7c1c64a875d1fc6a0a'
|
||||||
curl -s -S -L -o 'bbbca2ddaa5d8feaa63e36b76fdaad77386f024f.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/bbbca2ddaa5d8feaa63e36b76fdaad77386f024f'
|
curl -s -S -L -o '043fb46d1a93c77aae656e7c1c64a875d1fc6a0a.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/043fb46d1a93c77aae656e7c1c64a875d1fc6a0a'
|
||||||
curl -s -S -L -o 'ea165f8d65b6e75b540449e92b4886f43607fa02.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/ea165f8d65b6e75b540449e92b4886f43607fa02'
|
curl -s -S -L -o 'ea165f8d65b6e75b540449e92b4886f43607fa02.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/ea165f8d65b6e75b540449e92b4886f43607fa02'
|
||||||
curl -s -S -L -o 'ea165f8d65b6e75b540449e92b4886f43607fa02.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/ea165f8d65b6e75b540449e92b4886f43607fa02'
|
curl -s -S -L -o 'ea165f8d65b6e75b540449e92b4886f43607fa02.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/ea165f8d65b6e75b540449e92b4886f43607fa02'
|
||||||
curl -s -S -L -o 'c7d193f32edcb7bfad88892161225aeda64e9392.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/c7d193f32edcb7bfad88892161225aeda64e9392'
|
curl -s -S -L -o 'c7d193f32edcb7bfad88892161225aeda64e9392.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/c7d193f32edcb7bfad88892161225aeda64e9392'
|
||||||
@@ -48,8 +48,10 @@ curl -s -S -L -o 'b7c566a772e6b6bfb58ed0dc250532a479d7789f.tar.gz' 'https://api.
|
|||||||
curl -s -S -L -o 'b7c566a772e6b6bfb58ed0dc250532a479d7789f.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/b7c566a772e6b6bfb58ed0dc250532a479d7789f'
|
curl -s -S -L -o 'b7c566a772e6b6bfb58ed0dc250532a479d7789f.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/b7c566a772e6b6bfb58ed0dc250532a479d7789f'
|
||||||
curl -s -S -L -o 'b7c566a772e6b6bfb58ed0dc250532a479d7789f.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/b7c566a772e6b6bfb58ed0dc250532a479d7789f'
|
curl -s -S -L -o 'b7c566a772e6b6bfb58ed0dc250532a479d7789f.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/b7c566a772e6b6bfb58ed0dc250532a479d7789f'
|
||||||
curl -s -S -L -o 'b7c566a772e6b6bfb58ed0dc250532a479d7789f.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/b7c566a772e6b6bfb58ed0dc250532a479d7789f'
|
curl -s -S -L -o 'b7c566a772e6b6bfb58ed0dc250532a479d7789f.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/b7c566a772e6b6bfb58ed0dc250532a479d7789f'
|
||||||
|
curl -s -S -L -o '043fb46d1a93c77aae656e7c1c64a875d1fc6a0a.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/043fb46d1a93c77aae656e7c1c64a875d1fc6a0a'
|
||||||
|
curl -s -S -L -o '043fb46d1a93c77aae656e7c1c64a875d1fc6a0a.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/043fb46d1a93c77aae656e7c1c64a875d1fc6a0a'
|
||||||
curl -s -S -L -o 'bbbca2ddaa5d8feaa63e36b76fdaad77386f024f.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/bbbca2ddaa5d8feaa63e36b76fdaad77386f024f'
|
curl -s -S -L -o 'bbbca2ddaa5d8feaa63e36b76fdaad77386f024f.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/bbbca2ddaa5d8feaa63e36b76fdaad77386f024f'
|
||||||
curl -s -S -L -o 'bbbca2ddaa5d8feaa63e36b76fdaad77386f024f.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/bbbca2ddaa5d8feaa63e36b76fdaad77386f024f'
|
curl -s -S -L -o 'bbbca2ddaa5d8feaa63e36b76fdaad77386f024f.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/bbbca2ddaa5d8feaa63e36b76fdaad77386f024f'
|
||||||
curl -s -S -L -o 'bbbca2ddaa5d8feaa63e36b76fdaad77386f024f.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/bbbca2ddaa5d8feaa63e36b76fdaad77386f024f'
|
curl -s -S -L -o '043fb46d1a93c77aae656e7c1c64a875d1fc6a0a.tar.gz' 'https://api.github.com/repos/actions/upload-artifact/tarball/043fb46d1a93c77aae656e7c1c64a875d1fc6a0a'
|
||||||
curl -s -S -L -o 'bbbca2ddaa5d8feaa63e36b76fdaad77386f024f.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/bbbca2ddaa5d8feaa63e36b76fdaad77386f024f'
|
curl -s -S -L -o '043fb46d1a93c77aae656e7c1c64a875d1fc6a0a.zip' 'https://api.github.com/repos/actions/upload-artifact/zipball/043fb46d1a93c77aae656e7c1c64a875d1fc6a0a'
|
||||||
popd
|
popd
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
mkdir github_gh-aw-actions
|
|
||||||
pushd github_gh-aw-actions
|
|
||||||
curl -s -S -L -o '2b3c275b3652caa01c2ebe31cbab50ec2df0f927.tar.gz' 'https://api.github.com/repos/github/gh-aw-actions/tarball/2b3c275b3652caa01c2ebe31cbab50ec2df0f927'
|
|
||||||
curl -s -S -L -o '2b3c275b3652caa01c2ebe31cbab50ec2df0f927.zip' 'https://api.github.com/repos/github/gh-aw-actions/zipball/2b3c275b3652caa01c2ebe31cbab50ec2df0f927'
|
|
||||||
curl -s -S -L -o '6715c81fe97e4bcbfa0734c3422491672ebda34f.tar.gz' 'https://api.github.com/repos/github/gh-aw-actions/tarball/6715c81fe97e4bcbfa0734c3422491672ebda34f'
|
|
||||||
curl -s -S -L -o '6715c81fe97e4bcbfa0734c3422491672ebda34f.zip' 'https://api.github.com/repos/github/gh-aw-actions/zipball/6715c81fe97e4bcbfa0734c3422491672ebda34f'
|
|
||||||
curl -s -S -L -o 'ea222e359276c0702a5f5203547ff9d88d0ddd76.tar.gz' 'https://api.github.com/repos/github/gh-aw-actions/tarball/ea222e359276c0702a5f5203547ff9d88d0ddd76'
|
|
||||||
curl -s -S -L -o 'ea222e359276c0702a5f5203547ff9d88d0ddd76.zip' 'https://api.github.com/repos/github/gh-aw-actions/zipball/ea222e359276c0702a5f5203547ff9d88d0ddd76'
|
|
||||||
popd
|
|
||||||
@@ -44,18 +44,6 @@ class ActionConfig {
|
|||||||
*/
|
*/
|
||||||
defaultBranch = 'master'
|
defaultBranch = 'master'
|
||||||
|
|
||||||
/**
|
|
||||||
* Maximum number of latest major versions to include (default to unlimited)
|
|
||||||
* @type {number|undefined}
|
|
||||||
*/
|
|
||||||
latestMajorVersions = undefined
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maximum number of latest version tags per major version (default to unlimited)
|
|
||||||
* @type {number|undefined}
|
|
||||||
*/
|
|
||||||
latestVersionsPerMajor = undefined
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag versions
|
* Tag versions
|
||||||
* @type {{[ref: string]: TagVersion}}
|
* @type {{[ref: string]: TagVersion}}
|
||||||
@@ -85,11 +73,9 @@ exports.TagVersion = TagVersion
|
|||||||
* @param {string[]} patternStrings
|
* @param {string[]} patternStrings
|
||||||
* @param {string} defaultBranch
|
* @param {string} defaultBranch
|
||||||
* @param {string[]|undefined} ignoreTags
|
* @param {string[]|undefined} ignoreTags
|
||||||
* @param {number|undefined} latestMajorVersions
|
|
||||||
* @param {number|undefined} latestVersionsPerMajor
|
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
async function add(owner, repo, patternStrings, defaultBranch, ignoreTags, latestMajorVersions, latestVersionsPerMajor) {
|
async function add(owner, repo, patternStrings, defaultBranch, ignoreTags) {
|
||||||
assert.ok(owner, "Arg 'owner' must not be empty")
|
assert.ok(owner, "Arg 'owner' must not be empty")
|
||||||
assert.ok(repo, "Arg 'repo' must not be empty")
|
assert.ok(repo, "Arg 'repo' must not be empty")
|
||||||
assert.ok(patternStrings, "Arg 'patternStrings' must not be null")
|
assert.ok(patternStrings, "Arg 'patternStrings' must not be null")
|
||||||
@@ -108,12 +94,6 @@ async function add(owner, repo, patternStrings, defaultBranch, ignoreTags, lates
|
|||||||
if (ignoreTags && ignoreTags.length > 0) {
|
if (ignoreTags && ignoreTags.length > 0) {
|
||||||
config.ignoreTags = ignoreTags
|
config.ignoreTags = ignoreTags
|
||||||
}
|
}
|
||||||
if (latestMajorVersions && latestMajorVersions > 0) {
|
|
||||||
config.latestMajorVersions = latestMajorVersions
|
|
||||||
}
|
|
||||||
if (latestVersionsPerMajor && latestVersionsPerMajor > 0) {
|
|
||||||
config.latestVersionsPerMajor = latestVersionsPerMajor
|
|
||||||
}
|
|
||||||
config.defaultBranch = defaultBranch
|
config.defaultBranch = defaultBranch
|
||||||
|
|
||||||
const tempDir = path.join(paths.temp, `${owner}_${repo}`)
|
const tempDir = path.join(paths.temp, `${owner}_${repo}`)
|
||||||
@@ -150,9 +130,6 @@ async function add(owner, repo, patternStrings, defaultBranch, ignoreTags, lates
|
|||||||
config.tags[tag] = tagVersion
|
config.tags[tag] = tagVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prune old tags based on version limits
|
|
||||||
pruneOldTags(config)
|
|
||||||
|
|
||||||
// Write config
|
// Write config
|
||||||
await exec.exec('mkdir', ['-p', path.dirname(file)])
|
await exec.exec('mkdir', ['-p', path.dirname(file)])
|
||||||
await fs.promises.writeFile(file, JSON.stringify(config, null, ' '))
|
await fs.promises.writeFile(file, JSON.stringify(config, null, ' '))
|
||||||
@@ -164,75 +141,6 @@ async function add(owner, repo, patternStrings, defaultBranch, ignoreTags, lates
|
|||||||
}
|
}
|
||||||
exports.add = add
|
exports.add = add
|
||||||
|
|
||||||
/**
|
|
||||||
* Prunes old tags from the config based on latestMajorVersions and latestVersionsPerMajor.
|
|
||||||
* Modifies config.tags in place.
|
|
||||||
* @param {ActionConfig} config
|
|
||||||
*/
|
|
||||||
function pruneOldTags(config) {
|
|
||||||
const maxMajors = config.latestMajorVersions || 0
|
|
||||||
const maxPerMajor = config.latestVersionsPerMajor || 0
|
|
||||||
|
|
||||||
if (!maxMajors && !maxPerMajor) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const tagNames = Object.keys(config.tags)
|
|
||||||
const versionTags = []
|
|
||||||
const keepTags = new Set()
|
|
||||||
|
|
||||||
for (const tag of tagNames) {
|
|
||||||
const match = tag.match(/^v(\d+)(?:\.(\d+))?(?:\.(\d+))?$/)
|
|
||||||
if (!match) {
|
|
||||||
// Always keep non-version tags
|
|
||||||
keepTags.add(tag)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
const major = parseInt(match[1], 10)
|
|
||||||
const minor = match[2] !== undefined ? parseInt(match[2], 10) : -1
|
|
||||||
const patch = match[3] !== undefined ? parseInt(match[3], 10) : -1
|
|
||||||
versionTags.push({ tag, major, minor, patch, isMajorOnly: minor === -1 })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Distinct major versions sorted descending (newest first)
|
|
||||||
const majorVersions = [...new Set(versionTags.map(v => v.major))].sort((a, b) => b - a)
|
|
||||||
const allowedMajors = new Set(
|
|
||||||
maxMajors > 0 ? majorVersions.slice(0, maxMajors) : majorVersions
|
|
||||||
)
|
|
||||||
|
|
||||||
for (const major of allowedMajors) {
|
|
||||||
const tagsForMajor = versionTags.filter(v => v.major === major)
|
|
||||||
|
|
||||||
// Always keep major-only pointers (e.g. "v4")
|
|
||||||
for (const v of tagsForMajor.filter(v => v.isMajorOnly)) {
|
|
||||||
keepTags.add(v.tag)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort non-major-only tags by version descending (latest first)
|
|
||||||
const sorted = tagsForMajor
|
|
||||||
.filter(v => !v.isMajorOnly)
|
|
||||||
.sort((a, b) => {
|
|
||||||
if (a.minor !== b.minor) return b.minor - a.minor
|
|
||||||
return b.patch - a.patch
|
|
||||||
})
|
|
||||||
|
|
||||||
const kept = maxPerMajor > 0 ? sorted.slice(0, maxPerMajor) : sorted
|
|
||||||
for (const v of kept) {
|
|
||||||
keepTags.add(v.tag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove pruned tags
|
|
||||||
for (const tag of tagNames) {
|
|
||||||
if (!keepTags.has(tag)) {
|
|
||||||
console.log(`Pruning tag '${tag}' from config (version limit)`)
|
|
||||||
delete config.tags[tag]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.pruneOldTags = pruneOldTags
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the action config file path
|
* Returns the action config file path
|
||||||
* @param {string} owner
|
* @param {string} owner
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ async function main() {
|
|||||||
const patterns = args.patterns
|
const patterns = args.patterns
|
||||||
const defaultBranch = args.defaultBranch || 'master'
|
const defaultBranch = args.defaultBranch || 'master'
|
||||||
const ignoreTags = args.ignoreTags
|
const ignoreTags = args.ignoreTags
|
||||||
const latestMajorVersions = args.latestMajorVersions
|
|
||||||
const latestVersionsPerMajor = args.latestVersionsPerMajor
|
|
||||||
|
|
||||||
// File exists?
|
// File exists?
|
||||||
const file = actionConfig.getFilePath(owner, repo)
|
const file = actionConfig.getFilePath(owner, repo)
|
||||||
@@ -26,7 +24,7 @@ async function main() {
|
|||||||
await fsHelper.reinitTemp()
|
await fsHelper.reinitTemp()
|
||||||
|
|
||||||
// Add the config
|
// Add the config
|
||||||
await actionConfig.add(owner, repo, patterns, defaultBranch, ignoreTags, latestMajorVersions, latestVersionsPerMajor)
|
await actionConfig.add(owner, repo, patterns, defaultBranch, ignoreTags)
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
// Help
|
// Help
|
||||||
@@ -62,7 +60,7 @@ class Args {
|
|||||||
*/
|
*/
|
||||||
function getArgs() {
|
function getArgs() {
|
||||||
// Parse
|
// Parse
|
||||||
const parsedArgs = argHelper.parse([], ['default-branch', 'ignore-tags', 'latest-major-versions', 'latest-versions-per-major'])
|
const parsedArgs = argHelper.parse([], ['default-branch', 'ignore-tags'])
|
||||||
if (parsedArgs.arguments.length < 1) {
|
if (parsedArgs.arguments.length < 1) {
|
||||||
argHelper.throwError('Expected at least one arg')
|
argHelper.throwError('Expected at least one arg')
|
||||||
}
|
}
|
||||||
@@ -103,29 +101,16 @@ function getArgs() {
|
|||||||
repo: splitNwo[1],
|
repo: splitNwo[1],
|
||||||
patterns: patterns,
|
patterns: patterns,
|
||||||
defaultBranch: parsedArgs.options['default-branch'],
|
defaultBranch: parsedArgs.options['default-branch'],
|
||||||
ignoreTags: ignoreTags,
|
ignoreTags: ignoreTags
|
||||||
latestMajorVersions: parseNonNegativeInt(parsedArgs.options['latest-major-versions'], 'latest-major-versions'),
|
|
||||||
latestVersionsPerMajor: parseNonNegativeInt(parsedArgs.options['latest-versions-per-major'], 'latest-versions-per-major')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseNonNegativeInt(value, name) {
|
|
||||||
if (!value) return 0
|
|
||||||
const n = Number(value)
|
|
||||||
if (!Number.isInteger(n) || n < 0) {
|
|
||||||
argHelper.throwError(`--${name} must be a non-negative integer, got '${value}'`)
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
function printUsage() {
|
function printUsage() {
|
||||||
console.error('USAGE: add-action.sh [--default-branch branch] [--ignore-tags versions] [--latest-major-versions N] [--latest-versions-per-major N] nwo [(+|-)regexp [...]]')
|
console.error('USAGE: add-action.sh [--default-branch branch] [--ignore-tags versions] nwo [(+|-)regexp [...]]')
|
||||||
console.error(` --default-branch Default branch name. For example: master`)
|
console.error(` --default-branch Default branch name. For example: master`)
|
||||||
console.error(` --ignore-tags Comma-separated version prefixes to ignore. For example: v1,v2`)
|
console.error(` --ignore-tags Comma-separated version prefixes to ignore. For example: v1,v2`)
|
||||||
console.error(` --latest-major-versions Only cache the latest N major versions. For example: 3`)
|
console.error(` nwo Name with owner. For example: actions/checkout`)
|
||||||
console.error(` --latest-versions-per-major Only cache the latest N version tags per major version. For example: 5`)
|
console.error(` regexp Refs to include or exclude. Default: ${actionConfig.defaultPatterns.join(' ')}`)
|
||||||
console.error(` nwo Name with owner. For example: actions/checkout`)
|
|
||||||
console.error(` regexp Refs to include or exclude. Default: ${actionConfig.defaultPatterns.join(' ')}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
// Filters tags from an action config based on latestMajorVersions and latestVersionsPerMajor.
|
|
||||||
// Reads JSON config from stdin, outputs allowed tag names (one per line).
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
let input = ''
|
|
||||||
for await (const chunk of process.stdin) {
|
|
||||||
input += chunk
|
|
||||||
}
|
|
||||||
|
|
||||||
const config = JSON.parse(input)
|
|
||||||
const tags = Object.keys(config.tags || {})
|
|
||||||
const latestMajorVersions = config.latestMajorVersions || 0 // 0 = unlimited
|
|
||||||
const latestVersionsPerMajor = config.latestVersionsPerMajor || 0 // 0 = unlimited
|
|
||||||
|
|
||||||
if (!latestMajorVersions && !latestVersionsPerMajor) {
|
|
||||||
// No filtering configured, output all tags
|
|
||||||
for (const tag of tags) {
|
|
||||||
console.log(tag)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse version info from tag names
|
|
||||||
const versionTags = []
|
|
||||||
const nonVersionTags = []
|
|
||||||
|
|
||||||
for (const tag of tags) {
|
|
||||||
const match = tag.match(/^v(\d+)(?:\.(\d+))?(?:\.(\d+))?$/)
|
|
||||||
if (!match) {
|
|
||||||
nonVersionTags.push(tag)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
const major = parseInt(match[1], 10)
|
|
||||||
const minor = match[2] !== undefined ? parseInt(match[2], 10) : -1
|
|
||||||
const patch = match[3] !== undefined ? parseInt(match[3], 10) : -1
|
|
||||||
const isMajorOnly = minor === -1
|
|
||||||
|
|
||||||
versionTags.push({ tag, major, minor, patch, isMajorOnly })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find distinct major versions sorted descending (newest first)
|
|
||||||
const majorVersions = [...new Set(versionTags.map(v => v.major))].sort((a, b) => b - a)
|
|
||||||
|
|
||||||
// Apply latestMajorVersions filter
|
|
||||||
const allowedMajors = new Set(
|
|
||||||
latestMajorVersions > 0 ? majorVersions.slice(0, latestMajorVersions) : majorVersions
|
|
||||||
)
|
|
||||||
|
|
||||||
// Always include non-version tags
|
|
||||||
const result = [...nonVersionTags]
|
|
||||||
|
|
||||||
for (const major of allowedMajors) {
|
|
||||||
const tagsForMajor = versionTags.filter(v => v.major === major)
|
|
||||||
|
|
||||||
// Always include major-only pointers (e.g., "v4")
|
|
||||||
for (const v of tagsForMajor.filter(v => v.isMajorOnly)) {
|
|
||||||
result.push(v.tag)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort non-major-only tags by version descending (latest first)
|
|
||||||
const sortedVersions = tagsForMajor
|
|
||||||
.filter(v => !v.isMajorOnly)
|
|
||||||
.sort((a, b) => {
|
|
||||||
if (a.minor !== b.minor) return b.minor - a.minor
|
|
||||||
return b.patch - a.patch
|
|
||||||
})
|
|
||||||
|
|
||||||
// Apply latestVersionsPerMajor filter
|
|
||||||
const kept = latestVersionsPerMajor > 0
|
|
||||||
? sortedVersions.slice(0, latestVersionsPerMajor)
|
|
||||||
: sortedVersions
|
|
||||||
|
|
||||||
for (const v of kept) {
|
|
||||||
result.push(v.tag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const tag of result) {
|
|
||||||
console.log(tag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch(err => {
|
|
||||||
console.error(err.message)
|
|
||||||
process.exitCode = 1
|
|
||||||
})
|
|
||||||
@@ -44,15 +44,6 @@ for json_file in $script_dir/../../config/actions/*.json; do
|
|||||||
ignore_patterns=()
|
ignore_patterns=()
|
||||||
IFS=$'\n' read -r -d '' -a ignore_patterns < <( echo "$json" | jq --raw-output '.ignoreTags // [] | .[]' && printf '\0' )
|
IFS=$'\n' read -r -d '' -a ignore_patterns < <( echo "$json" | jq --raw-output '.ignoreTags // [] | .[]' && printf '\0' )
|
||||||
|
|
||||||
# Get version-filtered tags (applies latestMajorVersions and latestVersionsPerMajor)
|
|
||||||
filtered_tags=()
|
|
||||||
IFS=$'\n' read -r -d '' -a filtered_tags < <( echo "$json" | node "$script_dir/filter-tags.js" && printf '\0' )
|
|
||||||
unset filtered_tag_set
|
|
||||||
declare -A filtered_tag_set
|
|
||||||
for t in "${filtered_tags[@]}"; do
|
|
||||||
filtered_tag_set[$t]=1
|
|
||||||
done
|
|
||||||
|
|
||||||
# Get an array of tag info. Each item contains "<tag> <commit_sha>"
|
# Get an array of tag info. Each item contains "<tag> <commit_sha>"
|
||||||
tag_info=()
|
tag_info=()
|
||||||
IFS=$'\n' read -r -d '' -a tag_info < <( echo "$json" | jq --raw-output '.tags | to_entries | .[] | .key + " " + .value.commit' && printf '\0' )
|
IFS=$'\n' read -r -d '' -a tag_info < <( echo "$json" | jq --raw-output '.tags | to_entries | .[] | .key + " " + .value.commit' && printf '\0' )
|
||||||
@@ -76,12 +67,6 @@ for json_file in $script_dir/../../config/actions/*.json; do
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the tag passes version filter
|
|
||||||
if [ -z "${filtered_tag_set[$tag]+x}" ]; then
|
|
||||||
echo "Skipping tag '$tag' (filtered by version limits)"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Append curl download command
|
# Append curl download command
|
||||||
curl_download_commands+=("curl -s -S -L -o '$sha.tar.gz' 'https://api.github.com/repos/$owner/$repo/tarball/$sha'")
|
curl_download_commands+=("curl -s -S -L -o '$sha.tar.gz' 'https://api.github.com/repos/$owner/$repo/tarball/$sha'")
|
||||||
curl_download_commands+=("curl -s -S -L -o '$sha.zip' 'https://api.github.com/repos/$owner/$repo/zipball/$sha'")
|
curl_download_commands+=("curl -s -S -L -o '$sha.zip' 'https://api.github.com/repos/$owner/$repo/zipball/$sha'")
|
||||||
|
|||||||
@@ -23,10 +23,8 @@ async function main() {
|
|||||||
const patterns = config.patterns
|
const patterns = config.patterns
|
||||||
const defaultBranch = config.defaultBranch
|
const defaultBranch = config.defaultBranch
|
||||||
const ignoreTags = config.ignoreTags
|
const ignoreTags = config.ignoreTags
|
||||||
const latestMajorVersions = args.latestMajorVersions || config.latestMajorVersions
|
|
||||||
const latestVersionsPerMajor = args.latestVersionsPerMajor || config.latestVersionsPerMajor
|
|
||||||
assert.ok(patterns && patterns.length, 'Existing patterns must not be empty')
|
assert.ok(patterns && patterns.length, 'Existing patterns must not be empty')
|
||||||
await actionConfig.add(owner, repo, patterns, defaultBranch, ignoreTags, latestMajorVersions, latestVersionsPerMajor)
|
await actionConfig.add(owner, repo, patterns, defaultBranch, ignoreTags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
@@ -53,8 +51,6 @@ class Args {
|
|||||||
all = false
|
all = false
|
||||||
owner = ''
|
owner = ''
|
||||||
repo = ''
|
repo = ''
|
||||||
latestMajorVersions = 0
|
|
||||||
latestVersionsPerMajor = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,11 +58,9 @@ class Args {
|
|||||||
* @returns {Args}
|
* @returns {Args}
|
||||||
*/
|
*/
|
||||||
function getArgs() {
|
function getArgs() {
|
||||||
const parsedArgs = argHelper.parse(['all'], ['latest-major-versions', 'latest-versions-per-major'])
|
const parsedArgs = argHelper.parse(['all'])
|
||||||
const result = new Args()
|
const result = new Args()
|
||||||
result.all = !!parsedArgs.flags['all']
|
result.all = !!parsedArgs.flags['all']
|
||||||
result.latestMajorVersions = parseNonNegativeInt(parsedArgs.options['latest-major-versions'], 'latest-major-versions')
|
|
||||||
result.latestVersionsPerMajor = parseNonNegativeInt(parsedArgs.options['latest-versions-per-major'], 'latest-versions-per-major')
|
|
||||||
|
|
||||||
// All
|
// All
|
||||||
if (result.all) {
|
if (result.all) {
|
||||||
@@ -94,21 +88,9 @@ function getArgs() {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseNonNegativeInt(value, name) {
|
|
||||||
if (!value) return 0
|
|
||||||
const n = Number(value)
|
|
||||||
if (!Number.isInteger(n) || n < 0) {
|
|
||||||
argHelper.throwError(`--${name} must be a non-negative integer, got '${value}'`)
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
function printUsage() {
|
function printUsage() {
|
||||||
console.error('USAGE: update-action.sh [--all] [--latest-major-versions N] [--latest-versions-per-major N] [nwo]')
|
console.error('USAGE: update-action.sh nwo')
|
||||||
console.error(` --all Update all configured actions`)
|
console.error(` nwo Name with owner. For example: actions/checkout`)
|
||||||
console.error(` --latest-major-versions Update to only keep the latest N major versions`)
|
|
||||||
console.error(` --latest-versions-per-major Update to only keep the latest N version tags per major`)
|
|
||||||
console.error(` nwo Name with owner. For example: actions/checkout`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
@@ -46,8 +46,6 @@ function test_tar_gz ()
|
|||||||
echo "Find action.yml under $sha_archive_full_path"
|
echo "Find action.yml under $sha_archive_full_path"
|
||||||
elif [[ -f "$first_dir/action.yaml" ]]; then
|
elif [[ -f "$first_dir/action.yaml" ]]; then
|
||||||
echo "Find action.yaml under $sha_archive_full_path"
|
echo "Find action.yaml under $sha_archive_full_path"
|
||||||
elif find "$first_dir" -name 'action.yml' -o -name 'action.yaml' | grep -q .; then
|
|
||||||
echo "Find action.yml in subdirectory under $sha_archive_full_path"
|
|
||||||
else
|
else
|
||||||
echo "$sha_archive_full_path doesn't contain an action.yml or action.yaml"
|
echo "$sha_archive_full_path doesn't contain an action.yml or action.yaml"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -85,8 +83,6 @@ function test_zip ()
|
|||||||
echo "Find action.yml under $sha_archive_full_path"
|
echo "Find action.yml under $sha_archive_full_path"
|
||||||
elif [[ -f "$first_dir/action.yaml" ]]; then
|
elif [[ -f "$first_dir/action.yaml" ]]; then
|
||||||
echo "Find action.yaml under $sha_archive_full_path"
|
echo "Find action.yaml under $sha_archive_full_path"
|
||||||
elif find "$first_dir" -name 'action.yml' -o -name 'action.yaml' | grep -q .; then
|
|
||||||
echo "Find action.yml in subdirectory under $sha_archive_full_path"
|
|
||||||
else
|
else
|
||||||
echo "$sha_archive_full_path doesn't contain an action.yml or action.yaml"
|
echo "$sha_archive_full_path doesn't contain an action.yml or action.yaml"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user