Skip to content

Commit

Permalink
add 'exclude' input option
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrunton committed Mar 7, 2021
1 parent a96c5a5 commit df7cdaf
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 6 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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 != '');
Expand Down
19 changes: 16 additions & 3 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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 != '')
Expand Down
25 changes: 25 additions & 0 deletions test/unit/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('Inputs', () => {
function createInputs(platform: string, inputs: {[key: string]: string} = {}): Inputs {
const core = mock<ActionsCore>()
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')
}
Expand Down Expand Up @@ -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" })

Expand All @@ -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")
Expand Down

0 comments on commit df7cdaf

Please sign in to comment.