Deploy Astro on Netlify with GitHub Actions

🚀 Astro 🌐 Netlify Platform ⚙️ GitHub Actions

Configuration Files

Production-ready configuration files with detailed comments and best practices. Each file works together as a complete deployment solution.
name: Deploy to Netlify

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build

      - name: Deploy to Netlify
        uses: nwtgck/actions-netlify@v2
        with:
          publish-dir: './dist'
          production-branch: main
          github-token: ${{ secrets.GITHUB_TOKEN }}
          deploy-message: 'Deploy from GitHub Actions'
        env:
          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
          NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}

Prerequisites

  • Netlify account (free tier)
  • Astro project with static output
  • GitHub repository
  • Node.js 18+

Deployment Steps

  • 1. Create Netlify account
  • 2. Create new site in Netlify dashboard
  • 3. Get Site ID from Site settings
  • 4. Generate Personal Access Token in User settings
  • 5. Add secrets to GitHub: NETLIFY_AUTH_TOKEN, NETLIFY_SITE_ID
  • 6. Create .github/workflows/deploy.yml
  • 7. Push to deploy
  • 8. Access at your-site.netlify.app

Additional Notes

  • 🚀 Instant cache invalidation
  • 🔀 Deploy previews for PRs
  • 📝 Built-in form handling
  • 🔒 Free SSL certificates
  • 💰 Free: 100GB bandwidth/month
  • ⚠️ Use @astrojs/netlify for SSR