-
Notifications
You must be signed in to change notification settings - Fork 1
82 lines (82 loc) · 3.34 KB
/
VercelPreview.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Vercel Preview Deployment
on:
pull_request:
branches:
- main
jobs:
checkLabels:
runs-on: ubuntu-latest
outputs:
output1: ${{ steps.labels.outputs.json }}
permissions: write-all
steps:
- uses: actions/checkout@v4
- name: Get PR labels
id: labels
shell: bash
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.number }}
run: |
json=$(gh pr view "$PR_NUMBER" --json labels | jq -c '.labels|map(.name)')
echo "json=$json" >> "$GITHUB_OUTPUT"
- name: Comment on PR
if: ${{ contains(fromJSON(steps.labels.outputs.json), 'dependencies') || contains(fromJSON(steps.labels.outputs.json), 'documentation') || contains(fromJSON(steps.labels.outputs.json), 'duplicate') || contains(fromJSON(steps.labels.outputs.json), 'devtool') }}
run: |
cat << EOF > comment.md
## :rocket: Preview Deployment
Deployment skipped due to label(s) - dependencies, documentation, duplicate
EOF
gh pr comment ${{ github.event.number }} --body-file comment.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deployment:
needs: checkLabels
if: ${{ !(contains(fromJSON(needs.checkLabels.outputs.output1), 'dependencies') || contains(fromJSON(needs.checkLabels.outputs.output1), 'documentation') || contains(fromJSON(needs.checkLabels.outputs.output1), 'duplicate') || contains(fromJSON(needs.checkLabels.outputs.output1), 'devtool') ) }}
runs-on: ubuntu-latest
concurrency: Preview
environment:
name: Preview
url: ${{ steps.get_release_url.outputs.release_url }}
steps:
- uses: actions/checkout@v4
- name: Get PR labels
id: labels
shell: bash
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.number }}
run: |
json=$(gh pr view "$PR_NUMBER" --json labels | jq -c '.labels|map(.name)')
echo "json=$json" >> "$GITHUB_OUTPUT"
- name: Install Vercel CLI
run: npm install -g vercel
- name: Link Vercel Project
run: vercel link --token=${{secrets.VERCEL_TOKEN}} --project ${{vars.VERCEL_PROJECT}} --yes
- name: Deploy with Vercel
run: vercel deploy --target=staging -f --token=${{secrets.VERCEL_TOKEN}} >deployment-url.txt 2>error.txt
- name: Set release url
id: get_release_url
run: echo release_url=$(cat deployment-url.txt) >> $GITHUB_OUTPUT
- name: Comment on PR
run: |
cat << EOF > comment.md
## :rocket: Preview Deployment
[Preview Deployment](${{ steps.get_release_url.outputs.release_url }})
EOF
gh pr comment ${{ github.event.number }} --body-file comment.md
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Comment on PR
if: failure()
run: |
cat << EOF > comment.md
## :warning: Un Error Occured
Un error occured while deploying the preview. Please check the logs for more information.
EOF
gh pr comment ${{ github.event.number }} --body-file comment.md
gh pr comment ${{ github.event.number }} --body-file error.txt
env:
GITHUB_TOKEN: ${{ github.token }}