-
Notifications
You must be signed in to change notification settings - Fork 288
77 lines (72 loc) · 2.69 KB
/
preview.yml
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
69
70
71
72
73
74
75
76
77
name: preview
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
workflow_dispatch:
pull_request:
types: [ready_for_review]
permissions:
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number || github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
preview:
if: |
github.event_name == 'workflow_dispatch' ||
(
github.actor != 'dependabot[bot]' &&
(
github.event.pull_request ||
(
github.event.issue.pull_request &&
contains(github.event.comment.body, '/create-preview')
)
)
)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.issue.pull_request && format('refs/pull/{0}/merge', github.event.issue.number) || '' }}
- name: Prepare Yarn
uses: ./.github/actions/prepare/
- name: Prepare build
run: yarn prepare
shell: bash
- name: Generate API
run: yarn generate:api
shell: bash
- name: Build
run: yarn build
# Convert to Vercel project and upload
- name: Install Vercel CLI
run: npm install --global vercel@latest
- 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
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} > vercel_output.txt
# Set the deploy URL as an output
- name: Set deploy url
id: deploy_url
run: echo "DEPLOY_URL=$(cat vercel_output.txt | awk 'END{print}')" >> $GITHUB_OUTPUT
- name: Print deploy url
run: echo ${{ steps.deploy_url.outputs.DEPLOY_URL }}
# Create a comment on the pull request with the deployed URL
- name: Comment on pull request
if: github.event_name != 'workflow_dispatch'
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const DEPLOY_URL = '${{ steps.deploy_url.outputs.DEPLOY_URL }}'
const COMMIT_SHA = '${{ github.event.pull_request.head.sha }}'
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `This pull request has been deployed to Vercel.\n\n\nLatest commit: ${COMMIT_SHA}\n\n:white_check_mark: Preview: ${DEPLOY_URL}`
})