Yesterday, I tried to build a review app to migrate a Next.js app from Vercel to Fly. So, I configured a GitHub Action to handle it, and it works very well. Here is an example:
name: Staging App
on:
pull_request:
types: [opened, reopened, synchronize, closed]
env:
FLY_API_TOKEN: ${{ secrets.FLY_AUTH_TOKEN }}
FLY_REGION: gru
FLY_ORG: personal
NEXT_PUBLIC_API_URL: https://myurl.com/api
jobs:
staging_app:
runs-on: ubuntu-latest
# Only run one deployment at a time per PR.
concurrency:
group: app-name-${{ github.event.pull_request.number }}
# Create a GitHub deployment environment per staging app so it shows up
# in the pull request UI.
environment:
name: app-name-${{ github.event.pull_request.number }}
url: ${{ steps.deploy.outputs.url }}
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Running tests (almost easy...)
run: pnpm test
- name: Deploy
id: deploy
uses: superfly/fly-pr-review-apps@1.0.0
with:
app-name: app-name-${{ github.event.pull_request.number }}
- name: Clean up GitHub environment
uses: strumwolf/delete-deployment-environment@v2
if: ${{ github.event.action == 'closed' }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
environment: app-name-${{ github.event.pull_request.number }}
That’s easy, and we can save money per seat in my team, and everyone can deploy things and see what happens. It’s easy to have a trunk-based development workflow in our team at AgendFlow.
Next, I will try to do the same with a Phoenix app, and I will return here to share.