Skip to content
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

feat: allow ignoring protoc version comments in go generate check #53

Merged
merged 5 commits into from
Oct 31, 2023
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
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/[email protected]
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]"
Comment on lines +93 to +94

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand correctly that this won't be actually commit the repo? Is this commit only used on CI?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's 100% right. We're only making a local commit to make it easier to check the diff. But even for local commits, git wants us to set user details.

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