From 1e4d66fc28c63646ddf6c6f28f7fe70472712aac Mon Sep 17 00:00:00 2001 From: Dariksha Date: Sun, 2 Jun 2024 15:00:13 +0530 Subject: [PATCH 1/5] Added updated check for docs using swagger in Makefile Signed-off-by: Dariksha --- Makefile | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 66152bd7..82ae9fe7 100644 --- a/Makefile +++ b/Makefile @@ -16,50 +16,67 @@ # See https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#autobuild-for-go all: help -run-dev: ## Run the dev server +# Run the dev server +run-dev: @echo "Running dev server. It will refresh automatically when you change code." @docker compose -f compose-dev.yml up --remove-orphans - .PHONY: stop -stop: ## Stop the dev server +# Stop the dev server +stop: @docker-compose -f compose-dev.yml down -v - .PHONY: clean -clean: ## Clean up the dev server +# Clean up the dev server +clean: $(MAKE) stop @docker compose -f compose-dev.yml rm --force @docker rmi archivista-archivista --force - .PHONY: test -test: ## Run tests +# Run tests +test: @go test ./... -covermode atomic -coverprofile=cover.out -v .PHONY: coverage -coverage: ## Show html coverage +# Show html coverage +coverage: @go tool cover -html=cover.out - .PHONY: lint -lint: ## Run linter +# Run linter +lint: @golangci-lint run @go fmt ./... @go vet ./... - .PHONY: docs -docs: ## Generate swagger docs +# Generate swagger docs +docs: check_docs + +.PHONY: check_docs +check_docs: + @server_mod_time=$$(stat -c %Y internal/server/server.go); \ + swagger_mod_time=$$(stat -c %Y docs/swagger.json); \ + if [ $$server_mod_time -gt $$swagger_mod_time ]; then \ + echo "Swagger documentation needs to be updated"; \ + make update_docs; \ + else \ + echo "Swagger documentation is up to date"; \ + fi + +.PHONY: update_docs +update_docs: @go install github.com/swaggo/swag/cmd/swag@v1.16.2 @swag init -o docs -d internal/server -g server.go -pd .PHONY: db-migrations -db-migrations: ## Run the migrations for the database +# Run the migrations for the database +db-migrations: @go generate ./... @atlas migrate diff mysql --dir "file://ent/migrate/migrations/mysql" --to "ent://ent/schema" --dev-url "docker://mysql/8/dev" @atlas migrate diff pgsql --dir "file://ent/migrate/migrations/pgsql" --to "ent://ent/schema" --dev-url "docker://postgres/16/dev?search_path=public" - -help: ## Show this help +# Show this help +help: @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' From 32b77a462f8b28322e17dc354a1572fea682ef80 Mon Sep 17 00:00:00 2001 From: Dariksha Date: Sun, 2 Jun 2024 15:07:33 +0530 Subject: [PATCH 2/5] Added updated makefile Signed-off-by: Dariksha --- Makefile | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 82ae9fe7..8635aed1 100644 --- a/Makefile +++ b/Makefile @@ -16,43 +16,41 @@ # See https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#autobuild-for-go all: help -# Run the dev server -run-dev: +run-dev: ## Run the dev server @echo "Running dev server. It will refresh automatically when you change code." @docker compose -f compose-dev.yml up --remove-orphans + .PHONY: stop -# Stop the dev server -stop: +stop: ## Stop the dev server @docker-compose -f compose-dev.yml down -v + .PHONY: clean -# Clean up the dev server -clean: +clean: ## Clean up the dev server $(MAKE) stop @docker compose -f compose-dev.yml rm --force @docker rmi archivista-archivista --force + .PHONY: test -# Run tests -test: +test: ## Run tests @go test ./... -covermode atomic -coverprofile=cover.out -v .PHONY: coverage -# Show html coverage -coverage: +coverage: ## Show html coverage @go tool cover -html=cover.out + .PHONY: lint -# Run linter -lint: +lint: ## Run linter @golangci-lint run @go fmt ./... @go vet ./... + .PHONY: docs -# Generate swagger docs -docs: check_docs +docs: check_docs # Generate swagger docs .PHONY: check_docs check_docs: @@ -70,13 +68,13 @@ update_docs: @go install github.com/swaggo/swag/cmd/swag@v1.16.2 @swag init -o docs -d internal/server -g server.go -pd + .PHONY: db-migrations -# Run the migrations for the database -db-migrations: +db-migrations: ## Run the migrations for the database @go generate ./... @atlas migrate diff mysql --dir "file://ent/migrate/migrations/mysql" --to "ent://ent/schema" --dev-url "docker://mysql/8/dev" @atlas migrate diff pgsql --dir "file://ent/migrate/migrations/pgsql" --to "ent://ent/schema" --dev-url "docker://postgres/16/dev?search_path=public" -# Show this help -help: - @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +help: ## Show this help + @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' \ No newline at end of file From f7e3cc3a7b36cd1e9752a27b2b529f054eb55c3a Mon Sep 17 00:00:00 2001 From: Dariksha Date: Mon, 3 Jun 2024 19:26:07 +0530 Subject: [PATCH 3/5] added the changes and github workflow Signed-off-by: Dariksha --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ Makefile | 18 ++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..1ce30bcf --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,20 @@ +name: CI + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '1.16' + + - name: Install dependencies + run: go mod tidy + + - name: Check and update Swagger docs + run: make docs diff --git a/Makefile b/Makefile index 8635aed1..b07031ae 100644 --- a/Makefile +++ b/Makefile @@ -54,19 +54,29 @@ docs: check_docs # Generate swagger docs .PHONY: check_docs check_docs: - @server_mod_time=$$(stat -c %Y internal/server/server.go); \ - swagger_mod_time=$$(stat -c %Y docs/swagger.json); \ - if [ $$server_mod_time -gt $$swagger_mod_time ]; then \ + @echo "Checking if Swagger documentation needs to be updated..." + @temp_dir=$$(mktemp -d); \ + mkdir -p $$temp_dir/docs; \ + go install github.com/swaggo/swag/cmd/swag@v1.16.2; \ + swag init -o $$temp_dir/docs -d internal/server -g server.go -pd > /dev/null 2>&1; \ + if [ ! -f docs/swagger.json ]; then \ + echo "Swagger documentation needs to be generated"; \ + make update_docs; \ + elif ! diff -q $$temp_dir/docs/swagger.json docs/swagger.json > /dev/null; then \ echo "Swagger documentation needs to be updated"; \ make update_docs; \ else \ echo "Swagger documentation is up to date"; \ - fi + fi; \ + rm -rf $$temp_dir .PHONY: update_docs update_docs: + @echo "Updating Swagger documentation..." @go install github.com/swaggo/swag/cmd/swag@v1.16.2 @swag init -o docs -d internal/server -g server.go -pd + @echo "Swagger documentation updated" + .PHONY: db-migrations From 769a79715f5412c70acb77d028b4ee4545c7c402 Mon Sep 17 00:00:00 2001 From: Dariksha Date: Mon, 3 Jun 2024 19:35:24 +0530 Subject: [PATCH 4/5] added license in ci.yml Signed-off-by: Dariksha --- .github/workflows/ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ce30bcf..44882d8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,3 +1,16 @@ +# Copyright 2024 The Archivista Contributors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. name: CI on: [push, pull_request] From 7988ae473377f2c6b16ddaeaf9c39efafe9e5eca Mon Sep 17 00:00:00 2001 From: John Kjell Date: Thu, 6 Jun 2024 13:18:01 -0500 Subject: [PATCH 5/5] Update .github/workflows/ci.yml Signed-off-by: John Kjell --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44882d8c..f79d48ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.16' + go-version: '1.22' - name: Install dependencies run: go mod tidy