-
Notifications
You must be signed in to change notification settings - Fork 2
163 lines (141 loc) · 5.62 KB
/
create-preview-link.yml
File metadata and controls
163 lines (141 loc) · 5.62 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Build Transcripts Preview Site
permissions:
contents: read
pull-requests: write
issues: write
on:
pull_request_target:
paths:
- '**'
workflow_dispatch:
issue_comment:
types: [created]
jobs:
build-preview:
runs-on: ubuntu-latest
environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external-fork-preview' || '' }}
steps:
- name: Get PR details for comment trigger
id: pr-details
if: github.event_name == 'issue_comment'
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
return JSON.stringify({
head_sha: pr.data.head.sha,
head_ref: pr.data.head.ref,
head_repo_fullname: pr.data.head.repo.full_name
});
- name: Setup Checkout for Bitcoin Transcripts (PR Target)
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
path: transcripts
- name: Setup Checkout for Bitcoin Transcripts (Comment Trigger)
if: github.event_name == 'issue_comment'
uses: actions/checkout@v4
with:
repository: ${{ fromJson(steps.pr-details.outputs.result).head_repo_fullname }}
ref: ${{ fromJson(steps.pr-details.outputs.result).head_sha }}
path: transcripts
- name: Setup Checkout for Bitcoin Transcripts (Workflow Dispatch)
if: github.event_name == 'workflow_dispatch'
uses: actions/checkout@v4
with:
path: transcripts
- name: Setup Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Clone Registry Repo
run: git clone https://github.com/bitcointranscripts/registry.git
- name: Replace the public/bitcoin-transcript submodule in Registry with contents of this current branch
working-directory: transcripts
run: |
rm -rf ../registry/public/bitcoin-transcript
mkdir -p ../registry/public/bitcoin-transcript
cp -r * ../registry/public/bitcoin-transcript/
- name: Install dependencies
working-directory: registry
run: |
npm install
- name: Run Next.js build only
working-directory: registry
env:
API_KEY: ${{ secrets.API_KEY }}
CLOUD_ID: ${{ secrets.CLOUD_ID }}
INDEX: ${{ secrets.INDEX }}
run: |
npm run fetch-topics
npm run fetch-reviewers
npx next build
- name: Install Vercel CLI
run: npm install -g vercel
- name: Add vercel.json with custom build-only command
working-directory: registry
run: |
cat <<EOF > vercel.json
{
"buildCommand": "npm run fetch-topics && npm run fetch-reviewers && npx next build"
}
EOF
- name: Pull Vercel project settings
working-directory: registry
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
run: vercel pull --yes --token=$VERCEL_TOKEN
- name: Build with Vercel CLI
working-directory: registry
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
API_KEY: ${{ secrets.API_KEY }}
CLOUD_ID: ${{ secrets.CLOUD_ID }}
INDEX: ${{ secrets.INDEX }}
run: vercel build --token=$VERCEL_TOKEN
- name: Deploy to Vercel
working-directory: registry
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
run: |
vercel deploy --prebuilt --token=$VERCEL_TOKEN --archive=tgz --yes > ../vercel-preview-url.txt
- name: Store Top-Level Folders
working-directory: transcripts
run: |
git remote add upstream https://github.com/bitcointranscripts/bitcointranscripts.git
git fetch upstream
top_level_folders=$(git diff --name-only upstream/master)
echo $top_level_folders > ../top_level_folders.txt
- name: Comment PR with Preview URL
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const url = fs.readFileSync('vercel-preview-url.txt', 'utf8').trim();
const top_level_folders = fs.readFileSync('top_level_folders.txt', 'utf8').trim();
const dirs = top_level_folders.split(' ');
let commentBody = `Your Transcript Preview is ready:\n`;
if (dirs.length >= 1) {
for (const dir of dirs) {
if(dir.includes(".md")) {
let dir_name = dir.replace(".md", "");
commentBody += `- [${dir_name}](${url}/${dir_name})\n`;
}
}
commentBody += `- [View All Transcript Sources](${url}/sources)\n`;
}
const prNumber = context.issue?.number || context.payload.pull_request?.number;
github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});