-
-
Notifications
You must be signed in to change notification settings - Fork 109
131 lines (129 loc) · 4.93 KB
/
create-stable-pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Create Pull Request from Beta to Stable
on:
push:
branches: [ beta ]
workflow_dispatch:
jobs:
create-pull-request:
runs-on: ubuntu-latest
steps:
- name: Checkout Beta Branch
uses: actions/checkout@v4
with:
clean: true
submodules: true
fetch-depth: 100
fetch-tags: true
show-progress: true
lfs: true
ref: beta
- name: Checkout Stable Branch
run: |
git fetch --all
git checkout stable
git branch
- name: Get Merge Commits from Beta not in Stable
id: get_commits
run: |
function repairNotes {
sed 's/\r//g' | awk '{
if (NR == 1) {
printf("%s", $0)
} else {
if ($0 ~ /^[\t ]*(-|IOS_ONLY[\t ]*-|MACOS_ONLY[\t ]*-).*$/) {
printf("\n%s", $0)
} else {
printf(" %s", $0)
}
}
}
END {
printf("\n")
}'
}
echo "Extracting merge commit texts..."
version="$(git log beta -n 1 --merges --pretty=format:%s | sed -E 's/^[\t\n ]*([^\n\t ]+)[\t\n ]+\(([^\n\t ]+)\)[\t\n ]*$/\1/g')"
echo "version=$version" | tee /dev/stderr >> "$GITHUB_OUTPUT"
echo "buildVersion=$(echo "$version" | grep -oE '^[0-9]+(\.[0-9]+){0,2}')" | tee /dev/stderr >> "$GITHUB_OUTPUT"
echo "description<<__EOF__" | tee /dev/stderr >> "$GITHUB_OUTPUT"
echo "$(git log stable..beta --merges --pretty=format:%b)" | repairNotes | tee /dev/stderr >> "$GITHUB_OUTPUT"
echo "__EOF__" | tee /dev/stderr >> "$GITHUB_OUTPUT"
- name: Find Existing Pull Request
id: find_pr
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
const { data: pullRequests } = await github.rest.pulls.list({
owner,
repo,
state: 'open',
head: 'beta',
base: 'stable'
});
const existingPR = pullRequests.find(pr => pr.labels.some(label => label.name === 'automated-pr'));
console.log(`Existing PR: `, existingPR);
if(existingPR)
return existingPR.number;
else
return null;
- name: Create or Update Pull Request
id: create_or_update_pr
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
const prNumber = ${{ steps.find_pr.outputs.result }};
let pullRequest;
if(prNumber)
{
console.log(`Updating old PR #${prNumber}...`);
pullRequest = await github.rest.pulls.update({
owner,
repo,
pull_number: prNumber,
title: `${{ steps.get_commits.outputs.buildVersion }}`,
body: `${{ steps.get_commits.outputs.description }}`,
});
console.log(`Updated pull request #${prNumber}`);
}
else
{
console.log(`Creating new PR...`);
pullRequest = await github.rest.pulls.create({
owner,
repo,
head: 'beta',
base: 'stable',
draft: false,
title: `${{ steps.get_commits.outputs.buildVersion }}`,
body: `${{ steps.get_commits.outputs.description }}`,
});
console.log(`Created pull request #${pullRequest.data.number}`);
//update pr after creation to trigger our pr-semver-title workflow
pullRequest = await github.rest.pulls.update({
owner,
repo,
pull_number: pullRequest.data.number,
title: `${{ steps.get_commits.outputs.buildVersion }}`,
body: `${{ steps.get_commits.outputs.description }}`,
});
console.log(`Updated pull request #${pullRequest.data.number}`);
}
return pullRequest.data.number;
- name: Add Label to Pull Request
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
const pullNumber = ${{ steps.create_or_update_pr.outputs.result }};
await github.rest.issues.addLabels({
owner,
repo,
issue_number: pullNumber,
labels: ['automated-pr']
});
console.log(`Added label to pull request #${pullNumber}`);