-
Notifications
You must be signed in to change notification settings - Fork 3
136 lines (123 loc) · 4.35 KB
/
gh-vercel-deploy.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: vercel-deploy
on:
push:
branches:
- main
- develop
pull_request:
types: [ opened, synchronize ]
workflow_dispatch:
inputs:
pull-request-number:
required: true
type: integer
default: ""
env:
PRODUCTION_BRANCH: main
jobs:
vercel-deploy:
if: "! github.event.pull_request.head.repo.fork"
runs-on: ubuntu-latest
permissions:
deployments: write
pull-requests: write
steps:
- name: Checkout
if: "${{ github.event.inputs.pull-request-number == '' }}"
uses: actions/checkout@v4
with:
submodules: recursive # Fetch private content
fetch-depth: 1 # Fetch all history for .GitInfo and .Lastmod
lfs: true
- name: Checkout workflow_dispatch input reference
if: "${{ github.event.inputs.pull-request-number != '' }}"
uses: actions/checkout@v4
with:
submodules: recursive # Fetch private content
fetch-depth: 1 # Fetch all history for .GitInfo and .Lastmod
lfs: true
ref: "refs/pull/${{ github.event.inputs.pull-request-number }}/merge"
- name: ⛮ cf-gha-baseline
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-baseline@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: ⛮ Set vercel deploy metadata
id: metadata
run: |
if [ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]
then
PR_NUMBER=${{ github.event.inputs.pull-request-number }}
echo "PR_NUMBER=${PR_NUMBER}" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}"
echo "DEPLOY_NAME=PR-${PR_NUMBER}" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}"
else
if [ "${TRIGGERING_REF}" == "branch" ]
then
if [ "${BRANCH_NAME}" == "${PRODUCTION_BRANCH}" ]
then
echo "VERCEL_ARGS=--prod" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}"
fi
echo "DEPLOY_NAME=BRANCH-${BRANCH_NAME}" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}"
elif [ "${TRIGGERING_REF}" == "pr" ]
then
echo "PR_NUMBER=${PR_NUMBER}" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}"
echo "DEPLOY_NAME=PR-${PR_NUMBER}" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}"
fi
fi
- name: Start Deployment
uses: bobheadxi/[email protected]
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: vercel-deploy-${{ steps.metadata.outputs.DEPLOY_NAME }}
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '22'
- name: 🔨 Build project
env:
VITE_GITHUB_URL: https://github.com/cardano-foundation/cf-explorer-landing
VITE_CARDANO_URL: https://cardano.org/
run: |
npm ci
npm run build
- name: Configure vercel.json
run: |
cat > dist/vercel.json <<EOF
{
"rewrites": [
{
"source": "/((?!^/$).*)",
"destination": "/index.html"
}
]
}
EOF
# Push our generated site to Vercel
- name: Deploy to Vercel
uses: amondnet/vercel-action@v20
id: vercel-action
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
#github-token: ${{ secrets.GITHUB_TOKEN }} #Optional
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} #Required
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} # Required
github-comment: false
vercel-args: ${{ steps.metadata.outputs.VERCEL_ARGS }}
working-directory: dist
- name: Comment PR
uses: thollander/actions-comment-pull-request@v1
if: ${{ (github.event_name == 'pull_request') || (github.event_name == 'workflow_dispatch') }}
with:
message: 'Vercel PR (merge commit) deploy URL: ${{ steps.vercel-action.outputs.preview-url }}'
pr_number: ${{ steps.metadata.outputs.PR_NUMBER }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update Deployment Status
uses: bobheadxi/[email protected]
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: ${{ steps.vercel-action.outputs.preview-url }}