name: Fly Preview API server on: 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 }} FLY_REGION: ams FLY_ORG: openstatus APP_NAME: openstatus-api-preview-${{ github.ref_name }} jobs: deploy: if: ${{ github.event.inputs.action == 'deploy' }} runs-on: depot-ubuntu-24.04-4 timeout-minutes: 15 concurrency: group: api-preview-${{ github.ref_name }} environment: name: api-preview-${{ github.ref_name }} url: https://${{ env.APP_NAME }}.fly.dev steps: - name: Get code uses: actions/checkout@v6 - 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 with: token: ${{ secrets.GITHUB_TOKEN }} environment: api-preview-${{ github.ref_name }}