Skip to content

Commit d990222

Browse files
devlooped-botkzu
authored andcommitted
⬆️ Bump files with dotnet-file sync
# devlooped/oss - Update combine prs default message devlooped/oss@74189b0 - Rename matrix lookup job and steps devlooped/oss@cf8e339 - Always pass in auth headers to GH API devlooped/oss@a922d03
1 parent fa60184 commit d990222

5 files changed

Lines changed: 173 additions & 14 deletions

File tree

.github/workflows/build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,29 @@ defaults:
2323
shell: bash
2424

2525
jobs:
26-
os:
26+
os-matrix:
2727
runs-on: ubuntu-latest
2828
outputs:
29-
os: ${{ steps.os.outputs.os }}
29+
matrix: ${{ steps.lookup.outputs.matrix }}
3030
steps:
3131
- name: 🤘 checkout
3232
uses: actions/checkout@v2
3333

34-
- name: 🔎 os
35-
id: os
34+
- name: 🔎 lookup
35+
id: lookup
3636
shell: pwsh
3737
run: |
3838
$path = './.github/workflows/os-matrix.json'
3939
$os = if (test-path $path) { cat $path } else { '["ubuntu-latest"]' }
40-
echo "::set-output name=os::$os"
40+
echo "::set-output name=matrix::$os"
4141
4242
build:
43-
needs: os
43+
needs: os-matrix
4444
name: build-${{ matrix.os }}
4545
runs-on: ${{ matrix.os }}
4646
strategy:
4747
matrix:
48-
os: ${{ fromJSON(needs.os.outputs.os) }}
48+
os: ${{ fromJSON(needs.os-matrix.outputs.matrix) }}
4949
steps:
5050
- name: 🤘 checkout
5151
uses: actions/checkout@v2

.github/workflows/combine-prs.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: '⛙ combine-prs'
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branchExpression:
7+
description: 'Regular expression to match against PR branches to find combinable PRs'
8+
required: true
9+
default: 'dependabot'
10+
mustBeGreen:
11+
description: 'Only combine PRs that are green (status is success)'
12+
required: true
13+
default: true
14+
combineTitle:
15+
description: 'Title of the combined PR'
16+
required: true
17+
default: '⬆️ Bump dependencies'
18+
combineBranchName:
19+
description: 'Name of the branch to combine PRs into'
20+
required: true
21+
default: 'combine-prs'
22+
ignoreLabel:
23+
description: 'Exclude PRs with this label'
24+
required: true
25+
default: 'nocombine'
26+
27+
jobs:
28+
combine-prs:
29+
name: ${{ github.event.inputs.combineBranchName }}
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/github-script@v6
33+
with:
34+
github-token: ${{secrets.GITHUB_TOKEN}}
35+
script: |
36+
const pulls = await github.paginate('GET /repos/:owner/:repo/pulls', {
37+
owner: context.repo.owner,
38+
repo: context.repo.repo
39+
});
40+
const branchRegExp = new RegExp(`${{github.event.inputs.branchExpression}}`);
41+
let branchesAndPRStrings = [];
42+
let baseBranch = null;
43+
let baseBranchSHA = null;
44+
for (const pull of pulls) {
45+
const branch = pull['head']['ref'];
46+
console.log('Pull for branch: ' + branch);
47+
if (branchRegExp.test(branch)) {
48+
console.log('Branch matched prefix: ' + branch);
49+
let statusOK = true;
50+
if(${{ github.event.inputs.mustBeGreen }}) {
51+
console.log('Checking green status: ' + branch);
52+
const stateQuery = `query($owner: String!, $repo: String!, $pull_number: Int!) {
53+
repository(owner: $owner, name: $repo) {
54+
pullRequest(number:$pull_number) {
55+
commits(last: 1) {
56+
nodes {
57+
commit {
58+
statusCheckRollup {
59+
state
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}
66+
}`
67+
const vars = {
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
pull_number: pull['number']
71+
};
72+
const result = await github.graphql(stateQuery, vars);
73+
const [{ commit }] = result.repository.pullRequest.commits.nodes;
74+
const state = commit.statusCheckRollup.state
75+
console.log('Validating status: ' + state);
76+
if(state != 'SUCCESS') {
77+
console.log('Discarding ' + branch + ' with status ' + state);
78+
statusOK = false;
79+
}
80+
}
81+
console.log('Checking labels: ' + branch);
82+
const labels = pull['labels'];
83+
for(const label of labels) {
84+
const labelName = label['name'];
85+
console.log('Checking label: ' + labelName);
86+
if(labelName == '${{ github.event.inputs.ignoreLabel }}') {
87+
console.log('Discarding ' + branch + ' with label ' + labelName);
88+
statusOK = false;
89+
}
90+
}
91+
if (statusOK) {
92+
console.log('Adding branch to array: ' + branch);
93+
const prString = '#' + pull['number'] + ' ' + pull['title'];
94+
branchesAndPRStrings.push({ branch, prString });
95+
baseBranch = pull['base']['ref'];
96+
baseBranchSHA = pull['base']['sha'];
97+
}
98+
}
99+
}
100+
if (branchesAndPRStrings.length == 0) {
101+
core.setFailed('No PRs/branches matched criteria');
102+
return;
103+
}
104+
if (branchesAndPRStrings.length == 1) {
105+
core.setFailed('Only one PR/branch matched criteria');
106+
return;
107+
}
108+
109+
try {
110+
await github.rest.git.createRef({
111+
owner: context.repo.owner,
112+
repo: context.repo.repo,
113+
ref: 'refs/heads/' + '${{ github.event.inputs.combineBranchName }}',
114+
sha: baseBranchSHA
115+
});
116+
} catch (error) {
117+
console.log(error);
118+
core.setFailed('Failed to create combined branch - maybe a branch by that name already exists?');
119+
return;
120+
}
121+
122+
let combinedPRs = [];
123+
let mergeFailedPRs = [];
124+
for(const { branch, prString } of branchesAndPRStrings) {
125+
try {
126+
await github.rest.repos.merge({
127+
owner: context.repo.owner,
128+
repo: context.repo.repo,
129+
base: '${{ github.event.inputs.combineBranchName }}',
130+
head: branch,
131+
});
132+
console.log('Merged branch ' + branch);
133+
combinedPRs.push(prString);
134+
} catch (error) {
135+
console.log('Failed to merge branch ' + branch);
136+
mergeFailedPRs.push(prString);
137+
}
138+
}
139+
140+
console.log('Creating combined PR');
141+
const combinedPRsString = combinedPRs.join('\n');
142+
let body = '⛙ Combined PRs:\n' + combinedPRsString;
143+
if(mergeFailedPRs.length > 0) {
144+
const mergeFailedPRsString = mergeFailedPRs.join('\n');
145+
body += '\n\n⚠️ The following PRs were left out due to merge conflicts:\n' + mergeFailedPRsString
146+
}
147+
await github.rest.pulls.create({
148+
owner: context.repo.owner,
149+
repo: context.repo.repo,
150+
title: '⛙ ${{github.event.inputs.combineTitle}}',
151+
head: '${{ github.event.inputs.combineBranchName }}',
152+
base: baseBranch,
153+
body: body
154+
});

