Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions .github/workflows/create-preview-link.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: Build Preview on Command
permissions:
contents: read
pull-requests: write
on:
issue_comment:
types: [created]

jobs:
build-preview:
runs-on: ubuntu-latest
# Only run on PR comments with the right command from maintainers
if: |
github.event.issue.pull_request &&
contains(github.event.comment.body, '/build-preview') &&
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'

steps:
- name: Get PR details
id: pr
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: pr.data.head.repo.clone_url
});

- name: Setup Checkout for Bitcoin Transcripts
uses: actions/checkout@v4
with:
repository: ${{ fromJson(steps.pr.outputs.result).head_repo }}
ref: ${{ fromJson(steps.pr.outputs.result).head_sha }}
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`;
}

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});