@@ -13,17 +13,19 @@ jobs:
13
13
github.event.workflow_run.conclusion == 'success' &&
14
14
github.event.workflow_run.event == 'pull_request'
15
15
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
17
24
uses : actions/github-script@v7
18
25
with :
19
26
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
+
27
29
// Check if this was a fork PR by checking if approve-fork job ran
28
30
const jobs = await github.rest.actions.listJobsForWorkflowRun({
29
31
owner: context.repo.owner,
@@ -36,18 +38,29 @@ jobs:
36
38
core.setFailed('Not a fork PR approval workflow run');
37
39
return;
38
40
}
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
+ }
39
52
40
- console.log(`Deploying approved fork PR #${pr.number }`);
53
+ console.log(`Deploying approved fork PR #${prNumber }`);
41
54
42
55
// Trigger deployment via repository dispatch
43
56
await github.rest.repos.createDispatchEvent({
44
57
owner: context.repo.owner,
45
58
repo: context.repo.repo,
46
59
event_type: 'pr-preview-deploy',
47
60
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 ,
51
64
is_fork: 'true'
52
65
}
53
66
});
0 commit comments