-
Notifications
You must be signed in to change notification settings - Fork 12
214 lines (208 loc) · 7.82 KB
/
release-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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: Create/Update Release PR
on:
push:
branches:
- main
workflow_dispatch:
inputs:
level:
default: minor
required: false
type: choice
options:
- major
- minor
- patch
description: 'bump to [major|minor|patch]'
env:
REGISTRY: ghcr.io
IMAGE_NAME: heromo/pronto-action
jobs:
prepare:
name: Prepare Versions and Release Note
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
outputs:
exist-release-pr: ${{ steps.release-pr.outputs.result }}
release-pr: ${{ steps.release-pr.outputs.pr }}
release-note: ${{ steps.release-note.outputs.release-note }}
latest-version: ${{ steps.versions.outputs.latest-version }}
next-version: ${{ steps.versions.outputs.next-version }}
timeout-minutes: 60
steps:
- name: Check out
uses: actions/checkout@v4
- name: Fetch Latest & Next Release Version
uses: actions/github-script@v6
id: versions
with:
script: |
const script = require('./.github/wf-scripts/latest-version.js');
let level = 'minor';
if ('${{ inputs.level }}' != '') level = '${{ inputs.level }}';
return await script({github, context, core, level});
- name: Generate Release Note
uses: actions/github-script@v6
id: release-note
with:
script: |
const script = require('./.github/wf-scripts/release-note.js');
const latestVersion = '${{ steps.versions.outputs.latest-version }}';
const nextVersion = '${{ steps.versions.outputs.next-version }}';
await script({github, context, core, latestVersion, nextVersion});
- name: Fetch Release PR
uses: actions/github-script@v6
id: release-pr
with:
script: |
const nextVersion = '${{ steps.versions.outputs.next-version }}';
const pulls = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `heromo:release/${ nextVersion }`,
});
const pull = pulls.data[0];
core.setOutput('pr', pull);
return !!pull
- name: Create Issue on Failure
if: failure()
uses: actions/github-script@v6
with:
script: |
const create = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "Failed to prepare create/update release pr",
body: `Automation has failed! Failed to create/update release pr for '${{ steps.versions.outputs.next-version }}'\nMore information can be found at:\n - ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`,
assignees: [
'${{ github.repository_owner }}'
]
})
create-release-pr:
name: Create Release Pull Request
needs: prepare
if: needs.prepare.outputs.exist-release-pr == 'false'
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
timeout-minutes: 60
steps:
- name: Check out
uses: actions/checkout@v4
with:
ref: main
- name: Git config
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b release/${{ needs.prepare.outputs.next-version }}
- name: Modify files
run: |
yq '.runs.image = "docker://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.next-version }}"' -i action.yaml
sed -i -r 's/pronto-action@v[0-9]+\.[0-9]+\.[0-9]+/pronto-action@${{ needs.prepare.outputs.next-version }}/' README.md
git add action.yaml README.md
- name: check diff
shell: bash
id: changes
run: |
echo "count=$(git diff --staged --name-only . |wc -l)" >> $GITHUB_OUTPUT
- name: Commit and Push if changed
if: steps.changes.outputs.count > 0
run: |
git commit -m 'bumpup image version'
git push origin release/${{ needs.prepare.outputs.next-version }}
- name: Create PR
if: steps.changes.outputs.count > 0
uses: actions/github-script@v6
id: create-pr
with:
script: |
const releaseNote = ${{ needs.prepare.outputs.release-note }};
const { data: pull } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: 'release/${{ needs.prepare.outputs.next-version }}',
base: 'main',
title: 'Release ${{ needs.prepare.outputs.next-version }}',
body: releaseNote.data.body
});
core.setOutput('created-pr', pull);
github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pull.number,
assignees: [context.repo.owner],
});
github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pull.number,
labels: ['release'],
});
- name: Create Issue on Failure
if: failure()
uses: actions/github-script@v6
with:
script: |
const create = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "Failed to create release pr",
body: `Automation has failed! Failed to create release pr for '${{ needs.prepare.outputs.next-version }}'\nMore information can be found at:\n - ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`,
assignees: [
'${{ github.repository_owner }}'
]
})
update-release-pr:
name: Update Release Pull Request
needs: prepare
if: needs.prepare.outputs.exist-release-pr == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
timeout-minutes: 60
steps:
- name: Update PR
uses: actions/github-script@v6
with:
script: |
const releasePull = ${{ needs.prepare.outputs.release-pr }};
const releaseNote = ${{ needs.prepare.outputs.release-note }};
const { data: pull } = await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: releasePull.number,
body: releaseNote.data.body
});
core.setOutput('updated-pr', pull);
- name: Create Issue on Failure
if: failure()
uses: actions/github-script@v6
with:
script: |
const releasePull = ${{ needs.prepare.outputs.release-pr }};
const create = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "Failed to update release pr",
body: `Automation has failed! Failed to update release pr '${releasePull.title}'\nMore information can be found at:\n - ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`,
assignees: [
'${{ github.repository_owner }}'
]
})