fix: Aggiungi il controllo della formattazione del codice e la valida… #2
This file contains hidden or 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: CI | |
| # Run CI on all pushes and pull requests to ensure code quality | |
| on: | |
| push: | |
| branches: [main, develop] | |
| pull_request: | |
| branches: [main, develop] | |
| env: | |
| ZIG_VERSION: "0.14.0" | |
| jobs: | |
| # Job to check code formatting and linting | |
| format-and-lint: | |
| name: Format and Lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Zig | |
| uses: goto-bus-stop/setup-zig@v2 | |
| with: | |
| version: ${{ env.ZIG_VERSION }} | |
| - name: Check code formatting | |
| shell: bash | |
| run: | | |
| echo "Checking Zig code formatting..." | |
| zig fmt --check src/ | |
| echo "✅ All Zig files are properly formatted" | |
| - name: Validate build.zig | |
| shell: bash | |
| run: | | |
| echo "Validating build.zig syntax..." | |
| zig build --help > /dev/null | |
| echo "✅ build.zig is valid" | |
| # Job to build and test on multiple platforms | |
| build-and-test: | |
| name: Build and Test | |
| needs: format-and-lint | |
| strategy: | |
| fail-fast: false # Continue testing other platforms even if one fails | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| optimize: [Debug, ReleaseFast] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Zig | |
| uses: goto-bus-stop/setup-zig@v2 | |
| with: | |
| version: ${{ env.ZIG_VERSION }} | |
| - name: Print Zig environment info | |
| run: | | |
| echo "Zig version: $(zig version)" | |
| echo "Zig environment:" | |
| zig env | |
| - name: Cache Zig dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/zig | |
| zig-cache | |
| key: ${{ runner.os }}-zig-${{ hashFiles('build.zig', 'build.zig.zon') }} | |
| restore-keys: | | |
| ${{ runner.os }}-zig- | |
| - name: Build project | |
| run: | | |
| echo "Building with optimization: ${{ matrix.optimize }}" | |
| if [ "${{ matrix.optimize }}" = "Debug" ]; then | |
| zig build | |
| else | |
| zig build -Doptimize=ReleaseFast | |
| fi | |
| - name: Run tests | |
| run: | | |
| echo "Running tests..." | |
| zig build test | |
| echo "✅ All tests passed" | |
| - name: Test basic functionality | |
| run: | | |
| echo "Testing basic binary functionality..." | |
| # Determine binary path based on platform | |
| if [ "${{ matrix.platform }}" = "windows" ]; then | |
| BINARY="./zig-out/bin/ziglets.exe" | |
| else | |
| BINARY="./zig-out/bin/ziglets" | |
| fi | |
| echo "Testing help command..." | |
| $BINARY help | |
| echo "Testing hello command..." | |
| $BINARY hello | |
| echo "Testing echo command..." | |
| $BINARY echo "CI test successful" | |
| echo "✅ Basic functionality tests passed" | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ziglets-${{ matrix.platform }}-${{ matrix.optimize }} | |
| path: zig-out/bin/ | |
| retention-days: 3 | |
| # Job to test cross-compilation capabilities | |
| cross-compile: | |
| name: Cross Compilation Test | |
| needs: format-and-lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Zig | |
| uses: goto-bus-stop/setup-zig@v2 | |
| with: | |
| version: ${{ env.ZIG_VERSION }} | |
| - name: Test cross-compilation for multiple targets | |
| run: | | |
| echo "Testing cross-compilation for various targets..." | |
| # Define test targets | |
| TARGETS=( | |
| "x86_64-linux-gnu" | |
| "aarch64-linux-gnu" | |
| "x86_64-windows-gnu" | |
| "x86_64-macos-none" | |
| "aarch64-macos-none" | |
| ) | |
| FAILED_TARGETS=() | |
| for target in "${TARGETS[@]}"; do | |
| echo "Cross-compiling for: $target" | |
| # Clean previous build | |
| rm -rf zig-out | |
| if zig build -Dtarget="$target" -Doptimize=ReleaseFast; then | |
| echo "✅ Successfully cross-compiled for $target" | |
| else | |
| echo "❌ Failed to cross-compile for $target" | |
| FAILED_TARGETS+=("$target") | |
| fi | |
| done | |
| if [ ${#FAILED_TARGETS[@]} -eq 0 ]; then | |
| echo "✅ All cross-compilation tests passed" | |
| else | |
| echo "❌ Cross-compilation failed for: ${FAILED_TARGETS[*]}" | |
| exit 1 | |
| fi | |
| # Job to validate deployment scripts | |
| validate-scripts: | |
| name: Validate Deployment Scripts | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest] | |
| include: | |
| - os: ubuntu-latest | |
| script: scripts/deploy-linux.sh | |
| shell: bash | |
| - os: windows-latest | |
| script: scripts/deploy-windows.ps1 | |
| shell: pwsh | |
| defaults: | |
| run: | |
| shell: ${{ matrix.shell }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Need full history for git tag operations | |
| - name: Setup Zig | |
| uses: goto-bus-stop/setup-zig@v2 | |
| with: | |
| version: ${{ env.ZIG_VERSION }} | |
| - name: Make script executable (Linux) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: chmod +x scripts/deploy-linux.sh | |
| - name: Validate script syntax | |
| run: | | |
| if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then | |
| # Validate bash script syntax | |
| bash -n scripts/deploy-linux.sh | |
| echo "✅ Linux deployment script syntax is valid" | |
| else | |
| # Validate PowerShell script syntax | |
| powershell -Command "& { . '${{ matrix.script }}'; exit }" | |
| echo "✅ Windows deployment script syntax is valid" | |
| fi | |
| - name: Test script help/error handling | |
| run: | | |
| # Test script with invalid parameters to check error handling | |
| if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then | |
| # Test Linux script error handling | |
| if ! ./scripts/deploy-linux.sh invalid-tag 2>/dev/null; then | |
| echo "✅ Linux script properly handles invalid input" | |
| else | |
| echo "❌ Linux script should fail with invalid tag" | |
| exit 1 | |
| fi | |
| else | |
| # Test Windows script error handling | |
| if (& ${{ matrix.script }} -TagName "invalid-tag") 2>$null; then | |
| echo "❌ Windows script should fail with invalid tag" | |
| exit 1 | |
| else { | |
| echo "✅ Windows script properly handles invalid input" | |
| } | |
| fi | |
| # Job to check documentation and project structure | |
| documentation: | |
| name: Documentation Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Check required files exist | |
| run: | | |
| echo "Checking for required project files..." | |
| REQUIRED_FILES=( | |
| "README.md" | |
| "LICENSE" | |
| "build.zig" | |
| "build.zig.zon" | |
| "src/main.zig" | |
| "scripts/deploy-linux.sh" | |
| "scripts/deploy-windows.ps1" | |
| ".github/workflows/ci.yml" | |
| ".github/workflows/release.yml" | |
| ) | |
| MISSING_FILES=() | |
| for file in "${REQUIRED_FILES[@]}"; do | |
| if [ -f "$file" ]; then | |
| echo "✅ $file exists" | |
| else | |
| echo "❌ $file is missing" | |
| MISSING_FILES+=("$file") | |
| fi | |
| done | |
| if [ ${#MISSING_FILES[@]} -eq 0 ]; then | |
| echo "✅ All required files are present" | |
| else | |
| echo "❌ Missing required files: ${MISSING_FILES[*]}" | |
| exit 1 | |
| fi | |
| - name: Validate README.md content | |
| run: | | |
| echo "Validating README.md content..." | |
| # Check for required sections | |
| REQUIRED_SECTIONS=( | |
| "# Ziglets" | |
| "## Purpose" | |
| "## Building" | |
| "## Usage" | |
| ) | |
| for section in "${REQUIRED_SECTIONS[@]}"; do | |
| if grep -q "$section" README.md; then | |
| echo "✅ Found section: $section" | |
| else | |
| echo "❌ Missing section: $section" | |
| exit 1 | |
| fi | |
| done | |
| echo "✅ README.md contains all required sections" | |
| - name: Check version consistency | |
| run: | | |
| echo "Checking version consistency across files..." | |
| # Extract version from build.zig.zon | |
| ZON_VERSION=$(grep -o '"0\.[0-9]\+\.[0-9]\+"' build.zig.zon | tr -d '"') | |
| echo "Version in build.zig.zon: $ZON_VERSION" | |
| # Extract version from build.zig | |
| BUILD_VERSION=$(grep -o '0\.[0-9]\+\.[0-9]\+' build.zig) | |
| echo "Version in build.zig: $BUILD_VERSION" | |
| if [ "$ZON_VERSION" = "$BUILD_VERSION" ]; then | |
| echo "✅ Version consistency check passed" | |
| else | |
| echo "❌ Version mismatch between build.zig.zon and build.zig" | |
| exit 1 | |
| fi | |
| # Summary job that depends on all other jobs | |
| ci-summary: | |
| name: CI Summary | |
| runs-on: ubuntu-latest | |
| needs: | |
| [ | |
| format-and-lint, | |
| build-and-test, | |
| cross-compile, | |
| validate-scripts, | |
| documentation, | |
| ] | |
| if: always() # Run even if some jobs fail | |
| steps: | |
| - name: Check CI results | |
| run: | | |
| echo "=== CI Summary ===" | |
| echo "Format and Lint: ${{ needs.format-and-lint.result }}" | |
| echo "Build and Test: ${{ needs.build-and-test.result }}" | |
| echo "Cross Compile: ${{ needs.cross-compile.result }}" | |
| echo "Validate Scripts: ${{ needs.validate-scripts.result }}" | |
| echo "Documentation: ${{ needs.documentation.result }}" | |
| # Check if any critical jobs failed | |
| if [ "${{ needs.format-and-lint.result }}" != "success" ] || \ | |
| [ "${{ needs.build-and-test.result }}" != "success" ] || \ | |
| [ "${{ needs.cross-compile.result }}" != "success" ]; then | |
| echo "❌ CI failed - critical issues detected" | |
| exit 1 | |
| else | |
| echo "✅ CI passed - all checks successful" | |
| fi |