Skip to content

Commit a794d78

Browse files
author
Sean P. Kane
committed
Add merge_group support
1 parent 113b427 commit a794d78

File tree

7 files changed

+68
-42
lines changed

7 files changed

+68
-42
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ clean:
55
npm run clean
66

77
.PHONY: install
8-
install:
8+
install:
99
npm install
1010

1111
.PHONY: build
12-
build:
12+
build:
1313
npm run build
1414

1515
.PHONY: test
@@ -21,12 +21,12 @@ coverage: build
2121
npm run coverage
2222

2323
.PHONY: all
24-
all:
24+
all:
2525
npm run all
2626

2727
.PHONY: release
2828
release: all
29-
npm prune --production
29+
npm prune --production
3030

3131
.PHONY: semantic-release
3232
semantic-release:
@@ -58,4 +58,4 @@ tag-major: check-version
5858
check-version:
5959
ifndef VERSION
6060
$(error VERSION not defined)
61-
endif
61+
endif

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ A simple Github Action that allows us to update the status of a commit.
99

1010
GitHub does not update the status of a commit when running workflow and therefore tools that rely on the context/status of a given commit are not compatible with it.
1111

12-
Currently the action supports `pull_request`, `pull_request_target` and `push` events:
12+
Currently the action supports `pull_request`, `pull_request_target`, `merge_group`, and `push` events:
13+
1314
* When the event is `pull_request` or `pull_request_target`, the action will set the status to the last commit in the pull request at the moment the workflow was triggered.
14-
* When the event is `push`, the action will set the status to the last commit pushed at the moment the workflow was triggered.
15+
* When the event is `push` or `merge_group`, the action will set the status to the last commit pushed at the moment the workflow was triggered.
1516

1617
## Input Parameters
1718

@@ -35,7 +36,7 @@ If set to `error` it will set status commit `error`.
3536

3637
## Input Parameters specific to `pull_request` event
3738

38-
_These parameters are all optional and are used only for pull requests_
39+
_These parameters are all optional and are used only for pull requests._
3940

4041
| Name | Description |
4142
|---|---|
@@ -52,11 +53,11 @@ By default, if we don't add `permissions` to the workflow or the job, the action
5253
* If we just want to set the status commit we need to be sure the job (or the whole workflow) has the permission: `statuses: write`
5354
* If we want to add a comment we need to be sure the job (or the whole workflow) has the permissions: `pull-requests: write`
5455

55-
## Examples
56+
## Examples
5657

5758
### Action sets push commit to pending status
5859

59-
```
60+
```yaml
6061
name: Test
6162

6263
on: [push]
@@ -71,12 +72,12 @@ jobs:
7172
7273
### Action sets push commit to pending status with specific permissions
7374
74-
```
75+
```yaml
7576
name: Test
7677

7778
on: [push]
7879

79-
permissions:
80+
permissions:
8081
statuses: write
8182

8283
jobs:
@@ -87,10 +88,9 @@ jobs:
8788
- uses: ouzi-dev/commit-status-updater@v2
8889
```
8990
90-
9191
### Action sets push commit to pending status with custom name
9292
93-
```
93+
```yaml
9494
name: Test
9595

9696
on: [push]
@@ -107,7 +107,7 @@ jobs:
107107
108108
### Action sets push commit to pending status on start, and updates check at the end of the workflow
109109
110-
```
110+
```yaml
111111
name: Test
112112

113113
on: [push]
@@ -126,7 +126,7 @@ jobs:
126126
127127
### Action sets pull request commit to pending status without comment
128128
129-
```
129+
```yaml
130130
name: Test
131131

132132
on: [pull_request]
@@ -141,7 +141,7 @@ jobs:
141141
142142
### Action sets pull request commit to error status without comment
143143
144-
```
144+
```yaml
145145
name: Test
146146

147147
on: [pull_request]
@@ -158,7 +158,7 @@ jobs:
158158
159159
### Action sets pull request commit to pending status with comment, and updates check and adds comment at the end of the workflow
160160
161-
```
161+
```yaml
162162
name: Test
163163

164164
on: [pull_request]
@@ -180,12 +180,12 @@ jobs:
180180
181181
### Action sets pull request commit to pending status with comment, and updates check and adds comment at the end of the workflow with specific permissions
182182
183-
```
183+
```yaml
184184
name: Test
185185

186186
on: [pull_request]
187187

188-
permissions:
188+
permissions:
189189
statuses: write
190190
pull-requests: write
191191

@@ -206,7 +206,7 @@ jobs:
206206
207207
### Action with custom hold comments
208208
209-
```
209+
```yaml
210210
name: Test
211211

212212
on: [pull_request]
@@ -224,10 +224,10 @@ jobs:
224224
successComment: "action success!"
225225
failComment: "action failed!"
226226
```
227-
227+
228228
### Action no comments, set commit to "error" status and set url, description and specific name
229229
230-
```
230+
```yaml
231231
name: Test
232232

