Skip to content

Commit 9adfd48

Browse files
Add upstream refs (#140)
* Create action.yml * Update pr-checks.yml * Update action.yml * Update action.yml * Update pr-checks.yml * Update action.yml * Update action.yml * Update pr-checks.yml * Update action.yml * Update pr-checks.yml * Update action.yml * Update action.yml * Update action.yml * Update action.yml * Update action.yml * Update action.yml * Update pr-checks.yml * Update action.yml * Update pr-checks.yml * Update action.yml * Update action.yml * Update pr-checks.yml * Update action.yml * Update pr-checks.yml * Update pr-checks.yml * Update pr-checks.yml * Update pr-checks.yml * Update pr-checks.yml * Update action.yml * Update action.yml * Update pr-checks.yml * Update action.yml * Update action.yml * Update action.yml * Update action.yml * Update pr-checks.yml * Update pr-checks.yml * Update action.yml * Update pr-checks.yml * Update action.yml * Update pr-checks.yml * Create PULL_REQUEST_TEMPLATE.md * Update pr-checks.yml
1 parent cb98886 commit 9adfd48

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Description
2+
3+
Fixes
4+
5+
### Remote Refs
6+
7+
<!--- REMOTE REFS START -->
8+
9+
premium: main
10+
11+
<!--- REMOTE REFS END -->

.github/workflows/pr-checks.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ on:
44
pull_request:
55
types: [opened, synchronize]
66

7-
env:
8-
PREMIUM_REPO_REF: main
9-
107
jobs:
118
php-lint-test:
129
name: "PHP: Lint, Test"
@@ -22,13 +19,17 @@ jobs:
2219
with:
2320
token: ${{ secrets.ACCESS_TOKEN_IR }}
2421

22+
- name: Remote refs
23+
uses: ./actions/upstream-refs
24+
id: remote-refs
25+
2526
- name: Checkout premium projects repo
2627
uses: actions/checkout@v4
2728
with:
2829
path: premium
2930
token: ${{ secrets.ACCESS_TOKEN_IR }}
3031
repository: ${{ secrets.PREMIUM_PROJECTS_REPO }}
31-
ref: ${{ env.PREMIUM_REPO_REF }}
32+
ref: ${{ fromJSON(steps.remote-refs.outputs.result).premium || 'main' }}
3233

3334
- name: Setup Environment
3435
uses: ./actions/setup
@@ -72,13 +73,17 @@ jobs:
7273
with:
7374
token: ${{ secrets.ACCESS_TOKEN_IR }}
7475

76+
- name: Remote refs
77+
uses: ./actions/upstream-refs
78+
id: remote-refs
79+
7580
- name: Checkout premium projects repo
7681
uses: actions/checkout@v4
7782
with:
7883
path: premium
7984
token: ${{ secrets.ACCESS_TOKEN_IR }}
8085
repository: ${{ secrets.PREMIUM_PROJECTS_REPO }}
81-
ref: ${{ env.PREMIUM_REPO_REF }}
86+
ref: ${{ fromJSON(steps.remote-refs.outputs.result).premium || 'main' }}
8287

8388
- name: Setup Environment
8489
uses: ./actions/setup

actions/upstream-refs/action.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: "Read the refs/branches to use for checking out upstream repos"
2+
description: "Reads and outputs the refs/branches from PR description to use for checking out upstream repos."
3+
author: "wpsocio"
4+
5+
outputs:
6+
result:
7+
description: "Refs JSON"
8+
value: ${{ steps.details.outputs.result }}
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Get details
14+
uses: actions/github-script@v7
15+
id: details
16+
with:
17+
script: |
18+
const pr = await github.rest.pulls.get({
19+
owner: context.repo.owner,
20+
repo: context.repo.repo,
21+
pull_number: context.payload.pull_request.number,
22+
});
23+
24+
/**
25+
* The comment has to be in this format
26+
*
27+
* <!--- REMOTE REFS START -->
28+
* some/project/path: add/some-feature
29+
* some/other/project/path: fix/some-bug
30+
* <!--- REMOTE REFS END -->
31+
*/
32+
const refsCommentRegex =
33+
/<!--- REMOTE REFS START -->(?<content>.+)<!--- REMOTE REFS END -->/is;
34+
35+
const result = (pr.data.body || '').match(refsCommentRegex);
36+
37+
if (!result?.groups?.content) {
38+
return {};
39+
}
40+
41+
const refs = result.groups.content
42+
.trim()
43+
.split(/[\n\r]+/)
44+
.filter((line) => line.trim())
45+
.reduce((list, line) => {
46+
const [name, ref] = line.split(/:\s?/);
47+
48+
list[name.trim()] = ref.trim();
49+
50+
return list;
51+
}, {});
52+
53+
return refs;

0 commit comments

Comments
 (0)