Implement Preview Apps for Pull Requests
mainYou can orchestrate per-PR app previews using the deploy_pr_preview: "true" input. This workflow typically involves:
- On Pull Request: Deploy the app with
deploy_pr_preview: "true". If successful, post thelive_urlas a comment. If it fails, post thebuild_logsanddeploy_logs. - On PR Closed/Merged: Use the
deleteaction withfrom_pr_preview: "true"to clean up the preview app.
# Workflow to deploy preview
name: App Platform Preview
on:
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Deploy the app
id: deploy
uses: digitalocean/app_action/deploy@v2
with:
deploy_pr_preview: "true"
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
# ... (logic to post comment with ${{ fromJson(steps.deploy.outputs.app).live_url }})
# Workflow to delete preview
name: Delete Preview
on:
pull_request:
types: [ closed ]
jobs:
closed:
runs-on: ubuntu-latest
steps:
- name: delete preview app
uses: digitalocean/app_action/delete@v2
with:
from_pr_preview: "true"
ignore_not_found: "true"
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}