Refactor NGINX template validation workflow to improve configuration … #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: Validate NGINX templates | ||
| on: | ||
| push: | ||
| paths: | ||
| - 'templates/**' | ||
| - '.github/**' | ||
| pull_request: | ||
| paths: | ||
| - 'templates/**' | ||
| - '.github/**' | ||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Validate templates with nginx container | ||
| uses: addnab/docker-run-action@v3 | ||
| with: | ||
| image: nginx:stable | ||
| options: --rm -v ${{ github.workspace }}:/workspace:ro | ||
| run: | | ||
| set -eux | ||
| echo "Workspace mounted:" | ||
| ls -la /workspace || true | ||
| # Create a temporary config directory for testing | ||
| tmpdir=/tmp/nginx-test | ||
| rm -rf "$tmpdir" | ||
| mkdir -p "$tmpdir/conf.d" | ||
| # Copy only site templates that contain server blocks (naive filter) | ||
| # This expects templates/sites/*.template to contain full server blocks. | ||
| for f in /workspace/templates/sites/*.template; do | ||
| [ -e "$f" ] || continue | ||
| echo "# from $f" > "$tmpdir/conf.d/$(basename "$f" .template).conf" | ||
| # Try to strip any top-level directives like 'worker_processes' if present. | ||
| sed '/^[[:space:]]*worker_processes\b/Id; p' "$f" >> "$tmpdir/conf.d/$(basename "$f" .template).conf" | ||
| done | ||
| # Create a minimal main config with proper contexts only | ||
| cat > "$tmpdir/nginx.conf" <<'EOF' | ||
| events { worker_connections 1024; } | ||
| http { | ||
| include /etc/nginx/mime.types; | ||
| default_type application/octet-stream; | ||
| include /tmp/nginx-test/conf.d/*.conf; | ||
| } | ||
| EOF | ||
| # Show what we'll test | ||
| sed -n '1,200p' "$tmpdir/nginx.conf" || true | ||
| ls -la "$tmpdir/conf.d" || true | ||
| nginx -t -c "$tmpdir/nginx.conf" | ||