diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..f79d48ee --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +# 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] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '1.22' + + - name: Install dependencies + run: go mod tidy + + - name: Check and update Swagger docs + run: make docs diff --git a/Makefile b/Makefile index 66152bd7..b07031ae 100644 --- a/Makefile +++ b/Makefile @@ -50,9 +50,34 @@ lint: ## Run linter .PHONY: docs -docs: ## Generate swagger docs +docs: check_docs # Generate swagger docs + +.PHONY: check_docs +check_docs: + @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; \ + 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 db-migrations: ## Run the migrations for the database @@ -62,4 +87,4 @@ db-migrations: ## Run the migrations for the database 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}' + @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