14 setup preview for pull request builds in GitHub actions azure ws #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pull Request Preview | |
on: | |
pull_request: | |
types: [opened, synchronize, closed] | |
branches: | |
- main | |
paths: | |
- "frontend/**" | |
workflow_dispatch: | |
env: | |
NEXT_PUBLIC_VIBES_BACKEND_URL: https://vibes-backend-app-preview-pr-${{ github.event.pull_request.number }}.azurewebsites.net | |
FRONTEND_URL: https://vibes-frontend-app-preview-pr-${{ github.event.pull_request.number }}.azurewebsites.net | |
jobs: | |
create-deployment-preview: | |
if: github.event.action == 'opened' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./frontend | |
steps: | |
- uses: actions/checkout@master | |
- name: Initial Deployment Preview Comment | |
uses: peter-evans/create-or-update-comment@v1.4.5 | |
id: pr-preview-comment | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
### Building Deployment Preview.. | |
A preview of this Pull Request is being created. Hold tight while it's building ⚒️ | |
This comment will be automatically updated when the preview is ready. | |
- name: Set up Node.js version | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 18.x | |
- name: 'Install ci dependencies' | |
run: yarn --frozen-lockfile --ignore-scripts | |
- name: 'Build with Next.js' | |
run: | | |
yarn build | |
mv ./build/static ./build/standalone/build | |
mv ./public ./build/standalone | |
env: | |
NEXT_PUBLIC_VIBES_BACKEND_URL: ${{ env.NEXT_PUBLIC_VIBES_BACKEND_URL }} | |
- name: Azure Login | |
uses: Azure/login@v1.4.3 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Create PR Deployment Slot | |
uses: Azure/cli@v1 | |
with: | |
inlineScript: az webapp deployment slot create --name vibes-frontend-app --resource-group vibes-dev --slot preview-pr-${{ github.event.pull_request.number }} | |
- name: Update PR Preview Comment | |
uses: peter-evans/create-or-update-comment@v1.4.5 | |
with: | |
comment-id: ${{ steps.pr-preview-comment.outputs.comment-id }} | |
edit-mode: replace | |
body: | | |
### Deployment Preview | |
😎 Preview this PR: ${{ env.FRONTEND_URL }} | |
🧑🏼💻 Commit SHA: ${{ github.sha }} | |
reactions: "rocket" | |
- name: Deploy frontend to Azure Web App | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: "vibes-frontend-app" | |
slot-name: preview-pr-${{ github.event.pull_request.number }} | |
package: ./frontend | |
update-deployment-preview: | |
if: github.event.action == 'synchronize' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./frontend | |
steps: | |
- uses: actions/checkout@master | |
- name: Find PR Preview Comment | |
uses: peter-evans/find-comment@v1 | |
id: deploy-preview-comment | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: "github-actions[bot]" | |
body-includes: Deployment Preview | |
- name: Update PR Preview Comment | |
if: steps.deploy-preview-comment.outputs.comment-id != '' | |
uses: peter-evans/create-or-update-comment@v1.4.5 | |
with: | |
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }} | |
edit-mode: replace | |
body: | | |
### Building Deployment Preview.. | |
The Pull Request preview is being updated. Hold tight while it's building ⚒️ | |
This comment will be automatically updated when the new version is ready. | |
- name: Set up Node.js version | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 18.x | |
- name: 'Install ci dependencies' | |
run: yarn --frozen-lockfile --ignore-scripts | |
- name: 'Build with Next.js' | |
run: | | |
yarn build | |
mv ./build/static ./build/standalone/build | |
mv ./public ./build/standalone | |
env: | |
NEXT_PUBLIC_VIBES_BACKEND_URL: ${{ env.NEXT_PUBLIC_VIBES_BACKEND_URL }} | |
- name: Azure Login | |
uses: Azure/login@v1.4.3 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Deploy frontend to Azure Web App | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: "vibes-frontend-app" | |
slot-name: preview-pr-${{ github.event.pull_request.number }} | |
package: ./frontend | |
- name: Update PR Preview Comment | |
uses: peter-evans/create-or-update-comment@v1.4.5 | |
with: | |
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }} | |
edit-mode: replace | |
body: | | |
### Deployment Preview | |
😎 Preview this PR: ${{ env.FRONTEND_URL }} | |
🧑🏼💻 Commit SHA: ${{ github.sha }} | |
delete-deployment-preview: | |
if: github.event.action == 'closed' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
- name: Azure Login | |
uses: Azure/login@v1.4.3 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Delete PR Deployment Slot | |
uses: Azure/cli@v1 | |
with: | |
inlineScript: | | |
az webapp deployment slot delete --name vibes-frontend-app --resource-group vibes-dev --slot preview-pr-${{ github.event.pull_request.number }} | |
- name: Find PR Preview Comment | |
uses: peter-evans/find-comment@v1 | |
id: deploy-preview-comment | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: "github-actions[bot]" | |
body-includes: Deployment Preview | |
- name: Update PR Preview Comment | |
if: steps.deploy-preview-comment.outputs.comment-id != '' | |
uses: peter-evans/create-or-update-comment@v1.4.5 | |
with: | |
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }} | |
edit-mode: replace | |
body: | | |
### Deployment Preview | |
🏁 This PR has been closed. No deployment preview is available. | |
reactions: "hooray" |