This GitHub Action, named "Validate Go Generate," is designed to help validate and manage Go code generation in a GitHub repository. The action performs tasks such as removing generated files, regenerating them using go generate
, and optionally committing the changes. Below is a detailed explanation of the inputs, steps, and usage.
-
root_path (default:
./
):- Description: The application's root path.
- Default:
./
-
commit (default:
false
):- Description: A flag indicating whether to commit the changes.
- Default:
false
-
commit-message (default:
'fix: generate files'
):- Description: The commit message to be used if commits are enabled.
- Default:
'fix: generate files'
-
commit-actor (default:
'github_actions'
):- Description: The actor or user to be associated with the commit.
- Default:
'github_actions'
The GitHub Action consists of the following steps:
-
Remove generated files:
- Description: Removes files generated by Go code generation based on a specific comment pattern.
-
Generate files:
- Description: Invokes the
go generate
command to regenerate files as per the Go code generation instructions.
- Description: Invokes the
-
Commit changes (conditional):
- Description: Commits the changes if the
commit
input is set totrue
. - Default Commit Message:
'fix: generate files'
- Default Commit Actor:
'github_actions'
- Description: Commits the changes if the
-
Check diff (conditional):
- Description: Checks for differences in the working directory after the changes.
- Conditional: Only runs if
commit
is set tofalse
.
name: Validate Go Generate
on:
pull_request:
jobs:
validate_go_generate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Run Validate Go Generate
uses: path/to/[email protected]
with:
root_path: './'
commit: 'true'
commit-message: 'fix: updated generated files'
commit-actor: 'github_actions'