From 7100a8580e6f58a466713a30438ef363a66e5f51 Mon Sep 17 00:00:00 2001 From: Jacob Brewer Date: Thu, 7 Nov 2024 11:05:34 +0000 Subject: [PATCH] chore(cicd): updating the cicd for installing dependencies (#65) * updating the cicd for installing dependencies * debug * debug * debug * debug * debug * debug * debug * remove debug --- .github/workflows/ci-code-approval.yml | 11 +++++------ Makefile | 5 ++++- pkg/models/generate.sh | 14 ++++++++++++++ pkg/models/schemas/season.sql | 4 ++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-code-approval.yml b/.github/workflows/ci-code-approval.yml index c6978d1..63a966e 100644 --- a/.github/workflows/ci-code-approval.yml +++ b/.github/workflows/ci-code-approval.yml @@ -139,17 +139,16 @@ jobs: GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: git config --global url."https://x:${GITHUB_API_TOKEN}@github.com".insteadOf "https://github.com" - - name: "Install goschema" - run: | - wget https://github.com/jacobbrewer1/goschema/releases/download/v0.0.1/goschema - chmod +x goschema - mv goschema /usr/local/bin + - name: "Install dependencies" + run: make deps - name: "Run Code Generation" run: make codegen + env: + GS_SILENT: true - name: "fmt" run: go fmt ./... - - name: "Check for changes" + - name: "Fail if code generation changes files" run: git diff --exit-code diff --git a/Makefile b/Makefile index db8948a..58a1efc 100644 --- a/Makefile +++ b/Makefile @@ -7,14 +7,17 @@ pr-approval: go build ./... go vet ./... go test ./... -codegen: deps +codegen: @echo "Generating code" go generate ./... deps: + sudo apt-get install dos2unix + dos2unix ./pkg/models/generate.sh chmod +x ./pkg/models/generate.sh go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest go install github.com/charmbracelet/gum@latest go install golang.org/x/tools/cmd/goimports@latest + go install github.com/jacobbrewer1/goschema@latest models: chmod +x ./pkg/models/generate.sh go generate ./pkg/models diff --git a/pkg/models/generate.sh b/pkg/models/generate.sh index 329eba5..45b2a3f 100755 --- a/pkg/models/generate.sh +++ b/pkg/models/generate.sh @@ -18,6 +18,7 @@ fi all=false clean=false forced=false +silent=false # Get the flags passed to the script and set the variables accordingly while getopts "acf" flag; do @@ -38,6 +39,11 @@ while getopts "acf" flag; do esac done +# If the silent environment variable is set, set the silent flag to true +if [ "$GS_SILENT" = true ]; then + silent=true +fi + # If the -c flag is passed, remove all generated models if [ "$clean" = true ]; then if [ "$forced" = false ]; then @@ -50,6 +56,14 @@ fi # If the -a flag is passed, generate all models if [ "$all" = true ]; then + if [ "$silent" = true ]; then + echo "Generating all models" + goschema generate --out=./ --sql=./schemas/*.sql --extension=xo + go fmt ./*.xo.go + goimports -w ./*.xo.go + exit 0 + fi + gum spin --spinner dot --title "Generating all models" -- goschema generate --out=./ --sql=./schemas/*.sql --extension=xo go fmt ./*.xo.go goimports -w ./*.xo.go diff --git a/pkg/models/schemas/season.sql b/pkg/models/schemas/season.sql index 6b04d56..3665676 100644 --- a/pkg/models/schemas/season.sql +++ b/pkg/models/schemas/season.sql @@ -1,7 +1,7 @@ create table season ( - id int not null auto_increment, - year int not null, + id int not null auto_increment, + year int not null, primary key (id) );