forked from boundless-xyz/boundless
-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (108 loc) · 4.34 KB
/
documentation.yml
File metadata and controls
128 lines (108 loc) · 4.34 KB
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
name: Documentation CI/CD
on:
push:
paths:
- "documentation/**"
env:
FOUNDRY_VERSION: v1.2.2
jobs:
build-and-deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./documentation
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Get latest tag
id: get_latest_tag
run: echo "LATEST_TAG=$(git describe --tags --abbrev=0 | sed 's/^v//')" >> $GITHUB_ENV
- name: 🍞 Setup Bun
uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: bun install
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: ${{ env.FOUNDRY_VERSION }}
- name: Run CI checks & build
env:
LATEST_TAG: ${{ env.LATEST_TAG }}
run: bun run ci
- name: Install Vercel CLI
run: |
bun install --global vercel@latest
vercel telemetry disable
- name: Link Vercel Project
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: team_x2TOoPBcvZhOcs3NOcG4IfAo
VERCEL_PROJECT_ID: prj_52J4bKnmBJxkhM6DQIxXBPsI2L7N
run: |
vercel link --token=${{ secrets.VERCEL_TOKEN }} --yes
- name: Deploy to Vercel
id: deploy
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: team_x2TOoPBcvZhOcs3NOcG4IfAo
VERCEL_PROJECT_ID: prj_52J4bKnmBJxkhM6DQIxXBPsI2L7N
run: |
if [[ ${{ github.ref }} == 'refs/heads/main' ]]; then
DEPLOYMENT_URL=$(vercel deploy site/dist --prod --token=${{ secrets.VERCEL_TOKEN }} --yes)
else
DEPLOYMENT_URL=$(vercel deploy site/dist --token=${{ secrets.VERCEL_TOKEN }} --yes)
fi
echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
- name: Find or Create Comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Try to find PR number from the commit
PR_NUMBER=$(gh pr list --search "${{ github.sha }}" --json number --jq '.[0].number')
if [ ! -z "$PR_NUMBER" ]; then
# If we found a PR, comment on it
COMMENTS_URL="https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
else
# If no PR found, comment on the commit
COMMIT_SHA=${{ github.sha }}
COMMENTS_URL="https://api.github.com/repos/${{ github.repository }}/commits/${COMMIT_SHA}/comments"
fi
# Get all comments
COMMENTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$COMMENTS_URL")
# Find existing comment ID
COMMENT_ID=$(echo "$COMMENTS" | jq -r '.[] | select(.body | contains("🚀 Documentation Preview")) | .id' | head -n1)
# Updated comment body with both URLs
COMMENT_BODY="🚀 Documentation Preview\n\nDeployment URL: ${{ steps.deploy.outputs.deployment_url }}\n\n_Updated at: $(date -u +'%Y-%m-%d %H:%M:%S UTC')_"
# Create JSON payload
PAYLOAD="{\"body\":\"$COMMENT_BODY\"}"
if [ ! -z "$PR_NUMBER" ]; then
if [ ! -z "$COMMENT_ID" ]; then
# Update existing PR comment
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-X PATCH \
-d "$PAYLOAD" \
"https://api.github.com/repos/${{ github.repository }}/issues/comments/${COMMENT_ID}"
else
# Create new PR comment
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-X POST \
-d "$PAYLOAD" \
"$COMMENTS_URL"
fi
else
# For commits without PRs, create a commit comment
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-X POST \
-d "$PAYLOAD" \
"$COMMENTS_URL"
fi