-
Notifications
You must be signed in to change notification settings - Fork 11
252 lines (232 loc) · 10.3 KB
/
auto_release.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
name: auto_release
on:
pull_request:
types: [closed]
jobs:
lookup_default_branch:
runs-on: ubuntu-latest
outputs:
branch_name: ${{ steps.lookup_default_branch.outputs.result }}
head_commit: ${{ steps.lookup_default_branch_head.outputs.result }}
steps:
- name: Lookup default branch name
id: lookup_default_branch
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const repo = await github.rest.repos.get({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name
});
return repo.data.default_branch
- name: Display default_branch_name
run: |
echo "default_branch_name : ${{ steps.lookup_default_branch.outputs.result }}"
- name: Lookup HEAD commit on default branch
id: lookup_default_branch_head
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const branch = await github.rest.repos.getBranch({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
branch: '${{ steps.lookup_default_branch.outputs.result }}'
});
return branch.data.commit.sha
- name: Display default_branch_name_head
run: |
echo "default_branch_head_commit : ${{ steps.lookup_default_branch_head.outputs.result }}"
check_for_norelease_label:
runs-on: ubuntu-latest
outputs:
no_release: ${{ steps.check_for_norelease_label.outputs.result }}
steps:
- name: Check for 'no_release' label on PR
id: check_for_norelease_label
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labels = await github.rest.issues.listLabelsOnIssue({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: context.payload.number
});
core.info("labels: " + JSON.stringify(labels.data))
if ( labels.data.map(l => l.name).includes("no_release") ) {
core.info("Label found")
if ( labels.data.map(l => l.name).includes("pending_release") ) {
// Remove the 'pending_release' label
await github.rest.issues.removeLabel({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: context.payload.pull_request.number,
name: 'pending_release'
})
}
return true
}
return false
- name: Display 'no_release' status
run: |
echo "no_release: ${{ steps.check_for_norelease_label.outputs.result }}"
check_ready_to_release:
runs-on: ubuntu-latest
needs: [check_for_norelease_label,lookup_default_branch]
if: |
needs.check_for_norelease_label.outputs.no_release == 'false'
outputs:
no_open_prs: ${{ steps.watch_dependabot_prs.outputs.is_complete }}
pending_release_pr_list: ${{ steps.get_release_pending_pr_list.outputs.result }}
ready_to_release: ${{ steps.set_ready_for_release.outputs.result }}
steps:
- name: Get Open PRs
id: get_open_pr_list
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# find all open PRs that are targetting the default branch (i.e. main/master)
# return their titles, so they can parsed later to determine if they are
# Dependabot PRs and whether we should wait for them to be auto-merged before
# allowing a release event.
script: |
const pulls = await github.rest.pulls.list({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
state: 'open',
base: '${{ needs.lookup_default_branch.outputs.branch_name }}'
});
return JSON.stringify(pulls.data.map(p=>p.title))
result-encoding: string
- name: Display open_pr_list
run: |
cat <<EOF
open_pr_list : ${{ steps.get_open_pr_list.outputs.result }}
EOF
- name: Get 'pending_release' PRs
id: get_release_pending_pr_list
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const repoWithOwner = `${context.payload.repository.owner.login}/${context.payload.repository.name}`;
const pulls = await github.rest.search.issuesAndPullRequests({
q: `is:pr repo:${repoWithOwner} is:merged`,
});
allPrs = pulls.data.items.map(p=>`#${p.number} '${p.title}' in ${p.repository_url}`);
core.info(`allPrs: ${JSON.stringify(allPrs)}`);
releasePendingPrDetails = pulls.data.items.
filter(function (x) { return x.labels.map(l=>l.name).includes('pending_release') }).
filter(function (x) { return !x.labels.map(l=>l.name).includes('no_release') }).
map(p=>`#${p.number} '${p.title}' in ${p.repository_url}`);
core.info(`releasePendingPrDetails: ${JSON.stringify(releasePendingPrDetails)}`);
const release_pending_prs = pulls.data.items.
filter(function (x) { return x.labels.map(l=>l.name).includes('pending_release') }).
filter(function (x) { return !x.labels.map(l=>l.name).includes('no_release') }).
map(p=>p.number);
core.info(`release_pending_prs: ${JSON.stringify(release_pending_prs)}`);
core.setOutput('is_release_pending', (release_pending_prs.length > 0));
return JSON.stringify(release_pending_prs);
result-encoding: string
- name: Display release_pending_pr_list
run: |
cat <<EOF
release_pending_pr_list : ${{ steps.get_release_pending_pr_list.outputs.result }}
EOF
echo "is_release_pending : ${{ steps.get_release_pending_pr_list.outputs.is_release_pending }}"
- uses: actions/checkout@v3
- name: Read pr-autoflow configuration
id: get_pr_autoflow_config
uses: endjin/pr-autoflow/actions/read-configuration@v4
with:
config_file: .github/config/pr-autoflow.json
- name: Check Human PR
id: is_human_pr
uses: actions/github-script@v6
with:
script: |
return context.payload.pull_request.user.login != 'dependabot[bot]' && context.payload.pull_request.user.login != 'dependjinbot[bot]'
- name: Watch Dependabot PRs
id: watch_dependabot_prs
uses: endjin/pr-autoflow/actions/dependabot-pr-watcher@v4
with:
pr_titles: ${{ steps.get_open_pr_list.outputs.result }}
package_wildcard_expressions: ${{ steps.get_pr_autoflow_config.outputs.AUTO_MERGE_PACKAGE_WILDCARD_EXPRESSIONS }}
max_semver_increment: minor
verbose_mode: 'False'
- name: Set Ready for Release
id: set_ready_for_release
uses: actions/github-script@v6
with:
script: |
return ( '${{ steps.is_human_pr.outputs.result }}' == 'true' || '${{ steps.watch_dependabot_prs.outputs.is_complete }}' == 'True') && '${{ steps.get_release_pending_pr_list.outputs.is_release_pending }}' == 'true'
- name: Display job outputs
run: |
echo "no_open_prs: ${{ steps.watch_dependabot_prs.outputs.is_complete }}"
cat <<EOF
pending_release_pr_list: ${{ steps.get_release_pending_pr_list.outputs.result }}
EOF
echo "is_human_pr: ${{ steps.is_human_pr.outputs.result }}"
echo "ready_to_release : ${{ steps.set_ready_for_release.outputs.result }}"
tag_for_release:
runs-on: ubuntu-latest
needs: [check_ready_to_release,lookup_default_branch]
if: |
needs.check_ready_to_release.outputs.ready_to_release == 'true'
steps:
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.x'
- uses: actions/checkout@v3
with:
# ensure we are creating the release tag on the default branch
ref: ${{ needs.lookup_default_branch.outputs.branch_name }}
fetch-depth: 0
- name: Install GitVersion
run: |
dotnet tool install -g GitVersion.Tool --version 5.8.0
echo "/github/home/.dotnet/tools" >> $GITHUB_PATH
- name: Run GitVersion
id: run_gitversion
run: |
pwsh -noprofile -c 'dotnet-gitversion /diag'
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.ENDJIN_BOT_APP_ID }}
private_key: ${{ secrets.ENDJIN_BOT_PRIVATE_KEY }}
- name: Create SemVer tag
uses: actions/github-script@v6
with:
github-token: ${{ steps.generate_token.outputs.token }}
script: |
const uri_path = '/repos/' + context.payload.repository.owner.login + '/' + context.payload.repository.name + '/git/refs'
const tag = await github.request(('POST ' + uri_path), {
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
ref: 'refs/tags/${{ env.GitVersion_MajorMinorPatch }}',
sha: '${{ needs.lookup_default_branch.outputs.head_commit }}'
})
- name: Remove 'release_pending' label from PRs
id: remove_pending_release_labels
uses: actions/github-script@v6
with:
github-token: '${{ steps.generate_token.outputs.token }}'
script: |
core.info('PRs to unlabel: ${{ needs.check_ready_to_release.outputs.pending_release_pr_list }}')
const pr_list = JSON.parse('${{ needs.check_ready_to_release.outputs.pending_release_pr_list }}')
core.info(`pr_list: ${pr_list}`)
for (const i of pr_list) {
core.info(`Removing label 'pending_release' from issue #${i}`)
github.rest.issues.removeLabel({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: i,
name: 'pending_release'
});
}