All snippets

GitHub Action file to deploy on Fly.io with production and staging environments

Jun 18, 2020·1 min read

.github/workflows/fly-deploy.yml

# Name of the workflow - appears in GitHub Actions UI
name: Fly Deploy with Quality Checks

# Trigger configuration - when should this workflow run
on:
  push:
    branches:
      - main
  # Optional: You might want to run this on pull requests too
  pull_request:
    branches:
      - main

# Define the jobs and their steps
jobs:
  quality-checks:
    name: Quality Checks
    runs-on: ubuntu-latest
    steps:
      # Check out the repository code
      - uses: actions/checkout@v4

      # Setup Bun with caching for faster installations
      - uses: oven-sh/setup-bun@v1
        with:
          bun-version: latest

      # Install dependencies with cache
      - name: Install Dependencies
        run: bun install

      # Run ESLint for code quality checks
      - name: Run ESLint
        run: bun lint

      # Run Prettier for code formatting
      - name: Run Prettier
        run: bun format

      # Run TypeScript type checking
      - name: Run Type Check
        run: bun ts:check

  deploy:
    name: Deploy to Fly.io
    runs-on: ubuntu-latest
    # Only run deploy job if quality checks pass and we're on main branch
    needs: quality-checks
    if: github.ref == 'refs/heads/main' && github.event_name == 'push'
    concurrency: deploy-group

    steps:
      - uses: actions/checkout@v4

      # Setup Fly.io CLI
      - uses: superfly/flyctl-actions/setup-flyctl@master

      # Deploy to Fly.io
      - name: Deploy to Fly.io
        run: flyctl deploy --remote-only
        env:
          FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}