Skip to content

Commit

Permalink
added step to check generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
fmartingr committed Dec 25, 2023
1 parent f1a1305 commit 6cd8ec4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/workflows/_generated-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "generated-check"

on: workflow_call

jobs:
swagger-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version-file: 'go.mod'

- name: check
run: make generated-check

4 changes: 3 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ jobs:
uses: ./.github/workflows/_test.yml
call-swagger-check:
uses: ./.github/workflows/_swagger-check.yml
call-generated-check:
uses: ./.github/workflows/_generated-check.yml
call-styles-check:
uses: ./.github/workflows/_styles-check.yml
call-gorelease:
needs: [call-lint, call-test, call-swagger-check, call-styles-check]
needs: [call-lint, call-test, call-swagger-check, call-generated-check, call-styles-check]
uses: ./.github/workflows/_gorelease.yml
call-buildx:
needs: call-gorelease
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ SHIORI_DEVELOPMENT ?= true
SWAG_VERSION := $(shell grep "swaggo/swag" go.mod | cut -d " " -f 2)
SWAGGER_DOCS_PATH ?= ./docs/swagger

# Versions
MOCKGEN_VERSION ?= v0.4.0

# Frontend
CLEANCSS_OPTS ?= --with-rebase

Expand Down Expand Up @@ -98,4 +101,11 @@ coverage:
## Run generate accross the project
.PHONY: generated
generate:
go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)
$(GO) generate ./...

## Run generate accross the project
.PHONY: generated-check
generate-check:
go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)
./scripts/generate_check.sh
26 changes: 26 additions & 0 deletions scripts/generate_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# This script is used to check that the go generated files are up to date:
GENERATE_PATHS=(
"internal/mocks"
)

# Check if the git tree for the paths is clean
for path in "${GENERATE_PATHS[@]}"; do
if [ -n "$(git status $path --porcelain)" ]; then
echo "❌ git tree is not clean. Please commit all changes before running this script."
git status $path --porcelain
exit 1
fi
done

# Check if the go generated files are up to date
make generate
for path in "${GENERATE_PATHS[@]}"; do
if [ -n "$(git status $path --porcelain)" ]; then
echo "❌ go generated files are not up to date. Please run 'make generate' and commit the changes."
git status $path --porcelain
git checkout -- $path
exit 1
fi
done

0 comments on commit 6cd8ec4

Please sign in to comment.