Skip to content

Commit

Permalink
feat: allow ignoring protoc version comments in go generate check (#53)
Browse files Browse the repository at this point in the history
* feat: allow ignoring protoc version comments in go generate check

* fix: do not run sed with no input files

* fix: set user before commit

* fix: commit only if there is something to commit

* fix: env var check
  • Loading branch information
galargh authored Oct 31, 2023
1 parent 0824a32 commit 1aa50e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion .github/workflows/go-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
go-version:
required: false
type: string
go-generate-ignore-protoc-version-comments:
required: false
type: boolean

jobs:
unit:
Expand Down Expand Up @@ -79,12 +82,25 @@ jobs:
- name: go generate
uses: protocol/multiple-go-modules@v1.2
if: (success() || failure()) && fromJSON(steps.config.outputs.json).gogenerate == true
env:
IGNORE_PROTOC_VERSION_COMMENTS: ${{ inputs.go-generate-ignore-protoc-version-comments }}
with:
run: |
git clean -fd # make sure there aren't untracked files / directories
if [[ "$IGNORE_PROTOC_VERSION_COMMENTS" == "true" ]]; then
find . -name '*.pb.go' -print0 | xargs -0 -r sed -i '/^\/\/.*protoc.*v/d'
git add .
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git diff --cached --quiet || git commit -m "chore: remove protoc version comments"
fi
go generate -x ./...
if [[ "$IGNORE_PROTOC_VERSION_COMMENTS" == "true" ]]; then
find . -name '*.pb.go' -print0 | xargs -0 -r sed -i '/^\/\/.*protoc.*v/d'
fi
git add .
# check if go generate modified or added any files
if ! $(git add . && git diff-index HEAD --exit-code --quiet); then
if ! $(git diff-index HEAD --exit-code --quiet); then
echo "go generated caused changes to the repository:"
git status --short
exit 1
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- ability to ignore protoc version comments in `go generate` check

## [0.0.12] - 2023-08-23
### Changed
Expand Down

0 comments on commit 1aa50e9

Please sign in to comment.