validate swagger.json #10
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Swagger Validation | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
ensure-up-to-date: | |
name: Ensure Up-to-date | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Detect Go version | |
id: runtimes | |
run: echo "::set-output name=golang-version::$(grep 'go [[:digit:]].[[:digit:]]*' go.work | cut -d' ' -f2)" | |
- name: Install Golang | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ steps.runtimes.outputs.golang-version }} | |
# Step 2: Install swag (Swagger generator) | |
- name: Install Swag | |
run: | | |
go install github.com/swaggo/swag/cmd/swag@latest | |
# Step 3: 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 | |
# Step 4: Generate the swagger.json | |
- name: Generate Swagger file | |
run: | | |
./scripts/generate-swagger.sh | |
# Step 5: 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 | |
# Step 6: Fail the build if Swagger doesn't match | |
- name: Fail if Swagger has differences | |
if: failure() | |
run: | | |
echo "Swagger is outdated. Please regenerate it with 'bash ./scripts/generate-swagger.sh' and commit the changes." | |
exit 1 |