-
Notifications
You must be signed in to change notification settings - Fork 2
68 lines (67 loc) · 2.35 KB
/
preview.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Preview Deploy
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
push:
branches-ignore:
- master
pull_request:
types: [opened]
jobs:
preview-deploy:
runs-on: ubuntu-latest
permissions:
deployments: write
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: chrnorm/deployment-action@v2
name: Create GitHub deployment
id: deployment
with:
token: '${{ github.token }}'
environment: preview
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Install dependencies
run: yarn install
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
id: vercel-deploy
run: echo "url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})" >> $GITHUB_OUTPUT
- name: Update GitHub Deployment Status (success)
if: success()
uses: chrnorm/deployment-status@v2
with:
token: '${{ github.token }}'
environment-url: ${{ steps.vercel-deploy.outputs.url }}
state: 'success'
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
- name: Find Pull Request
if: success()
uses: juliangruber/find-pull-request-action@v1
id: find-pull-request
with:
branch: ${{ github.ref_name }}
- name: write deployment comment (in PR)
if: success() && steps.find-pull-request.outputs.number
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: ${{ steps.find-pull-request.outputs.number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Preview URL: ' + '${{ steps.vercel-deploy.outputs.url }}'
})
- name: Update GitHub Deployment Status (failure)
if: failure()
uses: chrnorm/deployment-status@v2
with:
token: '${{ github.token }}'
state: 'failure'
deployment-id: ${{ steps.deployment.outputs.deployment_id }}