Skip to content

This is a Github Action that verifies that the files generated by the go generate command are up to date.

Notifications You must be signed in to change notification settings

pinnacles/validate-go-generate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

Validate Go Generate GitHub Action

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.

Usage

Inputs

  1. root_path (default: ./):

    • Description: The application's root path.
    • Default: ./
  2. commit (default: false):

    • Description: A flag indicating whether to commit the changes.
    • Default: false
  3. commit-message (default: 'fix: generate files'):

    • Description: The commit message to be used if commits are enabled.
    • Default: 'fix: generate files'
  4. generated-by (default: .*)

    • Description: Target only the code generated by the specified generator. By default, all generators
    • Default: .*
  5. commit-actor (default: 'github_actions'):

    • Description: The actor or user to be associated with the commit.
    • Default: 'github_actions'

Runs

The GitHub Action consists of the following steps:

  1. Remove generated files:

    • Description: Removes files generated by Go code generation based on a specific comment pattern.
  2. Generate files:

    • Description: Invokes the go generate command to regenerate files as per the Go code generation instructions.
  3. Commit changes (conditional):

    • Description: Commits the changes if the commit input is set to true.
    • Default Commit Message: 'fix: generate files'
    • Default Commit Actor: 'github_actions'
  4. Check diff (conditional):

    • Description: Checks for differences in the working directory after the changes.
    • Conditional: Only runs if commit is set to false.

Example YAML

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/validate-go-generate-action@v0.1.0
      with:
        root_path: './'
        commit: 'true'
        commit-message: 'fix: updated generated files'
        commit-actor: 'github_actions'

About

This is a Github Action that verifies that the files generated by the go generate command are up to date.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •