Skip to content

Commit 8c1c2c4

Browse files
committed
ci: update preview workflow to trigger on successful documentation builds
1 parent b7b20cb commit 8c1c2c4

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

.github/workflows/preview-docs.yml

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,57 @@
1818
name: Preview Documentation
1919

2020
on:
21-
pull_request_target:
22-
paths:
23-
- 'website/**'
21+
workflow_run:
22+
workflows: ["Build Documentation"]
23+
types:
24+
- completed
2425

2526
jobs:
26-
deploy-preview:
27+
preview:
2728
runs-on: ubuntu-latest
29+
permissions:
30+
pull-requests: write
31+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
2832
steps:
29-
- uses: actions/checkout@v4
33+
- name: Checkout
34+
uses: actions/checkout@v4
3035

31-
- uses: pnpm/action-setup@v4
36+
- name: Download artifact
37+
uses: actions/github-script@v7
3238
with:
33-
version: 8
34-
run_install: false
39+
script: |
40+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
run_id: ${{ github.event.workflow_run.id }},
44+
});
45+
const websiteArtifact = artifacts.data.artifacts.filter((artifact) => {
46+
return artifact.name == 'website'
47+
})[0];
48+
var download = await github.rest.actions.downloadArtifact({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
artifact_id: websiteArtifact.id,
52+
archive_format: 'zip',
53+
});
54+
const fs = require('fs');
55+
fs.writeFileSync('${{github.workspace}}/website.zip', Buffer.from(download.data));
3556
36-
- uses: actions/setup-node@v4
37-
with:
38-
node-version: "20"
39-
40-
- name: Corepack
41-
working-directory: website
42-
run: npm i -g --force corepack && corepack enable
43-
44-
- name: Install Dependencies
45-
working-directory: website
46-
run: pnpm install
47-
48-
- name: Build
49-
working-directory: website
50-
run: pnpm build
57+
- name: Unzip artifact
58+
run: unzip -q website.zip -d website/build
5159

52-
- name: Deploy to Netlify
60+
- name: Deploy preview to Netlify
5361
uses: nwtgck/actions-netlify@4cbaf4c08f1a7bfa537d6113472ef4424e4eb654
5462
with:
5563
publish-dir: './website/build'
5664
production-deploy: false
5765
github-token: ${{ secrets.GITHUB_TOKEN }}
58-
deploy-message: ${{ github.event.pull_request.title }}
66+
deploy-message: "Deploy preview for PR #${{ github.event.workflow_run.pull_requests[0].number }}"
5967
enable-pull-request-comment: true
6068
enable-commit-comment: false
6169
enable-github-deployment: false
62-
alias: deploy-preview-${{ github.event.number }}
70+
alias: deploy-preview-${{ github.event.workflow_run.pull_requests[0].number }}
6371
env:
6472
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
6573
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
74+
timeout-minutes: 10

0 commit comments

Comments
 (0)