From df7cdaf306763ba1fa2a49053793b275a8b84e69 Mon Sep 17 00:00:00 2001 From: John Brunton Date: Sun, 7 Mar 2021 17:30:23 +0000 Subject: [PATCH] add 'exclude' input option --- .github/workflows/build.yml | 14 ++++++++++++++ README.md | 12 ++++++++++++ action.yml | 4 ++++ dist/index.js | 15 ++++++++++++--- src/inputs.ts | 19 ++++++++++++++++--- test/unit/inputs.test.ts | 25 +++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 54df1fe..8f93cf0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,6 +53,20 @@ jobs: npm run verify:installed ytt kbld npm run verify:not:installed kapp kwt imgpkg vendir + test-e2e-exclude-apps: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: ./ + with: + exclude: kwt, vendir + token: ${{ secrets.GITHUB_TOKEN }} + - run: npm install + - name: check specific apps are installed + run: | + npm run verify:installed ytt kbld kapp imgpkg + npm run verify:not:installed kwt vendir + test-e2e-specific-version: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index 2935fbf..f4a3604 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,18 @@ steps: kbld version ``` +To exclude specific apps: + +```yaml +steps: +- uses: vmware-tanzu/carvel-setup-action@v1 + with: + exclude: kwt, vendir +- run: | + ytt version + kbld version +``` + To use a specific version of an app: ```yaml diff --git a/action.yml b/action.yml index 3d43317..f693367 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,10 @@ inputs: description: List apps to download if you don't need all required: false default: "" + exclude: + description: List apps to exclude if you want most but not all + required: false + default: "" ytt: description: ytt version required: false diff --git a/dist/index.js b/dist/index.js index 88666de..6acb5b1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -15147,7 +15147,7 @@ class Inputs { this._env = env; } getAppsToDownload() { - const apps = this.parseAppsList(); + const apps = this.includeAppsList(); if (apps.length == 0) { // if no options specified, download all apps.push(...this.getAllApps()); @@ -15167,9 +15167,18 @@ class Inputs { } return exports.carvelApps; } - parseAppsList() { + includeAppsList() { + const apps = this.parseAppList('only'); + if (apps.length == 0) { + // if no `only` option specified, include all by default + apps.push(...this.getAllApps()); + } + const excludeApps = this.parseAppList('exclude'); + return apps.filter(appName => !excludeApps.includes(appName)); + } + parseAppList(input) { return this._core - .getInput('only') + .getInput(input) .split(',') .map((appName) => appName.trim()) .filter((appName) => appName != ''); diff --git a/src/inputs.ts b/src/inputs.ts index 736b9fe..3b7120e 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -14,7 +14,7 @@ export class Inputs { } public getAppsToDownload(): AppInfo[] { - const apps = this.parseAppsList() + const apps = this.includeAppsList() if (apps.length == 0) { // if no options specified, download all @@ -39,9 +39,22 @@ export class Inputs { return carvelApps } - private parseAppsList(): string[] { + private includeAppsList(): string[] { + const apps = this.parseAppList('only') + + if (apps.length == 0) { + // if no `only` option specified, include all by default + apps.push(...this.getAllApps()) + } + + const excludeApps = this.parseAppList('exclude') + + return apps.filter(appName => !excludeApps.includes(appName)) + } + + private parseAppList(input: string): string[] { return this._core - .getInput('only') + .getInput(input) .split(',') .map((appName: string) => appName.trim()) .filter((appName: string) => appName != '') diff --git a/test/unit/inputs.test.ts b/test/unit/inputs.test.ts index e430a23..e94e986 100644 --- a/test/unit/inputs.test.ts +++ b/test/unit/inputs.test.ts @@ -6,6 +6,7 @@ describe('Inputs', () => { function createInputs(platform: string, inputs: {[key: string]: string} = {}): Inputs { const core = mock() core.getInput.calledWith('only').mockReturnValue(inputs.only || '') + core.getInput.calledWith('exclude').mockReturnValue(inputs.exclude || '') for (let appName of carvelApps) { core.getInput.calledWith(appName).mockReturnValue(inputs[appName] || 'latest') } @@ -57,6 +58,17 @@ describe('Inputs', () => { ]) }) + test('limits apps to "only" list', () => { + const inputs = createInputs("linux", { only: "ytt, kbld" }) + + const apps = inputs.getAppsToDownload() + + expect(apps).toEqual([ + { name: "ytt", "version": "latest" }, + { name: "kbld", "version": "latest" } + ]) + }) + test('allows for app list override', () => { const inputs = createInputs("linux", { only: "ytt, kbld", ytt: "0.28.0" }) @@ -68,6 +80,19 @@ describe('Inputs', () => { ]) }) + test('excludes apps from "exclude" list', () => { + const inputs = createInputs("linux", { exclude: "ytt, kwt", kapp: "0.34.0" }) + + const apps = inputs.getAppsToDownload() + + expect(apps).toEqual([ + { name: "kbld", "version": "latest" }, + { name: "kapp", "version": "0.34.0" }, + { name: "imgpkg", "version": "latest" }, + { name: "vendir", "version": "latest" } + ]) + }) + test('validates app names', () => { const inputs = createInputs("linux", { only: "ytt, kbl" }) expect(() => inputs.getAppsToDownload()).toThrowError("Unknown app: kbl")