Skip to content

feat: add asset and exclude pattern filtering for module releases #81

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

Merged
merged 1 commit into from
Oct 26, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ jobs:
disable-wiki: false
wiki-sidebar-changelog-max: 10
delete-legacy-tags: false # Note: We don't want to delete tags in this repository
module-change-exclude-patterns: .gitignore,*.md,*.tftest.hcl,tests/**
module-asset-exclude-patterns: .gitignore,*.md,*.tftest.hcl,tests/**
61 changes: 43 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ on:
- main

permissions:
contents: write
pull-requests: write
contents: write # Required for to push tags, create release, and push changes to the wiki
pull-requests: write # Required to comment on pull request

jobs:
release:
Expand Down Expand Up @@ -134,22 +134,46 @@ requests and creating releases.
If the permissions are insufficient, the action may fail with a 403 error, indicating a lack of access to the necessary
resources.

## Directory Structure Best Practices

- Avoid placing nested Terraform modules within a sub-directory of another module, as this practice can lead to issues
with dependency management and module separation. Instead, structure your repository with multiple levels of
folders/directories to organize modules while keeping each Terraform module isolated within its dedicated directory.
This approach promotes maintainability and helps ensure clarity across modules.

- We recommend structuring modules with a top-level namespace that is related to a major provider (e.g., `aws`, `azure`,
or `null`). Within this namespace, use a nested directory to house the actual module with a name that corresponds
closely to its intended purpose or resource. For example:

```shell
├── aws
│ ├── vpc
│ └── ec2
├── azure
│ ├── resource-group
│ └── storage-account
└── null
└── label
```

## Input Parameters

While the out-of-the-box defaults are suitable for most use cases, you can further customize the action's behavior by
configuring the following optional input parameters as needed.

| Input | Description | Default |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
| `major-keywords` | Keywords in commit messages that indicate a major release | `major change,breaking change` |
| `minor-keywords` | Keywords in commit messages that indicate a minor release | `feat,feature` |
| `patch-keywords` | Keywords in commit messages that indicate a patch release | `fix,chore,docs` |
| `default-first-tag` | Specifies the default tag version | `v1.0.0` |
| `terraform-docs-version` | Specifies the terraform-docs version used to generate documentation for the wiki | `v0.19.0` |
| `delete-legacy-tags` | Specifies a boolean that determines whether tags and releases from Terraform modules that have been deleted should be automatically removed | `true` |
| `disable-wiki` | Whether to disable wiki generation for Terraform modules | `false` |
| `wiki-sidebar-changelog-max` | An integer that specifies how many changelog entries are displayed in the sidebar per module | `5` |
| `disable-branding` | Controls whether a small branding link to the action's repository is added to PR comments. Recommended to leave enabled to support OSS. | `false` |
| Input | Description | Default |
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
| `major-keywords` | Keywords in commit messages that indicate a major release | `major change,breaking change` |
| `minor-keywords` | Keywords in commit messages that indicate a minor release | `feat,feature` |
| `patch-keywords` | Keywords in commit messages that indicate a patch release | `fix,chore,docs` |
| `default-first-tag` | Specifies the default tag version | `v1.0.0` |
| `terraform-docs-version` | Specifies the terraform-docs version used to generate documentation for the wiki | `v0.19.0` |
| `delete-legacy-tags` | Specifies a boolean that determines whether tags and releases from Terraform modules that have been deleted should be automatically removed | `true` |
| `disable-wiki` | Whether to disable wiki generation for Terraform modules | `false` |
| `wiki-sidebar-changelog-max` | An integer that specifies how many changelog entries are displayed in the sidebar per module | `5` |
| `disable-branding` | Controls whether a small branding link to the action's repository is added to PR comments. Recommended to leave enabled to support OSS. | `false` |
| `module-change-exclude-patterns` | A comma-separated list of file patterns to exclude from triggering version changes in Terraform modules. Patterns follow glob syntax (e.g., ".gitignore,_.md") and are relative to each Terraform module directory. Files matching these patterns will not affect version changes. **WARNING**: Avoid excluding '_.tf' files, as they are essential for module detection and versioning processes. | `".gitignore,*.md,*.tftest.hcl,tests/**"` |
| `module-asset-exclude-patterns` | A comma-separated list of file patterns to exclude when bundling a Terraform module for tag/release. Patterns follow glob syntax (e.g., "tests/\*\*") and are relative to each Terraform module directory. Files matching these patterns will be excluded from the bundled output. | `".gitignore,*.md,*.tftest.hcl,tests/**"` |

### Example Usage with Inputs

Expand All @@ -162,8 +186,8 @@ on:
- main

permissions:
contents: write
pull-requests: write
contents: write # Required for to push tags, create release, and push changes to the wiki
pull-requests: write # Required to comment on pull request

jobs:
release:
Expand All @@ -178,12 +202,13 @@ jobs:
major-keywords: major update,breaking change
minor-keywords: feat,feature
patch-keywords: fix,chore,docs
default-first-tag: v2.0.0
github_token: ${{ secrets.GITHUB_TOKEN }}
terraform-docs-version: v0.20.0
default-first-tag: v1.0.0
terraform-docs-version: v0.19.0
delete-legacy-tags: true
disable-wiki: false
wiki-sidebar-changelog-max: 10
module-change-exclude-patterns: .gitignore,*.md,*.tftest.hcl,tests/**
module-asset-exclude-patterns: .gitignore,*.md,*.tftest.hcl,tests/**
```

## Inspiration
Expand Down
24 changes: 24 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,36 @@ inputs:
or where third-party branding is undesirable.
required: true
default: "false"
module-change-exclude-patterns:
description: >
A comma-separated list of file patterns to exclude from triggering version changes in Terraform modules.
These patterns follow glob syntax (e.g., ".gitignore,*.md") and are relative to each Terraform module directory within
the repository, rather than the workspace root. Patterns are used for filtering files within module directories, allowing
for specific exclusions like documentation or non-Terraform code changes that do not require a version increment.

The minimatch syntax is used for pattern matching. Files matching these patterns will not affect version changes.

WARNING: Avoid excluding '*.tf' files, as they are essential for module detection and versioning processes.
required: true
default: ".gitignore,*.md,*.tftest.hcl,tests/**"
module-asset-exclude-patterns:
description: >
A comma-separated list of file patterns to exclude when bundling a Terraform module for tag/release.
These patterns follow glob syntax (e.g., "tests/**") and are relative to each Terraform module directory within
the repository. By default, all non-functional Terraform files and directories are excluded to reduce the size of the
bundled assets. This helps ensure that any imported file is correctly mapped, while allowing for further exclusions of
tests and other non-functional files as needed.

The minimatch syntax is used for pattern matching. Files matching these patterns will be excluded from the bundled output.
required: true
default: ".gitignore,*.md,*.tftest.hcl,tests/**"
github_token:
description: |
Required for retrieving pull request metadata, tags, releases, updating PR comments, wiki, and creating tags/releases.
Automatically injected for convenience; no need to provide a custom token unless you have specific requirements.
required: true
default: ${{ github.token }}

runs:
using: node20
main: dist/index.js
Loading