Skip to content

Commit

Permalink
update and validate swagger.json (#4619)
Browse files Browse the repository at this point in the history
update swagger and add new github action to detect if swagger is not up
to date with the source
  • Loading branch information
wdbaruni authored Oct 13, 2024
1 parent f09deb8 commit 85cbe5b
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 2,952 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/swagger-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Swagger Validation

on:
pull_request:
branches:
- main

jobs:
ensure-up-to-date:
name: Ensure Up-to-date
runs-on: ubuntu-latest

steps:
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1

# Detect Go version from go.mod
- name: Detect Go version from go.mod
id: detect-go-version
run: |
go_version=$(grep '^go ' go.mod | awk '{print $2}')
echo "Go version detected: $go_version"
echo "golang-version=$go_version" >> $GITHUB_ENV
# Setup Go using the detected version
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.golang-version }}
cache: true

# Install swag (Swagger generator)
- name: Install Swag
run: |
go install github.com/swaggo/swag/cmd/swag@latest
# Verify swag installation
- name: Verify Swag Installation
run: |
if ! command -v swag &> /dev/null; then
echo "Swag is not installed. Please ensure Go is properly configured and Swag is installed."
exit 1
fi
# Generate the swagger.json
- name: Generate Swagger file
run: make generate-swagger

# Compare the newly generated swagger.json with the committed swagger.json
- name: Check for Swagger differences
run: |
git diff --exit-code pkg/swagger/swagger.json || (echo "Swagger is outdated. Please regenerate it with 'make generate-swagger' and commit the changes." && exit 1)
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,15 @@ endif
# it is missing.
################################################################################
.PHONY: precommit
precommit:
precommit: check-precommit
@mkdir -p webui/build && touch webui/build/stub
${PRECOMMIT} run --all
@rm webui/build/stub
cd python && ${MAKE} pre-commit

# Check if pre-commit is installed only for precommit target
.PHONY: check-precommit
check-precommit:
PRECOMMIT_HOOKS_INSTALLED ?= $(shell grep -R "pre-commit.com" .git/hooks)
ifeq ($(PRECOMMIT_HOOKS_INSTALLED),)
$(warning "Pre-commit is not installed in .git/hooks/pre-commit. Please run 'make install-pre-commit' to install it.")
Expand Down Expand Up @@ -471,3 +474,7 @@ release: build-bacalhau
.PHONY: spellcheck-code
spellcheck-code:
cspell lint -c cspell.yaml --quiet "**/*.{go,js,ts,jsx,tsx,md,yml,yaml,json}"

.PHONY: generate-swagger
generate-swagger:
./scripts/generate_swagger.sh
Loading

0 comments on commit 85cbe5b

Please sign in to comment.