.github/workflows/release-notes.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ jobs:
4242
env:
4343
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4444
run: |
45-
$id = iwr "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/releases/tags/$env:CURRENT_TAG" |
45+
$headers = @{ 'Accept'='application/vnd.github.v3+json;charset=utf-8'; 'Authorization' = "bearer $env:GITHUB_TOKEN" }
46+
$id = iwr "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/releases/tags/$env:CURRENT_TAG" -Headers $headers |
4647
select -ExpandProperty Content |
4748
ConvertFrom-Json |
4849
select -ExpandProperty id
4950
5051
$notes = (Get-Content .\changelog.md | where { !($_ -like '\*') } | %{ $_.replace('\', '\\').replace('"', "'").replace('undefined', 'un-defined') }) -join '\n'
51-
$headers = @{ 'Accept'='application/vnd.github.v3+json;charset=utf-8'; 'Authorization' = "bearer $env:GITHUB_TOKEN" }
5252
$body = '{ "body":"' + $notes + '" }'
5353
5454
# ensure we can convert to json

.netconfig

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
skip
4848
[file ".github/workflows/build.yml"]
4949
url = https://github.com/devlooped/oss/blob/main/.github/workflows/build.yml
50-
sha = 391da5ef9fd53167f053600239ab79f5f5030d51
51-
etag = 118c1f063f38a157a458337f61dee7a74cb58a3d7960df5566af7d8a24f64206
50+
sha = cf8e33983b111d06b8e3a89fce5d8b8d97750f59
51+
etag = 546728274c46d85038c67a385df421cb8865552673ada35fcf0b30ff4f1c7548
5252
weak
5353
[file ".github/workflows/changelog.yml"]
5454
url = https://github.com/devlooped/oss/blob/main/.github/workflows/changelog.yml
@@ -67,8 +67,8 @@
6767
weak
6868
[file ".github/workflows/release-notes.yml"]
6969
url = https://github.com/devlooped/oss/blob/main/.github/workflows/release-notes.yml
70-
sha = be8f625e4cf5c2c572c7e56ba6dc4c4935ab0c00
71-
etag = d1de9cb9c403ed8632d22d4cc153ae63b075266b9ce638b9ac73fd47dd2bccc1
70+
sha = a922d0300a188bbd872bcf8ca48c6b7a13dee5df
71+
etag = 5db902d761d80de182417cfbece00cbb6d1fa4b99a945b3a97c57f58f7043b5d
7272
weak
7373
[file ".gitignore"]
7474
url = https://github.com/devlooped/oss/blob/main/.gitignore
@@ -158,3 +158,8 @@
158158
sha = e347e5c7b91aaeb11eff95037c2c0b54206cc976
159159
etag = 06319ff741c03cf4cd5113926d490ec09999a85b5a0e0480ce44222db026341a
160160
weak
161+
[file ".github/workflows/combine-prs.yml"]
162+
url = https://github.com/devlooped/oss/blob/main/.github/workflows/combine-prs.yml
163+
sha = 74189b061850a3527676d76281de61044abc86a2
164+
etag = 10106929413a89658d22c36b5b934c598809e1deb8cdd994ec846f824195aac6
165+
weak

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ The versioning scheme for packages is:
359359
[![Kirill Osenkov](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/KirillOsenkov.png "Kirill Osenkov")](https://github.com/KirillOsenkov)
360360
[![MFB Technologies, Inc.](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/MFB-Technologies-Inc.png "MFB Technologies, Inc.")](https://github.com/MFB-Technologies-Inc)
361361
[![SandRock](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/sandrock.png "SandRock")](https://github.com/sandrock)
362-
[![Eric C](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/eeseewy.png "Eric C")](https://github.com/eeseewy)
363362
[![Andy Gocke](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/agocke.png "Andy Gocke")](https://github.com/agocke)
363+
[![Shahzad Huq](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/shahzadhuq.png "Shahzad Huq")](https://github.com/shahzadhuq)
364364

365365

366366
<!-- sponsors.md -->

0 commit comments

Comments
 (0)