Skip to content

Commit

Permalink
Rename ignored to allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Nov 10, 2020
1 parent a9910e2 commit e1e1320
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ be updated to the latest available sha for your pinned ref.

## Leaving Actions unpinned

To leave an action unpinned, pass the `--ignore` option when running `pin-github-action`.
To leave an action unpinned, pass the `--allow` option when running `pin-github-action`.

Running `pin-github-action /path/to/.github/workflows/your-name.yml --ignore "actions/*"` will turn this:
Running `pin-github-action /path/to/.github/workflows/your-name.yml --allow "actions/*"` will turn this:

```yaml
jobs:
Expand All @@ -97,7 +97,7 @@ jobs:
uses: nexmo/github-actions/submodule-auto-pr@73549280c1c566830040d9a01fe9050dae6a3036 # pin@master
```

You can pass multiple actions to ignore as a comma separated list e.g. `actions/checkout,mheap/*`
You can pass multiple actions to allow as a comma separated list e.g. `actions/checkout,mheap/*`

A quick overview of the available globbing patterns (taken from [multimatch](https://github.com/sindresorhus/multimatch), which we use to match globs):

Expand Down
10 changes: 5 additions & 5 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ const packageDetails = require(path.join(__dirname, "package.json"));
program
.version(packageDetails.version)
.option(
"-i, --ignore <actions>",
"comma separated list of actions to ignore e.g. mheap/debug-action. May be a glob e.g. mheap/*"
"-a, --allow <actions>",
"comma separated list of actions to allow e.g. mheap/debug-action. May be a glob e.g. mheap/*"
)
.parse(process.argv);

const filename = program.args[0];
let ignored = program.opts().ignore;
ignored = (ignored || "").split(",").filter((r) => r);
let allowed = program.opts().allow;
allowed = (allowed || "").split(",").filter((r) => r);

const input = fs.readFileSync(filename).toString();

const output = await run(input, ignored);
const output = await run(input, allowed);

fs.writeFileSync(filename, output.workflow);

Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions checkIgnoredRepos.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
const checkIgnoredRepos = require("./checkIgnoredRepos");
const checkAllowedRepos = require("./checkAllowedRepos");

test("empty allow list", () => {
const actual = checkIgnoredRepos("mheap/demo", []);
const actual = checkAllowedRepos("mheap/demo", []);
expect(actual).toBe(false);
});

test("no match", () => {
expect(checkIgnoredRepos("mheap/demo", ["other/repo"])).toBe(false);
expect(checkAllowedRepos("mheap/demo", ["other/repo"])).toBe(false);
});

test("exact match", () => {
expect(checkIgnoredRepos("mheap/demo", ["mheap/demo"])).toBe(true);
expect(checkAllowedRepos("mheap/demo", ["mheap/demo"])).toBe(true);
});

test("partial match", () => {
expect(checkIgnoredRepos("mheap/demo", ["mheap/*"])).toBe(true);
expect(checkAllowedRepos("mheap/demo", ["mheap/*"])).toBe(true);
});

test("no partial match", () => {
expect(checkIgnoredRepos("other/demo", ["mheap/*"])).toBe(false);
expect(checkAllowedRepos("other/demo", ["mheap/*"])).toBe(false);
});

test("multiple ignores", () => {
expect(checkIgnoredRepos("mheap/demo", ["other", "mheap/*"])).toBe(true);
expect(checkAllowedRepos("mheap/demo", ["other", "mheap/*"])).toBe(true);
});

test("negative ignores", () => {
expect(checkIgnoredRepos("other/demo", ["!mheap/*"])).toBe(true);
expect(checkAllowedRepos("other/demo", ["!mheap/*"])).toBe(true);
});
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const YAML = require("yaml");
const extractActions = require("./extractActions");
const replaceActions = require("./replaceActions");
const findRefOnGithub = require("./findRefOnGithub");
const checkIgnoredRepos = require("./checkIgnoredRepos");
const checkAllowedRepos = require("./checkAllowedRepos");

module.exports = async function(input, ignored) {
ignored = ignored || [];
module.exports = async function(input, allowed) {
allowed = allowed || [];

// Parse the workflow file
let workflow = YAML.parseDocument(input);
Expand All @@ -17,7 +17,7 @@ module.exports = async function(input, ignored) {
for (let i in actions) {
// Should this action be updated?
const action = `${actions[i].owner}/${actions[i].repo}`;
if (checkIgnoredRepos(action, ignored)) {
if (checkAllowedRepos(action, allowed)) {
continue;
}

Expand All @@ -26,7 +26,7 @@ module.exports = async function(input, ignored) {
actions[i].newVersion = newVersion;

// Rewrite each action, replacing the uses block with a specific sha
workflow = replaceActions(workflow, actions[i], ignored);
workflow = replaceActions(workflow, actions[i]);
}

return {
Expand Down

0 comments on commit e1e1320

Please sign in to comment.