44 workflows : ["Build Preview Site"]
55 types :
66 - completed
7+ branches :
8+ - master
79
810# This workflow runs with write permissions from the base repository
911permissions :
1012 contents : write
1113 pull-requests : write
14+ actions : read
1215
1316jobs :
1417 deploy :
1518 runs-on : ubuntu-latest
16- # Only run if the build was successful
17- if : ${{ github.event.workflow_run.conclusion == 'success' }}
19+ # Only run if the build was successful and originated from a PR
20+ if : |
21+ github.event.workflow_run.conclusion == 'success' &&
22+ github.event.workflow_run.event == 'pull_request'
1823 steps :
1924 - name : Checkout 🛎️
2025 uses : actions/checkout@v6
2126
2227 - name : Download artifacts
23- uses : actions/download-artifact@v4
28+ uses : actions/github-script@v7
2429 with :
25- run-id : ${{ github.event.workflow_run.id }}
26- github-token : ${{ secrets.GITHUB_TOKEN }}
27- pattern : pr-*
28- merge-multiple : false
30+ script : |
31+ let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
32+ owner: context.repo.owner,
33+ repo: context.repo.repo,
34+ run_id: context.payload.workflow_run.id,
35+ });
36+
37+ let matchArtifacts = allArtifacts.data.artifacts.filter((artifact) => {
38+ return artifact.name.match(/^pr-(metadata|public-dir)-/);
39+ });
40+
41+ if (matchArtifacts.length === 0) {
42+ core.setFailed('No artifacts found');
43+ return;
44+ }
45+
46+ let fs = require('fs');
47+ for (const artifact of matchArtifacts) {
48+ let download = await github.rest.actions.downloadArtifact({
49+ owner: context.repo.owner,
50+ repo: context.repo.repo,
51+ artifact_id: artifact.id,
52+ archive_format: 'zip',
53+ });
54+ fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifact.name}.zip`, Buffer.from(download.data));
55+ }
56+
57+ - name : Extract artifacts
58+ run : |
59+ for zip in *.zip; do
60+ if [ -f "$zip" ]; then
61+ mkdir -p "${zip%.zip}"
62+ unzip -q "$zip" -d "${zip%.zip}"
63+ fi
64+ done
2965
3066 - name : Read PR metadata
3167 id : pr-metadata
3571
3672 if [ -z "$metadata_dir" ]; then
3773 echo "Error: Could not find PR metadata"
74+ ls -la
3875 exit 1
3976 fi
4077
@@ -52,11 +89,21 @@ jobs:
5289
5390 - name : Extract site
5491 run : |
55- # Find and unzip the public directory
56- public_zip=$(find . -type f -name "public-dir-pr-*.zip" | head -n 1)
92+ # Find and extract the public directory zip
93+ public_artifact=$(find . -type d -name "public-dir-pr-*" | head -n 1)
94+
95+ if [ -z "$public_artifact" ]; then
96+ echo "Error: Could not find public directory artifact"
97+ ls -la
98+ exit 1
99+ fi
100+
101+ # Find the zip file in the artifact directory
102+ public_zip=$(find "$public_artifact" -type f -name "*.zip" | head -n 1)
57103
58104 if [ -z "$public_zip" ]; then
59- echo "Error: Could not find public directory zip"
105+ echo "Error: Could not find public directory zip in artifact"
106+ ls -la "$public_artifact"
60107 exit 1
61108 fi
62109
67114 mv public-dir public
68115 elif [ ! -d "public" ]; then
69116 echo "Error: Neither public nor public-dir found after extraction"
117+ ls -la
70118 exit 1
71119 fi
72120
0 commit comments