Skip to content

Commit 3c5fd3f

Browse files
committed
Add action
Test in workflow Fix action multiline output undefined debug fix Remove debug Install Wasp from linked PR Fix step Case insensitive
1 parent b7b8047 commit 3c5fd3f

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Get linked PR
2+
description: Get the PR linked to this one, if any.
3+
4+
inputs:
5+
github-token:
6+
description: GitHub token to use for API requests
7+
default: ${{ github.token }}
8+
target-repo:
9+
description: Repository in which the PR should exist (e.g. "wasp-lang/wasp")
10+
required: true
11+
source-repo:
12+
description: Repository in which the current PR exists (e.g. "wasp-lang/open-saas")
13+
default: ${{ github.repository }}
14+
source-pr:
15+
description: Current PR number
16+
default: ${{ github.event.pull_request.number }}
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Get source PR
22+
id: source-pr
23+
env:
24+
GH_TOKEN: ${{ inputs.github-token }}
25+
SOURCE_REPO: ${{ inputs.source-repo }}
26+
SOURCE_PR: ${{ inputs.source-pr }}
27+
shell: bash
28+
run: |
29+
{
30+
echo 'pr-body<<EOF'
31+
gh pr view "$SOURCE_PR" \
32+
--repo "$SOURCE_REPO" \
33+
--json body \
34+
--jq '.body'
35+
echo EOF
36+
} >> "$GITHUB_OUTPUT"
37+
38+
- name: Get linked PR URL
39+
id: get-url
40+
env:
41+
PR_BODY: ${{ steps.source-pr.outputs.pr-body }}
42+
TARGET_REPO: ${{ inputs.target-repo }}
43+
uses: actions/github-script@v8
44+
with:
45+
script: |
46+
const prBody = process.env.PR_BODY;
47+
const targetRepo = process.env.TARGET_REPO;
48+
49+
const prUrlPrefix = RegExp.escape(`https://github.com/${targetRepo}/pull`);
50+
51+
// Captures the PR URL in a "link to ..." phrase.
52+
const prUrlRegex = new RegExp(`\\blink to (${prUrlPrefix}\/\\d+)\/?`, "i");
53+
54+
const prUrl = prBody.match(prUrlRegex)?.[1];
55+
return prUrl || "";
56+
result-encoding: string
57+
58+
- name: Get linked PR branch
59+
if: steps.get-url.outputs.result
60+
id: get-branch
61+
env:
62+
GH_TOKEN: ${{ inputs.github-token }}
63+
PR_URL: ${{ steps.get-url.outputs.result }}
64+
shell: bash
65+
run: |
66+
pr_branch=$(
67+
gh pr view "$PR_URL" \
68+
--json headRefName \
69+
--jq '.headRefName'
70+
)
71+
echo "pr-branch=$pr_branch" >> "$GITHUB_OUTPUT"
72+
73+
outputs:
74+
pr-url:
75+
description: URL of the linked PR, or empty if none found
76+
value: ${{ steps.get-url.outputs.result }}
77+
78+
pr-branch:
79+
description: Branch name of the linked PR, or empty if none found
80+
value: ${{ steps.get-branch.outputs.pr-branch }}

.github/workflows/e2e-tests.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ jobs:
2929
- name: Docker setup
3030
uses: docker/setup-buildx-action@v3
3131

32+
- name: Get linked PR branch
33+
id: get-linked-pr-branch
34+
uses: ./.github/actions/get-linked-pr
35+
with:
36+
target-repo: wasp-lang/wasp
37+
3238
- name: Download Wasp build artifacts from linked PR
3339
uses: wasp-lang/wasp/.github/actions/fetch-nightly-cli@main
3440
with:
3541
output-dir: ${{ runner.temp }}/wasp-cli
36-
branch: main
42+
branch: ${{ steps.get-linked-pr-branch.outputs.pr-branch || 'main' }}
3743

3844
- name: Install Wasp
3945
run: >

0 commit comments

Comments
 (0)