Files
action-versions/script/internal/update-action.js
Copilot ab7f3a1ca8 Add ignoreTags support to exclude old versions from packaging (#118)
* Add ignoreTags support to exclude old versions from packaging

Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>

* Add ignoreTags support to add-action and update-action scripts

Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>

* Fix JSDoc typo and add regex validation for ignore-tags patterns

Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>

* Simplify --ignore-tags to accept version prefixes instead of regex patterns

Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>

* Add helper script to add ignoreTags to existing actions and fix JSON syntax in README

Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>

* Remove --all flag from add-ignore-tags.sh, require specific action

Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>
2025-12-09 10:30:43 -05:00

96 lines
2.3 KiB
JavaScript

const actionConfig = require('./action-config')
const argHelper = require('./arg-helper')
const assert = require('assert')
const debugHelper = require('./debug-helper')
const fsHelper = require('./fs-helper')
async function main() {
try {
// Command line args
const args = getArgs()
// Reinit _temp
await fsHelper.reinitTemp()
// Get a list of action config files
const files = args.all ? await actionConfig.getFilePaths() : [actionConfig.getFilePath(args.owner, args.repo)]
debugHelper.debug(`files: ${files}`)
for (const file of files) {
// Load the config
const config = await actionConfig.loadFromPath(file)
const owner = config.owner
const repo = config.repo
const patterns = config.patterns
const defaultBranch = config.defaultBranch
const ignoreTags = config.ignoreTags
assert.ok(patterns && patterns.length, 'Existing patterns must not be empty')
await actionConfig.add(owner, repo, patterns, defaultBranch, ignoreTags)
}
}
catch (err) {
// Help
if (err.code === argHelper.helpCode) {
printUsage()
return
}
// Arg error?
if (err.code === argHelper.errorCode) {
printUsage()
console.error('')
}
// Print error
debugHelper.debug(err.stack)
console.error(`ERROR: ${err.message}`)
process.exitCode = 1
}
}
class Args {
all = false
owner = ''
repo = ''
}
/**
* Get the command line args
* @returns {Args}
*/
function getArgs() {
const parsedArgs = argHelper.parse(['all'])
const result = new Args()
result.all = !!parsedArgs.flags['all']
// All
if (result.all) {
// Validate no args
if (parsedArgs.arguments.length) {
argHelper.throwError(`Expected zero args when '--all' is specified`)
}
}
// Not all
else {
// Validate exactly one arg
if (parsedArgs.arguments.length !== 1) {
argHelper.throwError('Expected exactly one arg')
}
const nwo = parsedArgs.arguments[0]
const splitNwo = nwo.split('/')
if (splitNwo.length !== 2 || !splitNwo[0] || !splitNwo[1]) {
argHelper.throwError(`Invalid nwo '${nwo}'`)
}
result.owner = splitNwo[0]
result.repo = splitNwo[1]
}
return result
}
function printUsage() {
console.error('USAGE: update-action.sh nwo')
console.error(` nwo Name with owner. For example: actions/checkout`)
}
main()