-
Notifications
You must be signed in to change notification settings - Fork 17
feat: look up a hash by version #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,9 +25,13 @@ const packageDetails = require(path.join(__dirname, "package.json")); | |
| "-e, --allow-empty", | ||
| "allow workflows that do not contain any actions" | ||
| ) | ||
| .option( | ||
| "-o, --only <owner/repo>", | ||
| "single action to pin e.g. mheap/debug-action. May be a glob e.g. mheap/*. May have version tag e.g. mheap/debug-action@v1.2.3" | ||
| ) | ||
| .parse(process.argv); | ||
|
|
||
| const filename = program.args[0]; | ||
| const filename = program.args[0]; | ||
|
|
||
| if (!filename) { | ||
| console.log("Usage: pin-github-action /path/to/workflow.yml"); | ||
|
|
@@ -37,11 +41,27 @@ const packageDetails = require(path.join(__dirname, "package.json")); | |
| let allowed = program.opts().allow; | ||
| allowed = (allowed || "").split(",").filter((r) => r); | ||
| let ignoreShas = program.opts().ignoreShas; | ||
| let only = program.opts().only; | ||
|
|
||
| let [onlyOwner, onlyRepo] = [null,null]; | ||
| let onlyVersion = null; | ||
| if ( only ){ | ||
| let parts = only.split("/"); | ||
| if ( parts.length != 2 ){ | ||
| throw ( "Syntax for --only: account/repo or account/*"); | ||
| } | ||
| [onlyOwner,onlyRepo] = parts; | ||
|
|
||
| parts = onlyRepo.split("@"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable shadowing here. Could we use a more descriptive (and different) variable name? |
||
| if( 2 == parts.length ){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| [onlyRepo,onlyVersion] = parts; | ||
| } | ||
| } | ||
|
|
||
| const input = fs.readFileSync(filename).toString(); | ||
|
|
||
| let allowEmpty = program.opts().allowEmpty; | ||
| const output = await run(input, allowed, ignoreShas, allowEmpty, debug); | ||
| const output = await run(input, allowed, ignoreShas, allowEmpty, debug, onlyOwner, onlyRepo, onlyVersion); | ||
|
|
||
| fs.writeFileSync(filename, output.workflow); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,12 @@ const github = new Octokit({ | |
| }); | ||
|
|
||
| let debug = () => {}; | ||
| module.exports = function (action, log) { | ||
| module.exports = function (action, log, onlyVersion) { | ||
| debug = log.extend("find-ref-on-github"); | ||
| return new Promise(async function (resolve, reject) { | ||
| const owner = action.owner; | ||
| const repo = action.repo; | ||
| const pinned = action.pinnedVersion; | ||
| const pinned = onlyVersion ? onlyVersion : action.pinnedVersion; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test in |
||
| const name = `${owner}/${repo}`; | ||
|
|
||
| let error; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,10 @@ module.exports = async function ( | |
| allowed, | ||
| ignoreShas, | ||
| allowEmpty, | ||
| debug | ||
| debug, | ||
| onlyOwner, | ||
| onlyRepo, | ||
| onlyVersion | ||
| ) { | ||
| allowed = allowed || []; | ||
| ignoreShas = ignoreShas || false; | ||
|
|
@@ -33,9 +36,24 @@ module.exports = async function ( | |
| continue; | ||
| } | ||
|
|
||
| if (onlyOwner && actions[i].owner !== onlyOwner ){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please extract this in to another file (e.g. Example module: https://github.com/mheap/pin-github-action/blob/main/checkAllowedRepos.js |
||
| debug("skipping owner:",actions[i].owner) | ||
| continue; | ||
| } | ||
|
|
||
| if (onlyRepo && onlyRepo !== "*" && actions[i].repo !== onlyRepo ){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than checking |
||
| debug("skipping repo:",actions[i].repo) | ||
| continue; | ||
| } | ||
|
|
||
| debug("pinning action:",action) | ||
|
|
||
| // Look up those actions on Github | ||
| const newVersion = await findRefOnGithub(actions[i], debug); | ||
| const newVersion = await findRefOnGithub(actions[i], debug, onlyVersion); | ||
| actions[i].newVersion = newVersion; | ||
| if( onlyVersion ){ | ||
| actions[i].pinnedVersion = onlyVersion; | ||
| } | ||
|
|
||
| // Rewrite each action, replacing the uses block with a specific sha | ||
| workflow = replaceActions(workflow, actions[i]); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run
npm run lint-fixto ensure that formatting is correct