feat: integrate swag fmt and improve CI/CD workflows
Some checks failed
Go CI/CD Pipeline / Lint and Format (push) Successful in 4m51s
Docker Build and Publish / Version Bump (push) Successful in 4m54s
Docker Build and Publish / Build and Push Docker Image (push) Failing after 2m51s
Go CI/CD Pipeline / Build and Test (push) Successful in 9m47s
Go CI/CD Pipeline / Version Management (push) Successful in 12s
Some checks failed
Go CI/CD Pipeline / Lint and Format (push) Successful in 4m51s
Docker Build and Publish / Version Bump (push) Successful in 4m54s
Docker Build and Publish / Build and Push Docker Image (push) Failing after 2m51s
Go CI/CD Pipeline / Build and Test (push) Successful in 9m47s
Go CI/CD Pipeline / Version Management (push) Successful in 12s
- Add swag fmt to git pre-commit hook and CI/CD pipeline - Create comprehensive CONTRIBUTING.md guide with AI section - Update ADR-0013 with swag fmt documentation - Fix swagger generation to include all endpoints - Improve local testing scripts and workflows - Update Dockerfile for better swagger handling - Fix CI/CD workflow file references
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
---
|
||||
---
|
||||
# DanceLessonsCoach Docker Image Build Workflow
|
||||
# Based on Arcodange webapp conventions
|
||||
# Builds and publishes Docker images to Gitea Container Registry
|
||||
@@ -32,9 +32,66 @@ env:
|
||||
CI_REGISTRY: "gitea.arcodange.lab"
|
||||
|
||||
jobs:
|
||||
version-bump:
|
||||
name: Version Bump
|
||||
runs-on: ubuntu-latest
|
||||
if: github.ref == 'refs/heads/main'
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.26.1'
|
||||
|
||||
- name: Install swag and generate Swagger Docs
|
||||
run: |
|
||||
if [ ! -f pkg/server/docs/swagger.json ]; then
|
||||
echo "📝 Generating Swagger documentation..."
|
||||
go install github.com/swaggo/swag/cmd/swag@latest
|
||||
cd pkg/server && go generate
|
||||
echo "✅ Swagger documentation generated"
|
||||
else
|
||||
echo "✅ Swagger documentation already exists, skipping generation"
|
||||
fi
|
||||
|
||||
- name: Bump version based on commit type
|
||||
run: |
|
||||
# Analyze last commit message
|
||||
LAST_COMMIT=$(git log -1 --pretty=%B | head -1)
|
||||
|
||||
if echo "$LAST_COMMIT" | grep -q "^feat:"; then
|
||||
echo "🎯 Feature commit detected - bumping MINOR version"
|
||||
./scripts/version-bump.sh minor
|
||||
elif echo "$LAST_COMMIT" | grep -q "^fix:"; then
|
||||
echo "🐛 Fix commit detected - bumping PATCH version"
|
||||
./scripts/version-bump.sh patch
|
||||
elif echo "$LAST_COMMIT" | grep -q "BREAKING CHANGE"; then
|
||||
echo "💥 Breaking change detected - bumping MAJOR version"
|
||||
./scripts/version-bump.sh major
|
||||
else
|
||||
echo "⏭️ No automatic version bump needed"
|
||||
# Still ensure swagger version is updated
|
||||
source VERSION
|
||||
NEW_VERSION="$MAJOR.$MINOR.$PATCH${PRERELEASE:+-$PRERELEASE}"
|
||||
sed -i "s|// @version [0-9.]*|// @version $NEW_VERSION|" cmd/server/main.go
|
||||
fi
|
||||
|
||||
- name: Commit version changes
|
||||
run: |
|
||||
git config --global user.name "CI Bot"
|
||||
git config --global user.email "ci@arcodange.fr"
|
||||
git add VERSION cmd/server/main.go
|
||||
git commit -m "chore: auto version bump [skip ci]" || echo "No changes to commit"
|
||||
git push
|
||||
|
||||
build-and-push-image:
|
||||
name: Build and Push Docker Image
|
||||
runs-on: ubuntu-latest
|
||||
needs: version-bump
|
||||
if: always() && (needs.version-bump.result == 'success' || needs.version-bump.result == 'skipped')
|
||||
|
||||
steps:
|
||||
- name: Login to Gitea Container Registry
|
||||
@@ -80,4 +137,4 @@ jobs:
|
||||
else
|
||||
echo " - ${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}:latest"
|
||||
echo " - ${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}:${{ github.sha }}"
|
||||
fi
|
||||
fi
|
||||
@@ -91,9 +91,20 @@ jobs:
|
||||
with:
|
||||
go-version: '1.26.1'
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.26.1'
|
||||
|
||||
- name: Install swag
|
||||
run: go install github.com/swaggo/swag/cmd/swag@latest
|
||||
|
||||
- name: Run go fmt
|
||||
run: go fmt ./...
|
||||
|
||||
- name: Run swag fmt
|
||||
run: swag fmt
|
||||
|
||||
- name: Check for formatting issues
|
||||
run: |
|
||||
if [ -n "$(go fmt ./...)" ]; then
|
||||
@@ -105,7 +116,7 @@ jobs:
|
||||
version-check:
|
||||
name: Version Management
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build-test, lint-format, workflow-validation]
|
||||
needs: [build-test, lint-format]
|
||||
if: github.ref == 'refs/heads/main'
|
||||
|
||||
steps:
|
||||
|
||||
156
.gitea/workflows/test-local-ci-cd.yaml
Normal file
156
.gitea/workflows/test-local-ci-cd.yaml
Normal file
@@ -0,0 +1,156 @@
|
||||
---
|
||||
# Local CI/CD Testing Workflow
|
||||
# Simulates the CI/CD pipeline but builds Docker image locally
|
||||
# Use this for local development and testing
|
||||
|
||||
name: Local CI/CD Test
|
||||
|
||||
on:
|
||||
workflow_dispatch: {}
|
||||
push:
|
||||
branches:
|
||||
- 'test/**'
|
||||
- 'feature/**'
|
||||
paths-ignore:
|
||||
- 'README.md'
|
||||
- 'doc/**'
|
||||
- 'adr/**'
|
||||
- '.gitea/**'
|
||||
|
||||
# Arcodange-specific environment variables
|
||||
env:
|
||||
GITEA_INTERNAL: "https://gitea.arcodange.lab/"
|
||||
GITEA_EXTERNAL: "https://gitea.arcodange.fr/"
|
||||
GITEA_ORG: "arcodange"
|
||||
GITEA_REPO: "DanceLessonsCoach"
|
||||
CI_REGISTRY: "gitea.arcodange.lab"
|
||||
|
||||
jobs:
|
||||
local-test:
|
||||
name: Local CI/CD Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.26.1'
|
||||
cache: true
|
||||
|
||||
- name: Install dependencies
|
||||
run: go mod tidy
|
||||
|
||||
- name: Install swag
|
||||
run: go install github.com/swaggo/swag/cmd/swag@latest
|
||||
|
||||
- name: Generate Swagger Docs
|
||||
run: cd pkg/server && go generate
|
||||
|
||||
- name: Build all packages
|
||||
run: go build ./...
|
||||
|
||||
- name: Run tests with coverage
|
||||
run: go test ./... -cover -v
|
||||
|
||||
- name: Build binaries
|
||||
run: ./scripts/build.sh
|
||||
|
||||
- name: List artifacts
|
||||
run: ls -la bin/
|
||||
|
||||
- name: Version Bump Simulation
|
||||
run: |
|
||||
echo "📋 Simulating version bump based on commit type..."
|
||||
LAST_COMMIT=$(git log -1 --pretty=%B | head -1)
|
||||
echo "Last commit: $LAST_COMMIT"
|
||||
|
||||
if echo "$LAST_COMMIT" | grep -q "^feat:"; then
|
||||
echo "🎯 Feature commit detected - would bump MINOR version"
|
||||
echo "Run: ./scripts/version-bump.sh minor"
|
||||
elif echo "$LAST_COMMIT" | grep -q "^fix:"; then
|
||||
echo "🐛 Fix commit detected - would bump PATCH version"
|
||||
echo "Run: ./scripts/version-bump.sh patch"
|
||||
elif echo "$LAST_COMMIT" | grep -q "BREAKING CHANGE"; then
|
||||
echo "💥 Breaking change detected - would bump MAJOR version"
|
||||
echo "Run: ./scripts/version-bump.sh major"
|
||||
else
|
||||
echo "⏭️ No automatic version bump needed"
|
||||
fi
|
||||
|
||||
# Show current version
|
||||
source VERSION
|
||||
echo "📊 Current version: $MAJOR.$MINOR.$PATCH${PRERELEASE:+-$PRERELEASE}"
|
||||
|
||||
- name: Local Docker Build Instructions
|
||||
run: |
|
||||
echo "🐳 LOCAL DOCKER BUILD INSTRUCTIONS"
|
||||
echo "================================"
|
||||
echo ""
|
||||
|
||||
# Get current version
|
||||
source VERSION
|
||||
CURRENT_VERSION="$MAJOR.$MINOR.$PATCH${PRERELEASE:+-$PRERELEASE}"
|
||||
|
||||
echo "1. Build Docker image locally:"
|
||||
echo " docker build -t dance-lessons-coach:$CURRENT_VERSION ."
|
||||
echo ""
|
||||
|
||||
echo "2. Tag the image:"
|
||||
echo " docker tag dance-lessons-coach:$CURRENT_VERSION dance-lessons-coach:latest"
|
||||
echo ""
|
||||
|
||||
echo "3. Test the local image:"
|
||||
echo " docker run -p 8080:8080 dance-lessons-coach:$CURRENT_VERSION"
|
||||
echo ""
|
||||
|
||||
echo "4. Test API endpoints:"
|
||||
echo " curl http://localhost:8080/api/health"
|
||||
echo " curl http://localhost:8080/api/v1/greet/YourName"
|
||||
echo ""
|
||||
|
||||
echo "5. Clean up:"
|
||||
echo " docker stop <container_id> && docker rm <container_id>"
|
||||
echo ""
|
||||
|
||||
echo "💡 Tip: Use 'docker images' to see your built images"
|
||||
echo "💡 Use 'docker ps' to see running containers"
|
||||
|
||||
- name: Show Swagger UI Access
|
||||
run: |
|
||||
echo "📖 SWAGGER UI ACCESS"
|
||||
echo "===================="
|
||||
echo ""
|
||||
echo "After starting the container, access Swagger UI at:"
|
||||
echo " http://localhost:8080/swagger/"
|
||||
echo ""
|
||||
echo "Swagger JSON spec available at:"
|
||||
echo " http://localhost:8080/swagger/doc.json"
|
||||
echo ""
|
||||
echo "Generated Swagger files:"
|
||||
ls -la pkg/server/docs/ 2>/dev/null || echo " (Swagger docs will be generated during Docker build)"
|
||||
|
||||
- name: Test Summary
|
||||
run: |
|
||||
echo "✅ LOCAL CI/CD TEST COMPLETE"
|
||||
echo "============================"
|
||||
echo ""
|
||||
echo "📋 What was tested:"
|
||||
echo " ✅ Go dependencies installation"
|
||||
echo " ✅ Swagger documentation generation"
|
||||
echo " ✅ Code compilation"
|
||||
echo " ✅ Unit tests with coverage"
|
||||
echo " ✅ Binary build"
|
||||
echo " ✅ Version bump simulation"
|
||||
echo ""
|
||||
echo "🐳 Next steps:"
|
||||
echo " 1. Build Docker image locally (see instructions above)"
|
||||
echo " 2. Test the container"
|
||||
echo " 3. Verify API endpoints"
|
||||
echo " 4. Test Swagger UI"
|
||||
echo ""
|
||||
echo "🎯 When ready for production:"
|
||||
echo " Push to main branch to trigger full CI/CD pipeline"
|
||||
echo " Docker image will be built and pushed to Gitea Container Registry"
|
||||
Reference in New Issue
Block a user