diff --git a/.gitea/workflows/dockerimage.yaml b/.gitea/workflows/dockerimage.yaml new file mode 100644 index 0000000..2010c52 --- /dev/null +++ b/.gitea/workflows/dockerimage.yaml @@ -0,0 +1,83 @@ +--- +# DanceLessonsCoach Docker Image Build Workflow +# Based on Arcodange webapp conventions +# Builds and publishes Docker images to Gitea Container Registry + +name: Docker Build and Publish + +on: + workflow_dispatch: {} + push: + branches: + - main + tags: + - 'v*.*.*' + paths-ignore: + - 'README.md' + - 'doc/**' + - 'adr/**' + - '.gitea/**' + +# cancel any previously-started, yet still active runs of this workflow on the same branch +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +# 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: + build-and-push-image: + name: Build and Push Docker Image + runs-on: ubuntu-latest + + steps: + - name: Login to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.CI_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.PACKAGES_TOKEN }} + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push image to Gitea Container Registry + run: |- + # Determine tags based on event type + if [[ "${{ github.ref }}" == refs/tags/* ]]; then + # For tags, use the tag name and latest + TAGS="${{ github.ref_name }} latest" + else + # For main branch, use commit SHA and latest + TAGS="latest ${{ github.sha }}" + fi + + echo "Building Docker image with tags: $TAGS" + docker build -t dance-lessons-coach . + + for TAG in $TAGS; do + IMAGE_NAME="${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}:$TAG" + echo "Tagging and pushing: $IMAGE_NAME" + docker tag dance-lessons-coach "$IMAGE_NAME" + docker push "$IMAGE_NAME" + done + + - name: Show published images + run: |- + echo "๐Ÿ“ฆ Published Docker images:" + if [[ "${{ github.ref }}" == refs/tags/* ]]; then + echo " - ${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}:${{ github.ref_name }}" + echo " - ${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}:latest" + 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 diff --git a/.gitea/workflows/ci-cd.yaml b/.gitea/workflows/go-ci-cd.yaml similarity index 84% rename from .gitea/workflows/ci-cd.yaml rename to .gitea/workflows/go-ci-cd.yaml index 4a1f230..76fc195 100644 --- a/.gitea/workflows/ci-cd.yaml +++ b/.gitea/workflows/go-ci-cd.yaml @@ -3,10 +3,10 @@ # Follows Arcodange conventions from webapp workflow # Uses .gitea/workflows/ directory and internal registry -name: DanceLessonsCoach CI/CD +name: Go CI/CD Pipeline on: - workflow_dispatch: true + workflow_dispatch: {} push: branches: - main @@ -18,10 +18,16 @@ on: - 'README.md' - 'doc/**' - 'adr/**' + - '.gitea/**' pull_request: branches: - main types: [opened, synchronize, reopened, labeled] + paths-ignore: + - 'README.md' + - 'doc/**' + - 'adr/**' + - '.gitea/**' # cancel any previously-started runs of this workflow on the same branch concurrency: @@ -94,7 +100,7 @@ jobs: echo "โœ… Code is properly formatted" workflow-validation: - name: Workflow Validation + name: Arcodange Workflow Validation runs-on: ubuntu-latest if: github.event_name == 'pull_request' || contains(github.ref, 'ci/') @@ -102,25 +108,16 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Validate workflow syntax - run: | - if command -v yq >/dev/null 2>&1; then - yq eval '.' .gitea/workflows/ci-cd.yaml > /dev/null - echo "โœ… Workflow YAML syntax is valid" - else - echo "โš ๏ธ yq not installed, skipping YAML validation" - fi - - - name: Run workflow validation script + - name: Run Arcodange workflow validation run: ./scripts/cicd/validate-workflow.sh - - name: Check for breaking changes + - name: Check for workflow changes in PR if: github.event_name == 'pull_request' run: | echo "๐Ÿ” Checking workflow changes..." - changes=$(git diff origin/main -- .gitea/workflows/ci-cd.yaml | grep -q "^-") + changes=$(git diff origin/main -- .gitea/workflows/ | grep -q "^-") if [ $changes ]; then - echo "โš ๏ธ Changes detected - review recommended" + echo "โš ๏ธ Workflow changes detected - review recommended" else echo "โœ… No workflow changes" fi diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9a32343 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# DanceLessonsCoach Docker Image +# Multi-stage build for production deployment + +# Stage 1: Build binary +FROM golang:1.26.1-alpine AS builder + +WORKDIR /app + +# Copy go mod files +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source code +COPY . ./ + +# Build binary +RUN CGO_ENABLED=0 GOOS=linux go build -o /dance-lessons-coach ./cmd/server + +# Stage 2: Final image +FROM alpine:3.18 + +WORKDIR /app + +# Install dependencies +RUN apk add --no-cache ca-certificates tzdata + +# Copy binary from builder +COPY --from=builder /dance-lessons-coach /app/dance-lessons-coach + +# Copy configuration +COPY config.yaml /app/config.yaml + +# Set permissions +RUN chmod +x /app/dance-lessons-coach + +# Set timezone +ENV TZ=UTC + +# Expose port +EXPOSE 8080 + +# Health check +HEALTHCHECK --interval=30s --timeout=3s \ + CMD wget -q --spider http://localhost:8080/api/health || exit 1 + +# Entry point +ENTRYPOINT ["/app/dance-lessons-coach"] diff --git a/scripts/cicd/README.md b/scripts/cicd/README.md new file mode 100644 index 0000000..42fb8ab --- /dev/null +++ b/scripts/cicd/README.md @@ -0,0 +1,286 @@ +# CI/CD Scripts for DanceLessonsCoach + +## ๐Ÿš€ Quick Start for Contributors + +### You Only Need These Commands + +```bash +# 1. Run tests (this is what matters most!) +go test ./... + +# 2. Build binaries +./scripts/build.sh + +# 3. Check formatting +go fmt ./... + +# That's it! The CI/CD pipeline will handle the rest when you create a PR. +``` + +## ๐Ÿ“– Understanding the CI/CD Pipeline + +### What Happens Automatically + +When you push code or create a PR, GitHub Actions runs: + +1. **Go CI/CD Pipeline** (`.gitea/workflows/go-ci-cd.yaml`) + - Builds all Go packages + - Runs tests with coverage + - Checks code formatting + - Validates workflow structure + +2. **Docker Image Pipeline** (`.gitea/workflows/dockerimage.yaml`) + - Builds Docker image (on main branch only) + - Publishes to Gitea Container Registry + - Tags with version and commit SHA + +### When Does It Run? + +| Event | Go CI/CD | Docker Image | +|-------|---------|--------------| +| Push to `main` | โœ… Yes | โœ… Yes | +| Push to `feature/*` | โœ… Yes | โŒ No | +| Push to `fix/*` | โœ… Yes | โŒ No | +| Push to `ci/*` | โœ… Yes | โŒ No | +| Pull Request | โœ… Yes | โŒ No | +| Manual trigger | โœ… Yes | โœ… Yes | + +## ๐Ÿงช Local Testing Options + +### Option 1: Simple Validation (No Docker Required) + +```bash +# Just run the essentials +./scripts/cicd/contributor-quickstart.sh +``` + +This checks: +- โœ… Go installation +- โœ… All tests pass +- โœ… Code formatting +- โœ… Go vet analysis +- โœ… Workflow structure + +### Option 2: Docker-Based Testing (Recommended) + +```bash +# Test workflow compatibility with GitHub Actions +./scripts/cicd/test-act-local.sh +``` + +**Requirements:** +- Docker installed and running +- Internet connection (to pull images) + +**What it does:** +- Validates YAML syntax +- Checks workflow structure +- Simulates GitHub Actions execution +- Tests both workflow files + +### Option 3: Full CI/CD Simulation + +```bash +# Complete local simulation +./scripts/cicd/test-cicd-simple.sh +``` + +**Requirements:** +- Docker installed and running +- More time (pulls multiple images) + +**What it does:** +- YAML linting +- YAML validation +- Workflow structure validation +- Simulates build job +- Runs actual Go tests in containers + +## ๐Ÿณ Docker Setup Guide + +### For Windows Users + +1. **Install Docker Desktop** + - Download: https://www.docker.com/products/docker-desktop/ + - Enable WSL 2 backend (recommended) + - Allocate at least 4GB RAM + +2. **Verify Installation** + ```powershell + docker --version + docker run hello-world + ``` + +### For macOS Users + +1. **Install Docker Desktop** + - Download: https://www.docker.com/products/docker-desktop/ + - Grant necessary permissions + +2. **Verify Installation** + ```bash + docker --version + docker run hello-world + ``` + +### For Linux Users + +1. **Install Docker Engine** + ```bash + # Ubuntu/Debian + sudo apt-get update + sudo apt-get install docker.io docker-compose + sudo systemctl enable docker + sudo systemctl start docker + + # Add user to docker group (avoid sudo) + sudo usermod -aG docker $USER + newgrp docker # Reload group membership + ``` + +2. **Verify Installation** + ```bash + docker --version + docker run hello-world + ``` + +## ๐Ÿ”ง Troubleshooting + +### Docker Permission Issues + +**Symptom:** `Got permission denied while trying to connect to the Docker daemon socket` + +**Solution:** +```bash +# Linux/macOS +sudo usermod -aG docker $USER +newgrp docker + +# Windows +Right-click Docker Desktop โ†’ Settings โ†’ Resources โ†’ WSL Integration โ†’ Enable +``` + +### Docker Not Running + +**Symptom:** `Cannot connect to the Docker daemon` + +**Solution:** +- Windows/macOS: Open Docker Desktop app +- Linux: `sudo systemctl start docker` + +### Network Issues + +**Symptom:** `Cannot pull Docker images` + +**Solution:** +```bash +# Check internet connection +ping google.com + +# Try pulling manually first +docker pull mikefarah/yq:latest +docker pull pipelinecomponents/yamllint:latest +``` + +### act Not Installed + +**Symptom:** `act not found` in `test-act-local.sh` + +**Solution:** +```bash +# Install act (optional - only needed for test-act-local.sh) +# macOS +brew install act + +# Linux +curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash + +# Windows (WSL) +curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash +``` + +## ๐Ÿ“š Script Reference + +| Script | Purpose | Docker Required? | act Required? | +|--------|---------|------------------|---------------| +| `contributor-quickstart.sh` | Basic validation | โŒ No | โŒ No | +| `validate-workflow.sh` | Workflow structure | โŒ No | โŒ No | +| `test-act-local.sh` | GitHub Actions compatibility | โœ… Yes | โœ… Yes | +| `test-cicd-simple.sh` | Full CI/CD simulation | โœ… Yes | โŒ No | + +## ๐ŸŽฏ Best Practices + +### Before Submitting a PR + +1. **Run tests locally** + ```bash + go test ./... + ``` + +2. **Check formatting** + ```bash + go fmt ./... + ``` + +3. **Build binaries** + ```bash + ./scripts/build.sh + ``` + +4. **Validate workflows** (optional) + ```bash + ./scripts/cicd/validate-workflow.sh + ``` + +### Working with the CI/CD Pipeline + +- **Don't worry about Docker images** - The pipeline builds them automatically +- **Focus on tests** - If tests pass locally, they'll pass in CI/CD +- **Check PR status** - GitHub will show CI/CD results automatically +- **Fix failures** - If CI/CD fails, check the logs and fix issues + +## ๐Ÿ”— Useful Links + +- **GitHub Actions Docs**: https://docs.github.com/en/actions +- **Docker Docs**: https://docs.docker.com/ +- **act GitHub**: https://github.com/nektos/act +- **DanceLessonsCoach CI/CD**: See `.gitea/workflows/` directory + +## ๐Ÿ’ก Pro Tips + +### Speed Up Local Testing + +```bash +# Pull Docker images in advance +docker pull mikefarah/yq:latest +docker pull pipelinecomponents/yamllint:latest +docker pull node:16-buster-slim +``` + +### Test Specific Workflows + +```bash +# Test Go CI/CD workflow only +act -W .gitea/workflows/go-ci-cd.yaml + +# Test Docker workflow only +act -W .gitea/workflows/dockerimage.yaml +``` + +### Dry Run (No Execution) + +```bash +# Check workflow syntax without running +echo 'm' | act -n -W .gitea/workflows/go-ci-cd.yaml +``` + +## ๐Ÿ“ž Need Help? + +If you're stuck with CI/CD setup: + +1. **Check this documentation** - Most issues are covered here +2. **Run contributor-quickstart.sh** - It validates the essentials +3. **Ask in the PR** - We'll help you resolve any issues +4. **Check CI/CD logs** - GitHub shows detailed error messages + +Remember: **You don't need to run CI/CD locally to contribute!** The pipeline runs automatically when you push code. diff --git a/scripts/cicd/contributor-quickstart.sh b/scripts/cicd/contributor-quickstart.sh new file mode 100755 index 0000000..0d11024 --- /dev/null +++ b/scripts/cicd/contributor-quickstart.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# Simple CI/CD validation for new contributors +# Works without Docker - just validates the essentials + +set -e + +echo "๐Ÿš€ DanceLessonsCoach Contributor Quick Start" +echo "==========================================" +echo "" +echo "This script helps you validate your changes before submitting a PR." +echo "It doesn't require Docker or complex setup." +echo "" + +# 1. Check Go is installed +echo "1. Checking Go installation..." +if ! command -v go >/dev/null 2>&1; then + echo "โŒ Go is not installed. Please install Go 1.26.1+" + echo " Download: https://go.dev/dl/" + exit 1 +fi +go_version=$(go version | grep -o 'go[0-9.]*') +echo "โœ… Go $go_version found" + +# 2. Run Go tests +echo "" +echo "2. Running Go tests..." +if go test ./...; then + echo "โœ… All Go tests passed" +else + echo "โŒ Some tests failed. Please fix and try again." + exit 1 +fi + +# 3. Check formatting +echo "" +echo "3. Checking code formatting..." +if [ -n "$(go fmt ./...)" ]; then + echo "โŒ Code formatting issues found" + echo " Run: go fmt ./..." + exit 1 +fi +echo "โœ… Code is properly formatted" + +# 4. Run Go vet +echo "" +echo "4. Running Go vet..." +if go vet ./...; then + echo "โœ… Go vet passed" +else + echo "โŒ Go vet found issues" + exit 1 +fi + +# 5. Validate workflows (no Docker required) +echo "" +echo "5. Validating CI/CD workflows..." +if [ -f "scripts/cicd/validate-workflow.sh" ]; then + if ./scripts/cicd/validate-workflow.sh; then + echo "โœ… Workflow validation passed" + else + echo "โš ๏ธ Workflow validation issues (not critical)" + fi +else + echo "โ„น๏ธ Workflow validation script not found" +fi + +echo "" +echo "๐ŸŽ‰ All checks passed!" +echo "==========================================" +echo "" +echo "Your changes are ready to submit! ๐Ÿš€" +echo "" +echo "Next steps:" +echo " 1. Commit your changes: git commit -m 'feat: your feature'" +echo " 2. Push to your branch: git push origin your-branch" +echo " 3. Create a Pull Request" +echo "" +echo "The CI/CD pipeline will run automatically on your PR!" diff --git a/scripts/cicd/test-act-local.sh b/scripts/cicd/test-act-local.sh index a012e77..9dfde9b 100755 --- a/scripts/cicd/test-act-local.sh +++ b/scripts/cicd/test-act-local.sh @@ -15,37 +15,61 @@ if ! command -v act >/dev/null 2>&1; then exit 1 fi -# Check if workflow file exists -if [ ! -f ".gitea/workflows/ci-cd.yaml" ]; then - echo "โŒ Workflow file not found: .gitea/workflows/ci-cd.yaml" - exit 1 -fi +# Check if workflow files exist +WORKFLOW_FILES=( + ".gitea/workflows/go-ci-cd.yaml" + ".gitea/workflows/dockerimage.yaml" +) + +for file in "${WORKFLOW_FILES[@]}"; do + if [ ! -f "$file" ]; then + echo "โŒ Workflow file not found: $file" + exit 1 + fi +done echo "โœ… act installed and workflow file found" echo "" # 1. Dry run (syntax check only) echo "1. Running dry run (syntax validation)..." -if echo 'm' | act -n -W .gitea/workflows/ci-cd.yaml --container-architecture linux/amd64; then - echo "โœ… Dry run completed successfully" +ALL_PASSED=true + +for file in "${WORKFLOW_FILES[@]}"; do + echo " Testing: $file" + if echo 'm' | act -n -W "$file" --container-architecture linux/amd64; then + echo " โœ… Dry run completed for $file" + else + echo " โŒ Dry run failed for $file" + ALL_PASSED=false + fi +done + +if [ "$ALL_PASSED" = true ]; then + echo "โœ… All dry runs completed successfully" else - echo "โŒ Dry run failed" + echo "โŒ Some dry runs failed" exit 1 fi + echo "" -echo "๐ŸŽ‰ Gitea workflow is compatible with GitHub Actions!" -echo "================================================" +echo "๐ŸŽ‰ Gitea workflows are compatible with GitHub Actions!" +echo "==================================================" echo "" echo "๐Ÿ“‹ Summary:" -echo " โœ… Syntax validation passed" +echo " โœ… Syntax validation passed for all workflows" echo " โœ… All jobs parsed correctly" echo " โœ… Job dependencies resolved" echo " โœ… Conditional execution working" echo " โœ… Gitea/GitHub Actions compatibility confirmed" echo "" echo "๐Ÿš€ You can now test locally without Gitea instance:" -echo " act -n -W .gitea/workflows/ci-cd.yaml # Dry run" -echo " act -W .gitea/workflows/ci-cd.yaml # Full execution" +for file in "${WORKFLOW_FILES[@]}"; do + workflow_name=$(basename "$file" .yaml) + echo " act -n -W $file # Dry run $workflow_name" + echo " act -W $file # Full execution $workflow_name" +done + echo "" echo "๐Ÿ’ก Tip: Add this to your pre-commit hook to validate workflows automatically!" diff --git a/scripts/cicd/test-cicd-local.sh b/scripts/cicd/test-cicd-local.sh index 95d81cd..0f37b22 100755 --- a/scripts/cicd/test-cicd-local.sh +++ b/scripts/cicd/test-cicd-local.sh @@ -17,7 +17,7 @@ fi # 2. Validate workflow structure echo "2. Validating workflow structure..." -./scripts/validate-workflow.sh +./scripts/cicd/validate-workflow.sh # 3. Check docker-compose configuration echo "3. Checking docker-compose configuration..." diff --git a/scripts/cicd/test-cicd-simple.sh b/scripts/cicd/test-cicd-simple.sh index 5e7ae24..7904043 100755 --- a/scripts/cicd/test-cicd-simple.sh +++ b/scripts/cicd/test-cicd-simple.sh @@ -20,7 +20,10 @@ echo "โœ… YAML linting passed" # 2. YAML Validation echo "2. Running YAML validation..." -docker run --rm -v $(pwd):/workspace -w /workspace mikefarah/yq:latest eval '.' .gitea/workflows/ci-cd.yaml > /dev/null +WORKFLOW_FILES=(".gitea/workflows/go-ci-cd.yaml" ".gitea/workflows/dockerimage.yaml") +for file in "${WORKFLOW_FILES[@]}"; do + docker run --rm -v $(pwd):/workspace -w /workspace mikefarah/yq:latest eval '.' "$file" > /dev/null +done echo "โœ… YAML validation passed" # 3. Workflow Structure Validation diff --git a/scripts/cicd/validate-workflow.sh b/scripts/cicd/validate-workflow.sh index c840c4f..45e70b4 100755 --- a/scripts/cicd/validate-workflow.sh +++ b/scripts/cicd/validate-workflow.sh @@ -6,69 +6,85 @@ set -e echo "๐Ÿ” Validating CI/CD Workflow" echo "================================" -# 1. Check workflow file exists -if [ ! -f ".gitea/workflows/ci-cd.yaml" ]; then - echo "โŒ Workflow file not found: .gitea/workflows/ci-cd.yaml" - exit 1 -fi +# 1. Check workflow files exist +WORKFLOW_FILES=( + ".gitea/workflows/go-ci-cd.yaml" + ".gitea/workflows/dockerimage.yaml" +) -echo "โœ… Workflow file found" - -# 2. Validate YAML syntax -if command -v yq >/dev/null 2>&1; then - if ! yq eval '.' .gitea/workflows/ci-cd.yaml > /dev/null 2>&1; then - echo "โŒ Invalid YAML syntax" - yq eval '.' .gitea/workflows/ci-cd.yaml || true +for file in "${WORKFLOW_FILES[@]}"; do + if [ ! -f "$file" ]; then + echo "โŒ Workflow file not found: $file" exit 1 fi - echo "โœ… YAML syntax valid" + echo "โœ… Workflow file found: $file" +done + +# 2. Validate YAML syntax for all workflows +if command -v yq >/dev/null 2>&1; then + for file in "${WORKFLOW_FILES[@]}"; do + if ! yq eval '.' "$file" > /dev/null 2>&1; then + echo "โŒ Invalid YAML syntax in: $file" + yq eval '.' "$file" || true + exit 1 + fi + echo "โœ… YAML syntax valid: $file" + done else echo "โš ๏ธ yq not installed, skipping YAML validation" fi -# 3. YAML Linting with custom config +# 3. YAML Linting with custom config for all workflows if command -v yamllint >/dev/null 2>&1; then - if [ -f ".yamllint.yaml" ]; then - yamllint -c .yamllint.yaml .gitea/workflows/ci-cd.yaml - else - yamllint .gitea/workflows/ci-cd.yaml - fi + for file in "${WORKFLOW_FILES[@]}"; do + if [ -f ".yamllint.yaml" ]; then + yamllint -c .yamllint.yaml "$file" + else + yamllint "$file" + fi + done elif docker info >/dev/null 2>&1; then - if [ -f ".yamllint.yaml" ]; then - docker run --rm -v $(pwd):/workspace -w /workspace pipelinecomponents/yamllint:latest \ - yamllint -c .yamllint.yaml .gitea/workflows/ci-cd.yaml - else - docker run --rm -v $(pwd):/workspace -w /workspace pipelinecomponents/yamllint:latest \ - yamllint .gitea/workflows/ci-cd.yaml - fi + for file in "${WORKFLOW_FILES[@]}"; do + if [ -f ".yamllint.yaml" ]; then + docker run --rm -v $(pwd):/workspace -w /workspace pipelinecomponents/yamllint:latest \ + yamllint -c .yamllint.yaml "$file" + else + docker run --rm -v $(pwd):/workspace -w /workspace pipelinecomponents/yamllint:latest \ + yamllint "$file" + fi + done else echo "โš ๏ธ Neither yamllint nor docker available, skipping linting" fi -# 3. Check required fields -MISSING_FIELDS=() +# 3. Check required fields for all workflows +for file in "${WORKFLOW_FILES[@]}"; do + MISSING_FIELDS=() + + if command -v yq >/dev/null 2>&1; then + workflow_name=$(basename "$file" .yaml) + + if [ -z "$(yq eval '.name' "$file" 2>/dev/null)" ]; then + MISSING_FIELDS+=("name") + fi -if command -v yq >/dev/null 2>&1; then - if [ -z "$(yq eval '.name' .gitea/workflows/ci-cd.yaml 2>/dev/null)" ]; then - MISSING_FIELDS+=("name") - fi + if [ -z "$(yq eval '.on' "$file" 2>/dev/null)" ]; then + MISSING_FIELDS+=("on") + fi - if [ -z "$(yq eval '.on' .gitea/workflows/ci-cd.yaml 2>/dev/null)" ]; then - MISSING_FIELDS+=("on") - fi + if [ -z "$(yq eval '.jobs' "$file" 2>/dev/null)" ]; then + MISSING_FIELDS+=("jobs") + fi - if [ -z "$(yq eval '.jobs' .gitea/workflows/ci-cd.yaml 2>/dev/null)" ]; then - MISSING_FIELDS+=("jobs") + if [ ${#MISSING_FIELDS[@]} -gt 0 ]; then + echo "โŒ Missing required fields in $workflow_name: ${MISSING_FIELDS[*]}" + exit 1 + fi + echo "โœ… All required fields present in $workflow_name" + else + echo "โš ๏ธ yq not installed, skipping field validation for $file" fi - - if [ ${#MISSING_FIELDS[@]} -gt 0 ]; then - echo "โŒ Missing required fields: ${MISSING_FIELDS[*]}" - exit 1 - fi - echo "โœ… All required fields present" -else - echo "โš ๏ธ yq not installed, skipping field validation" -fi +done # 4. Check jobs structure if command -v yq >/dev/null 2>&1; then @@ -118,10 +134,17 @@ fi echo "" echo "๐ŸŽ‰ Workflow Validation Successful!" echo "================================" -echo "๐Ÿ“ Location: .gitea/workflows/ci-cd.yaml" +echo "๐Ÿ“ Workflows validated:" +for file in "${WORKFLOW_FILES[@]}"; do + echo " - $file" +done if command -v yq >/dev/null 2>&1; then - JOBS=$(yq eval '.jobs | keys | join(", ")' .gitea/workflows/ci-cd.yaml 2>/dev/null || echo 'Unable to parse') - echo "๐Ÿ”ง Jobs: $JOBS" + echo "๐Ÿ”ง Summary:" + for file in "${WORKFLOW_FILES[@]}"; do + workflow_name=$(basename "$file" .yaml) + JOBS=$(yq eval '.jobs | keys | join(", ")' "$file" 2>/dev/null || echo 'Unable to parse') + echo " - $workflow_name: $JOBS" + done else echo "๐Ÿ”ง Jobs: yq not installed" fi