Skip to content

feat: serverless worker #2675

feat: serverless worker

feat: serverless worker #2675

name: Docs Preview Links
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
permissions:
contents: read
pull-requests: write
jobs:
comment-preview-links:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Get preview URL from Vercel comment
id: preview-url
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { resolvePreviewUrl } = require('./bin/preview-url-from-vercel.js');
const baseUrl = await resolvePreviewUrl({ github, context, core });
core.exportVariable('DOCS_PREVIEW_BASE_URL', baseUrl);
core.setOutput('base_url', baseUrl);
- name: Generate docs preview list
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
DOCS_PREVIEW_BASE_URL: ${{ env.DOCS_PREVIEW_BASE_URL }}
run: |
SUMMARY_FILE="temp/doc-preview-summary.md"
mkdir -p "$(dirname "$SUMMARY_FILE")"
node bin/generate-docs-preview-list.js > "$SUMMARY_FILE"
if [ -s "$SUMMARY_FILE" ]; then
echo "has_changes=true" >> "$GITHUB_ENV"
else
echo "This PR does not change any pages in /docs. If you make updates, links to the modified pages will appear here." > "$SUMMARY_FILE"
echo "has_changes=false" >> "$GITHUB_ENV"
fi
echo "SUMMARY_FILE_PATH=$SUMMARY_FILE" >> "$GITHUB_ENV"
- name: Comment with changed docs
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const marker = '<!-- docs-preview-links -->';
const summaryPath = process.env.SUMMARY_FILE_PATH || 'temp/doc-preview-summary.md';
const summary = fs.readFileSync(summaryPath, 'utf8').trim();
const hasChanges = process.env.has_changes === 'true';
core.info(`Docs changes detected: ${hasChanges}`);
const body = [
marker,
'',
'### 📖 Docs PR preview links',
'',
summary,
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100,
});
const existing = comments.find(
(comment) => comment.user?.login === 'github-actions[bot]' && comment.body?.includes(marker),
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
core.info(`Updated existing preview comment (${existing.id}).`);
} else {
const { data: newComment } = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
core.info(`Created new preview comment (${newComment.id}).`);
}