Skip to content

Open-source status page, incident response and uptime monitoring

improve fly pr action (#1919)

Thibault Le Ouay6a258b4ae96a
diff --git a/.github/workflows/api-preview.yml b/.github/workflows/api-preview.yml
index 98285c2bd..3ab6fd90d 100644
--- a/.github/workflows/api-preview.yml
+++ b/.github/workflows/api-preview.yml
@@ -1,63 +1,80 @@
name: Fly Preview API server
on:
- pull_request:
- types: [opened, reopened, synchronize, closed]
- paths:
- - "apps/server/**"
- - "packages/db/**"
- - "packages/emails/**"
- - "packages/regions/**"
- - "packages/tsconfig/**"
- - "packages/utils/**"
- - "packages/upstash/**"
- - "packages/proto/**"
+ workflow_dispatch:
+ inputs:
+ action:
+ description: "Action to perform"
+ required: true
+ type: choice
+ options:
+ - deploy
+ - destroy
+
+permissions:
+ contents: read
+ deployments: write
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- # Set these to your Fly.io organization and preferred region.
FLY_REGION: ams
FLY_ORG: openstatus
+ APP_NAME: openstatus-api-preview-${{ github.ref_name }}
jobs:
- review_app:
+ deploy:
+ if: ${{ github.event.inputs.action == 'deploy' }}
runs-on: depot-ubuntu-24.04-4
timeout-minutes: 15
- outputs:
- url: ${{ steps.deploy.outputs.url }}
- # Only run one deployment at a time per PR.
concurrency:
- group: pr-${{ github.event.number }}
-
- # Deploying apps with this "review" environment allows the URL for the app to be displayed in the PR UI.
- # Feel free to change the name of this environment.
+ group: api-preview-${{ github.ref_name }}
environment:
- name: pr-${{ github.event.number }} # The script in the `deploy` sets the URL output for each review app.
- url: ${{ steps.deploy.outputs.url }}
+ name: api-preview-${{ github.ref_name }}
+ url: https://${{ env.APP_NAME }}.fly.dev
steps:
- name: Get code
uses: actions/checkout@v4
- - name: Deploy PR app to Fly.io
- id: deploy
- uses: superfly/[email protected]
- with:
- config: apps/server/fly.toml
- vmsize: shared-cpu-1x
- name: openstatus-api-pr-${{ github.event.number }}
- secrets: |
- DATABASE_URL=${{ secrets.STAGING_DB_URL }}
- DATABASE_AUTH_TOKEN=${{ env.STAGING_DB_AUTH_TOKEN }}
- RESEND_API_KEY=${{ secrets.STAGING_RESEND_API_KEY }}
- UPSTASH_REDIS_REST_URL=test
- UPSTASH_REDIS_REST_TOKEN=test
- GCP_PROJECT_ID=test
- NEXT_PUBLIC_OPENPANEL_CLIENT_ID=test
- OPENPANEL_CLIENT_SECRET=test
+ - name: Setup Fly.io CLI
+ uses: superfly/flyctl-actions/setup-flyctl@master
+
+ - name: Create app if not exists
+ run: flyctl apps create ${{ env.APP_NAME }} --org ${{ env.FLY_ORG }} || true
+
+ - name: Set secrets
+ run: |
+ flyctl secrets set \
+ DATABASE_URL="${{ secrets.STAGING_DB_URL }}" \
+ DATABASE_AUTH_TOKEN="${{ secrets.STAGING_DB_AUTH_TOKEN }}" \
+ RESEND_API_KEY="${{ secrets.STAGING_RESEND_API_KEY }}" \
+ UPSTASH_REDIS_REST_URL=test \
+ UPSTASH_REDIS_REST_TOKEN=test \
+ GCP_PROJECT_ID=test \
+ NEXT_PUBLIC_OPENPANEL_CLIENT_ID=test \
+ OPENPANEL_CLIENT_SECRET=test \
+ --app ${{ env.APP_NAME }}
+
+ - name: Deploy to Fly.io
+ run: |
+ flyctl deploy \
+ --config apps/server/fly.toml \
+ --app ${{ env.APP_NAME }} \
+ --region ${{ env.FLY_REGION }} \
+ --vm-size shared-cpu-1x \
+ --yes
+
+ destroy:
+ if: ${{ github.event.inputs.action == 'destroy' }}
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ steps:
+ - name: Setup Fly.io CLI
+ uses: superfly/flyctl-actions/setup-flyctl@master
+
+ - name: Destroy app
+ run: flyctl apps destroy ${{ env.APP_NAME }} --yes || true
- name: Clean up GitHub environment
uses: strumwolf/delete-deployment-environment@v2
- if: ${{ github.event.action == 'closed' }}
with:
- # ⚠️ The provided token needs permission for admin write:org
token: ${{ secrets.GITHUB_TOKEN }}
- environment: pr-${{ github.event.number }}
+ environment: api-preview-${{ github.ref_name }}
diff --git a/.github/workflows/workflow-preview.yml b/.github/workflows/workflow-preview.yml
index 6e35d5193..69d03a13a 100644
--- a/.github/workflows/workflow-preview.yml
+++ b/.github/workflows/workflow-preview.yml
@@ -1,59 +1,78 @@
name: Fly Preview Workflows
on:
- pull_request:
- types: [opened, reopened, synchronize, closed]
- paths:
- - "apps/workflows/**"
- - "packages/db/**"
- - "packages/emails/**"
- - "packages/utils/**"
- - "packages/notifications/**"
- - "packages/tsconfig/**"
+ workflow_dispatch:
+ inputs:
+ action:
+ description: "Action to perform"
+ required: true
+ type: choice
+ options:
+ - deploy
+ - destroy
+
+permissions:
+ contents: read
+ deployments: write
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- # Set these to your Fly.io organization and preferred region.
FLY_REGION: ams
FLY_ORG: openstatus
+ APP_NAME: openstatus-workflows-preview-${{ github.ref_name }}
jobs:
- review_app:
+ deploy:
+ if: ${{ github.event.inputs.action == 'deploy' }}
runs-on: ubuntu-latest
timeout-minutes: 15
- outputs:
- url: ${{ steps.deploy.outputs.url }}
- # Only run one deployment at a time per PR.
concurrency:
- group: pr-${{ github.event.number }}
-
- # Deploying apps with this "review" environment allows the URL for the app to be displayed in the PR UI.
- # Feel free to change the name of this environment.
+ group: workflows-preview-${{ github.ref_name }}
environment:
- name: pr-${{ github.event.number }} # The script in the `deploy` sets the URL output for each review app.
- url: ${{ steps.deploy.outputs.url }}
+ name: workflows-preview-${{ github.ref_name }}
+ url: https://${{ env.APP_NAME }}.fly.dev
steps:
- name: Get code
uses: actions/checkout@v4
- - name: Deploy PR app to Fly.io
- id: deploy
- uses: superfly/[email protected]
- with:
- config: apps/workflows/fly.toml
- vmsize: shared-cpu-1x
- name: openstatus-workflows-pr-${{ github.event.number }}
- secrets: |
- DATABASE_URL=${{ secrets.STAGING_DB_URL }}
- DATABASE_AUTH_TOKEN=${{ env.STAGING_DB_AUTH_TOKEN }}
- RESEND_API_KEY=${{ secrets.STAGING_RESEND_API_KEY }}
- UPSTASH_REDIS_REST_URL=test
- UPSTASH_REDIS_REST_TOKEN=test
- GCP_PROJECT_ID=test
+ - name: Setup Fly.io CLI
+ uses: superfly/flyctl-actions/setup-flyctl@master
+
+ - name: Create app if not exists
+ run: flyctl apps create ${{ env.APP_NAME }} --org ${{ env.FLY_ORG }} || true
+
+ - name: Set secrets
+ run: |
+ flyctl secrets set \
+ DATABASE_URL="${{ secrets.STAGING_DB_URL }}" \
+ DATABASE_AUTH_TOKEN="${{ secrets.STAGING_DB_AUTH_TOKEN }}" \
+ RESEND_API_KEY="${{ secrets.STAGING_RESEND_API_KEY }}" \
+ UPSTASH_REDIS_REST_URL=test \
+ UPSTASH_REDIS_REST_TOKEN=test \
+ GCP_PROJECT_ID=test \
+ --app ${{ env.APP_NAME }}
+
+ - name: Deploy to Fly.io
+ run: |
+ flyctl deploy \
+ --config apps/workflows/fly.toml \
+ --app ${{ env.APP_NAME }} \
+ --region ${{ env.FLY_REGION }} \
+ --vm-size shared-cpu-1x \
+ --yes
+
+ destroy:
+ if: ${{ github.event.inputs.action == 'destroy' }}
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ steps:
+ - name: Setup Fly.io CLI
+ uses: superfly/flyctl-actions/setup-flyctl@master
+
+ - name: Destroy app
+ run: flyctl apps destroy ${{ env.APP_NAME }} --yes || true
- name: Clean up GitHub environment
uses: strumwolf/delete-deployment-environment@v2
- if: ${{ github.event.action == 'closed' }}
with:
- # ⚠️ The provided token needs permission for admin write:org
token: ${{ secrets.GITHUB_TOKEN }}
- environment: pr-${{ github.event.number }}
+ environment: workflows-preview-${{ github.ref_name }}