233233
on: [pull_request]
@@ -247,7 +247,7 @@ jobs:
247247
248248
### Action with specific token and setting status check in commits in forks
249249
250-
```
250+
```yaml
251251
name: Test
252252

253253
on: [pull_request]
@@ -265,12 +265,12 @@ jobs:
265265
266266
## Integration with Prow
267267
268-
An example is [Prow](https://github.com/kubernetes/test-infra/tree/master/prow#readme) which uses the Github Status API to read the status of a given commit.
268+
An example is [Prow](https://github.com/kubernetes/test-infra/tree/master/prow#readme) which uses the Github Status API to read the status of a given commit.
269269
Using this actions you can tell tide to not skip optional contexts and effectively wait for a GitHub Workflow to pass before merging.
270270
271271
### Example with Tide
272272
273-
```
273+
```yaml
274274
tide:
275275
context_options:
276276
# Treat unknown contexts as required

dist/index.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code generated via make release - DO NOT EDIT
2+
3+
14
/******/ (() => { // webpackBootstrap
25
/******/ var __webpack_modules__ = ({
36

@@ -71,7 +74,7 @@ class GithubHelper {
7174
this.baseOwner = (_2 = (_1 = (_0 = (_z = (_y = github_1.context.payload) === null || _y === void 0 ? void 0 : _y.pull_request) === null || _z === void 0 ? void 0 : _z.base) === null || _0 === void 0 ? void 0 : _0.repo) === null || _1 === void 0 ? void 0 : _1.owner) === null || _2 === void 0 ? void 0 : _2.login;
7275
this.baseRepoName = (_6 = (_5 = (_4 = (_3 = github_1.context.payload) === null || _3 === void 0 ? void 0 : _3.pull_request) === null || _4 === void 0 ? void 0 : _4.base) === null || _5 === void 0 ? void 0 : _5.repo) === null || _6 === void 0 ? void 0 : _6.name;
7376
}
74-
if (github_1.context.eventName === 'push') {
77+
if (['push', 'merge_group'].includes(github_1.context.eventName)) {
7578
this.isPR = false;
7679
this.owner = (_9 = (_8 = (_7 = github_1.context.payload) === null || _7 === void 0 ? void 0 : _7.repository) === null || _8 === void 0 ? void 0 : _8.owner) === null || _9 === void 0 ? void 0 : _9.login;
7780
this.repo = (_11 = (_10 = github_1.context.payload) === null || _10 === void 0 ? void 0 : _10.repository) === null || _11 === void 0 ? void 0 : _11.name;
@@ -105,7 +108,18 @@ class GithubHelper {
105108
core.info(`Updated build status: ${params.status}`);
106109
}
107110
catch (error) {
108-
throw new Error(`error while setting context status: ${error.message}`);
111+
/*
112+
There is a point where a merge group has been merged and checks
113+
may be re-run, where this status update does not appear possible
114+
from some context/state reason that is not clear.
115+
Therefore we try to sidestep this a bit and either allow this to
116+
pass or fail without actually updating anything.
117+
*/
118+
const SUCCESS = 'success';
119+
core.warning(`Unable to properly update build status: ${params.status}`);
120+
if (params.status !== SUCCESS) {
121+
throw new Error(`Check ended with status: ${params.status}`);
122+
}
109123
}
110124
});
111125
}
@@ -456,8 +470,9 @@ function validateEventType() {
456470
return __awaiter(this, void 0, void 0, function* () {
457471
if (github.context.eventName !== 'pull_request' &&
458472
github.context.eventName !== 'pull_request_target' &&
473+
github.context.eventName !== 'merge_group' &&
459474
github.context.eventName !== 'push') {
460-
throw new Error('Error, action only works for pull_request, pull_request_target or push events!');
475+
throw new Error('Error, action only works for pull_request, pull_request_target, merge_group or push events!');
461476
}
462477
});
463478
}

package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"format": "prettier --write **/*.ts",
1010
"format-check": "prettier --check **/*.ts",
1111
"lint": "eslint src/**/*.ts",
12-
"pack": "ncc build",
12+
"pack": "ncc build && mv dist/index.js dist/index.js.tmp && echo '// Code generated via make release - DO NOT EDIT\n\n' > dist/index.js && cat dist/index.js.tmp >> dist/index.js && rm -f dist/index.js.tmp",
1313
"test": "jest",
1414
"coverage": "jest --coverage=true",
1515
"clean": "rm -rf node_modules && rm -rf lib && rm -rf coverage && rm -rf dist",
@@ -51,7 +51,7 @@
5151
"@semantic-release/exec": "^6.0.3",
5252
"@semantic-release/github": "^8.0.6",
5353
"@semantic-release/release-notes-generator": "^10.0.3",
54-
"@types/jest": "^29.2.0",
54+
"@types/jest": "^29.5.14",
5555
"@types/node": "^18.11.2",
5656
"@types/uuid": "^8.3.4",
5757
"@typescript-eslint/eslint-plugin": "^5.40.1",

src/githubHelper.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ class GithubHelper {
3434
}
3535

3636
private async initialize(): Promise<void> {
37-
if (['pull_request', 'pull_request_target'].includes(context.eventName)) {
37+
if (
38+
['pull_request', 'pull_request_target'].includes(
39+
context.eventName
40+
)
41+
) {
3842
this.isPR = true
3943
this.owner = context.payload?.pull_request?.head?.repo?.owner?.login
4044
this.repo = context.payload?.pull_request?.head?.repo?.name
@@ -46,7 +50,11 @@ class GithubHelper {
4650
this.baseRepoName = context.payload?.pull_request?.base?.repo?.name
4751
}
4852

49-
if (context.eventName === 'push') {
53+
if (
54+
['push', 'merge_group'].includes(
55+
context.eventName
56+
)
57+
) {
5058
this.isPR = false
5159
this.owner = context.payload?.repository?.owner?.login
5260
this.repo = context.payload?.repository?.name
@@ -74,8 +82,9 @@ class GithubHelper {
7482
state: params.status,
7583
target_url: params.url
7684
})
77-
core.info(`Updated build status: ${params.status}`)
85+
core.info(`Updated build status for ${params.name}: ${params.status}`)
7886
} catch (error) {
87+
core.warning(`Unable to properly update build status for ${params.name}: ${params.status}`)
7988
throw new Error(
8089
`error while setting context status: ${(error as Error).message}`
8190
)

src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ export async function validateEventType(): Promise<void> {
44
if (
55
github.context.eventName !== 'pull_request' &&
66
github.context.eventName !== 'pull_request_target' &&
7+
github.context.eventName !== 'merge_group' &&
78
github.context.eventName !== 'push'
89
) {
910
throw new Error(
10-
'Error, action only works for pull_request, pull_request_target or push events!'
11+
'Error, action only works for pull_request, pull_request_target, merge_group or push events!'
1112
)
1213
}
1314
}

0 commit comments

Comments
 (0)