Skip to content

Create Deploy Preview #18

Create Deploy Preview

Create Deploy Preview #18

# Warning: This has access to secrets and checks out untrusted code. Modify with caution
# This uses pull_request/workflow_run instead of pull_request_target so it needs to be approved
name: Create Deploy Preview
on:
workflow_run:
workflows: New Pull Request
types: completed
jobs:
comment:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Find PR number
id: number
run: |
number=$(curl -s ${{ github.event.workflow_run.jobs_url }} |
jq -r '.jobs[0].steps | map(select(.number == 2)) | first.name')
echo "number=$number" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}
- uses: superfly/flyctl-actions/setup-flyctl@v1
- name: Deploy preview app
run: |
app_name="setcookie-staging-${{ steps.number.outputs.number }}"
flyctl apps list | grep "$app_name" || flyctl apps create "$app_name"
flyctl deploy --remote-only -a "$app_name" -e APP_ENV=staging
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- name: Find Comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ steps.number.outputs.number }}
comment-author: 'github-actions[bot]'
body-includes: Your deploy preview
- name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ steps.number.outputs.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: >
Your deploy preview can be found at https://setcookie-staging-${{ steps.number.outputs.number }}.fly.dev.