Skip to content

Commit e32668f

Browse files
committed
refactor: improve GitHub API interactions and error handling
This commit refactors the GitHub API interactions and error handling in the codebase. The changes include: - Separating the GitHub API interactions from the shared module `github.ts` and into the purpose-specific file (e.g. tags, releases). - Improving error handling for GitHub API requests. - Adding more detailed logging for GitHub API requests. - Drop @actions/github and instantiate GitHub context and Octokit directly. This allows us to leverage proper instanceof RequestError. - Updating the README.md file to reflect the changes. Fixes #17
1 parent 42f1087 commit e32668f

21 files changed

+11778
-12235
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111
- main
1212

1313
permissions:
14-
contents: write
15-
pull-requests: write
14+
contents: write # Required to create tags, creaste releases and update wiki
15+
pull-requests: write # Required to comment on pull requests
1616

1717
jobs:
1818
test-action:

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,27 +124,29 @@ requests and creating releases.
124124
for `pull-requests` must be set to `"write"`.
125125
- Additionally, the workflow permission for `contents` must also be set to `"write"` to allow the action to create tags
126126
and releases.
127-
- For security considerations and best practices when using the `github_token` or PATs, please refer to the
127+
- For security considerations and best practices when using the `github_token`, please refer to the
128128
[Security Documentation](./security.md).
129129
- Ensure the **Restrict editing to users in teams with push access only** setting is enabled for public repositories, as
130130
the GitHub Actions Bot can write to the wiki by default.
131131

132132
If the permissions are insufficient, the action may fail with a 403 error, indicating a lack of access to the necessary
133133
resources.
134134

135-
## Optional Inputs
135+
## Input Parameters
136136

137-
| Input | Description | Default |
138-
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------ |
139-
| `major-keywords` | Keywords in commit messages that indicate a major release | `major change,breaking change` |
140-
| `minor-keywords` | Keywords in commit messages that indicate a minor release | `feat,feature` |
141-
| `patch-keywords` | Keywords in commit messages that indicate a patch release | `fix,chore,docs` |
142-
| `default-first-tag` | Specifies the default tag version | `v1.0.0` |
143-
| `github_token` | Use this if you wish to use a different GitHub token than the one provided by the workflow | `${{ github.token }}default` |
144-
| `terraform-docs-version` | Specifies the terraform-docs version used to generate documentation for the wiki | `v0.19.0` |
145-
| `delete-legacy-tags` | Specifies a boolean that determines whether tags from Terraform modules that have been deleted should be automatically removed | `true` |
146-
| `disable-wiki` | Whether to disable wiki generation for Terraform modules | `false` |
147-
| `wiki-sidebar-changelog-max` | An integer that specifies how many changelog entries are displayed in the sidebar per module | `5` |
137+
While the out-of-the-box defaults are suitable for most use cases, you can further customize the action's behavior by
138+
configuring the following optional input parameters as needed.
139+
140+
| Input | Description | Default |
141+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
142+
| `major-keywords` | Keywords in commit messages that indicate a major release | `major change,breaking change` |
143+
| `minor-keywords` | Keywords in commit messages that indicate a minor release | `feat,feature` |
144+
| `patch-keywords` | Keywords in commit messages that indicate a patch release | `fix,chore,docs` |
145+
| `default-first-tag` | Specifies the default tag version | `v1.0.0` |
146+
| `terraform-docs-version` | Specifies the terraform-docs version used to generate documentation for the wiki | `v0.19.0` |
147+
| `delete-legacy-tags` | Specifies a boolean that determines whether tags and releases from Terraform modules that have been deleted should be automatically removed | `true` |
148+
| `disable-wiki` | Whether to disable wiki generation for Terraform modules | `false` |
149+
| `wiki-sidebar-changelog-max` | An integer that specifies how many changelog entries are displayed in the sidebar per module | `5` |
148150

149151
### Example Usage with Inputs
150152

@@ -190,7 +192,8 @@ by Piotr Krukowski.
190192
## Notes
191193

192194
- This action uses [Conventional Commits](https://www.conventionalcommits.org/) to automatically determine the release
193-
type _(major, minor, or patch)_ based on commit messages.
195+
type _(major, minor, or patch)_ based on commit messages. This behavior is configurable via
196+
[inputs](#input-parameters).
194197
- Versioning is done using [Semantic Versioning (SemVer)](https://semver.org/), which provides a clear and consistent
195198
way to manage module versions.
196199
- Commit messages are linked to the respective Terraform directories _(handling PRs that may have separate modules and

action.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ inputs:
2424
description: Specifies the default tag version. (Should be in format v#.#.#)
2525
required: true
2626
default: v1.0.0
27-
github_token:
28-
description: Use this if you wish to use a different GitHub token than the one provided by the workflow.
29-
required: true
30-
default: ${{ github.token }}default
3127
terraform-docs-version:
3228
description: >
3329
Specifies the terraform-docs version used to generate documentation for the wiki.
@@ -55,7 +51,12 @@ inputs:
5551
Adjust this value to control the visibility of changelog entries in the module sidebar.
5652
required: true
5753
default: "5"
58-
54+
github_token:
55+
description: |
56+
Required for retrieving pull request metadata, tags, releases, updating PR comments, wiki, and creating tags/releases.
57+
Automatically injected for convenience; no need to provide a custom token unless you have specific requirements.
58+
required: true
59+
default: ${{ github.token }}
5960
runs:
6061
using: node20
6162
main: dist/index.js

0 commit comments

Comments
 (0)