Skip to content

Commit 1aa1a49

Browse files
authored
Merge branch 'master' into test-preview-deployment
2 parents 7b458f6 + f3204b7 commit 1aa1a49

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

.github/workflows/fork-preview-deploy.yml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ jobs:
1313
github.event.workflow_run.conclusion == 'success' &&
1414
github.event.workflow_run.event == 'pull_request'
1515
steps:
16-
- name: Check and deploy approved fork PR
16+
- name: Download PR information
17+
uses: actions/download-artifact@v4
18+
with:
19+
name: pr
20+
github-token: ${{ secrets.GITHUB_TOKEN }}
21+
run-id: ${{ github.event.workflow_run.id }}
22+
23+
- name: Read PR information and trigger deployment
1724
uses: actions/github-script@v7
1825
with:
1926
script: |
20-
// Get the PR that triggered the workflow
21-
const pr = context.payload.workflow_run.pull_requests[0];
22-
if (!pr) {
23-
core.setFailed('No PR found in workflow run');
24-
return;
25-
}
26-
27+
const fs = require('fs');
28+
2729
// Check if this was a fork PR by checking if approve-fork job ran
2830
const jobs = await github.rest.actions.listJobsForWorkflowRun({
2931
owner: context.repo.owner,
@@ -36,18 +38,29 @@ jobs:
3638
core.setFailed('Not a fork PR approval workflow run');
3739
return;
3840
}
41+
42+
// Read PR information from artifacts
43+
let prNumber, prHeadSha, prCheckoutRepo;
44+
try {
45+
prNumber = fs.readFileSync('./pr_number', 'utf8').trim();
46+
prHeadSha = fs.readFileSync('./pr_head_sha', 'utf8').trim();
47+
prCheckoutRepo = fs.readFileSync('./pr_checkout_repository', 'utf8').trim();
48+
} catch (error) {
49+
core.setFailed(`Failed to read PR information: ${error.message}`);
50+
return;
51+
}
3952
40-
console.log(`Deploying approved fork PR #${pr.number}`);
53+
console.log(`Deploying approved fork PR #${prNumber}`);
4154
4255
// Trigger deployment via repository dispatch
4356
await github.rest.repos.createDispatchEvent({
4457
owner: context.repo.owner,
4558
repo: context.repo.repo,
4659
event_type: 'pr-preview-deploy',
4760
client_payload: {
48-
pr_number: String(pr.number),
49-
pr_head_sha: pr.head.sha,
50-
pr_checkout_repository: pr.head.repo.full_name,
61+
pr_number: prNumber,
62+
pr_head_sha: prHeadSha,
63+
pr_checkout_repository: prCheckoutRepo,
5164
is_fork: 'true'
5265
}
5366
});

.github/workflows/pr-preview-check.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,17 @@ jobs:
3535
if: github.event.pull_request.head.repo.fork == true
3636
environment: fork-preview-protection
3737
steps:
38-
- run: echo "Fork PR ${{ github.event.pull_request.number }} approved for preview deployment"
38+
- name: Save PR information
39+
run: |
40+
echo "Fork PR #${{ github.event.pull_request.number }} approved for preview deployment"
41+
mkdir -p ./pr
42+
echo "${{ github.event.pull_request.number }}" > ./pr/pr_number
43+
echo "${{ github.event.pull_request.head.sha }}" > ./pr/pr_head_sha
44+
echo "${{ github.event.pull_request.head.repo.full_name }}" > ./pr/pr_checkout_repository
45+
46+
- name: Upload PR information
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: pr
50+
path: pr/
51+
retention-days: 1

0 commit comments

Comments
 (0)