-
Notifications
You must be signed in to change notification settings - Fork 951
95 lines (85 loc) · 3.32 KB
/
preview-link.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Vercel deployment preview link generator
on:
pull_request:
types: [opened, synchronize]
paths:
- 'website/docs/docs/**'
- 'website/docs/best-practices/**'
- 'website/docs/guides/**'
- 'website/docs/faqs/**'
- 'website/docs/reference/**'
permissions:
contents: read
pull-requests: write
jobs:
comment-deployment-link:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GitHub CLI and jq
run: |
sudo apt-get update
sudo apt-get install -y jq
sudo apt-get install -y gh
- name: Wait for Vercel deployment
id: vercel_deploy
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CHECK_RUN_ID=""
ATTEMPTS=0
MAX_ATTEMPTS=30 # Adjust as needed
SLEEP_TIME=10 # Adjust as needed
while [ $ATTEMPTS -lt $MAX_ATTEMPTS ]; do
CHECK_RUNS=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/check-runs)
VERCEL_CHECK=$(echo $CHECK_RUNS | jq '.check_runs[] | select(.name=="Vercel")')
if [ -n "$VERCEL_CHECK" ]; then
STATUS=$(echo $VERCEL_CHECK | jq -r '.status')
CONCLUSION=$(echo $VERCEL_CHECK | jq -r '.conclusion')
if [ "$STATUS" == "completed" ]; then
if [ "$CONCLUSION" == "success" ]; then
echo "Vercel deployment completed successfully."
VERCEL_URL=$(echo $VERCEL_CHECK | jq -r '.details_url')
echo "deployment_url=$VERCEL_URL" >> $GITHUB_OUTPUT
break
else
echo "Vercel deployment failed."
exit 1
fi
else
echo "Vercel deployment status: $STATUS. Waiting..."
fi
else
echo "Vercel check not found. Waiting..."
fi
ATTEMPTS=$((ATTEMPTS + 1))
sleep $SLEEP_TIME
done
if [ $ATTEMPTS -eq $MAX_ATTEMPTS ]; then
echo "Vercel deployment did not complete within expected time."
exit 1
fi
- name: Get changed files
id: files
run: |
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep 'website/docs/docs/')
echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT
- name: Generate file preview links
id: links
run: |
DEPLOYMENT_URL="${{ steps.vercel_deploy.outputs.deployment_url }}"
CHANGED_FILES="${{ steps.files.outputs.changed_files }}"
LINKS=$(echo "$CHANGED_FILES" | sed 's#website/docs/docs/##; s/.md$//' | awk -v url="$DEPLOYMENT_URL" '{print "- [" $0 "](" url "/docs/" $0 ")"}')
echo "links=$LINKS" >> $GITHUB_OUTPUT
- name: Post comment with deployment link
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
🚀 Deployment available: ${{ steps.vercel_deploy.outputs.deployment_url }}
Here are the direct links to the updated files:
${{ steps.links.outputs.links }}