Skip to content

Refactor NGINX template validation workflow to improve configuration … #2

Refactor NGINX template validation workflow to improve configuration …

Refactor NGINX template validation workflow to improve configuration … #2

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; }

Check failure on line 44 in .github/workflows/validate-templates.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/validate-templates.yml

Invalid workflow file

You have an error in your yaml syntax on line 44
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"