Skip to content
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

feat: support ignore/include modules #12

Merged
merged 2 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@ jobs:
strategy:
matrix:
module: ${{ fromJson(needs.modules.outputs.modules) }}
defaults:
run:
working-directory: ${{ matrix.module }}
steps:
- uses: actions/checkout@v2
- uses: hashicorp/setup-terraform@v1
- run: terraform init
working-directory: ${{ matrix.module }}
- run: terraform plan
working-directory: ${{ matrix.module }}
```

## Inputs

- `token` (optional) GitHub token. Defaults to secrets.GITHUB_TOKEN.
- `mode` (optional) Set to `all` to return all modules or `changed` to only return modules that have changes in this PR/commit. Defaults to `changed`.
- `ignore` (optional) Comma-separated list of module paths to ignore.
- `include` (optional) Comma-separated list of module paths to include. If set all other modules are ignored.

## Outputs

Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ inputs:
description: Set to `all` to return all modules or `changed` to only return modules that have changes in this PR/commit. Defaults to `changed`.
required: false
default: changed
ignore:
description: Comma-separated list of module paths to ignore.
required: false
include:
description: Comma-separated list of module paths to include. If set all other modules are ignored.
required: false
outputs:
modules:
description: An array of paths to Terraform modules.
Expand Down
10 changes: 10 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ async function run(): Promise<void> {
try {
const token = core.getInput('token', { required: true })
const mode = core.getInput('mode', { required: true })
const ignore = core.getInput('ignore')
const include = core.getInput('include')

let modules: string[]

Expand All @@ -22,6 +24,16 @@ async function run(): Promise<void> {
throw new Error(`Unknown mode: ${mode}`)
}

if (ignore) {
const list = ignore.split(',').map((item) => item.trim())
modules = modules.filter((module) => !list.includes(module))
}

if (include) {
const list = include.split(',').map((item) => item.trim())
modules = modules.filter((module) => list.includes(module))
}

if (modules.length) {
core.debug(`Found modules:${modules.map((module) => `\n- ${module}`)}`)
} else {
Expand Down