Skip to content

Merge group support #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ clean:
npm run clean

.PHONY: install
install:
install:
npm install

.PHONY: build
build:
build:
npm run build

.PHONY: test
Expand All @@ -21,12 +21,12 @@ coverage: build
npm run coverage

.PHONY: all
all:
all:
npm run all

.PHONY: release
release: all
npm prune --production
npm prune --production

.PHONY: semantic-release
semantic-release:
Expand Down Expand Up @@ -58,4 +58,4 @@ tag-major: check-version
check-version:
ifndef VERSION
$(error VERSION not defined)
endif
endif
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ A simple Github Action that allows us to update the status of a commit.

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.

Currently the action supports `pull_request` and `push` events:
* When the event is `pull_request`, the action will set the status to the last commit in the pull request at the moment the workflow was triggered.
* When the event is `push`, the action will set the status to the last commit pushed at the moment the workflow was triggered.
Currently the action supports `pull_request`, `pull_request_target`, `merge_group`, and `push` events:

* 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.
* 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.

## Input Parameters

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

## Input Parameters specific to `pull_request` event

_These parameters are all optional and are used only for pull requests_
_These parameters are all optional and are used only for pull requests._

| Name | Description |
|---|---|
Expand All @@ -52,11 +53,11 @@ By default, if we don't add `permissions` to the workflow or the job, the action
* 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`
* If we want to add a comment we need to be sure the job (or the whole workflow) has the permissions: `pull-requests: write`

## Examples
## Examples

### Action sets push commit to pending status

```
```yaml
name: Test

on: [push]
Expand All @@ -71,12 +72,12 @@ jobs:

### Action sets push commit to pending status with specific permissions

```
```yaml
name: Test

on: [push]

permissions:
permissions:
statuses: write

jobs:
Expand All @@ -87,10 +88,9 @@ jobs:
- uses: ouzi-dev/commit-status-updater@v2
```


### Action sets push commit to pending status with custom name

```
```yaml
name: Test

on: [push]
Expand All @@ -107,7 +107,7 @@ jobs:

### Action sets push commit to pending status on start, and updates check at the end of the workflow

```
```yaml
name: Test

on: [push]
Expand All @@ -126,7 +126,7 @@ jobs:

### Action sets pull request commit to pending status without comment

```
```yaml
name: Test

on: [pull_request]
Expand All @@ -141,7 +141,7 @@ jobs:

### Action sets pull request commit to error status without comment

```
```yaml
name: Test

on: [pull_request]
Expand All @@ -158,7 +158,7 @@ jobs:

### Action sets pull request commit to pending status with comment, and updates check and adds comment at the end of the workflow

```
```yaml
name: Test

on: [pull_request]
Expand All @@ -180,12 +180,12 @@ jobs:

### 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

```
```yaml
name: Test

on: [pull_request]

permissions:
permissions:
statuses: write
pull-requests: write

Expand All @@ -206,7 +206,7 @@ jobs:

### Action with custom hold comments

```
```yaml
name: Test

on: [pull_request]
Expand All @@ -224,10 +224,10 @@ jobs:
successComment: "action success!"
failComment: "action failed!"
```

### Action no comments, set commit to "error" status and set url, description and specific name

```
```yaml
name: Test

on: [pull_request]
Expand All @@ -247,7 +247,7 @@ jobs:

### Action with specific token and setting status check in commits in forks

```
```yaml
name: Test

on: [pull_request]
Expand All @@ -265,12 +265,12 @@ jobs:

## Integration with Prow

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.
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.
Using this actions you can tell tide to not skip optional contexts and effectively wait for a GitHub Workflow to pass before merging.

### Example with Tide

```
```yaml
tide:
context_options:
# Treat unknown contexts as required
Expand All @@ -279,4 +279,4 @@ tide:

## Development

__Important: Before pushing your changes run `make release` to generate all the correct files and clean stuff, etc...__
__Important: Before pushing your changes run `make release` to generate all the correct files and clean stuff, etc...__
24 changes: 20 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Code generated via make release - DO NOT EDIT


/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

Expand Down Expand Up @@ -60,7 +63,7 @@ class GithubHelper {
initialize() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
return __awaiter(this, void 0, void 0, function* () {
if (github_1.context.eventName === 'pull_request') {
if (['pull_request', 'pull_request_target'].includes(github_1.context.eventName)) {
this.isPR = true;
this.owner = (_e = (_d = (_c = (_b = (_a = github_1.context.payload) === null || _a === void 0 ? void 0 : _a.pull_request) === null || _b === void 0 ? void 0 : _b.head) === null || _c === void 0 ? void 0 : _c.repo) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.login;
this.repo = (_j = (_h = (_g = (_f = github_1.context.payload) === null || _f === void 0 ? void 0 : _f.pull_request) === null || _g === void 0 ? void 0 : _g.head) === null || _h === void 0 ? void 0 : _h.repo) === null || _j === void 0 ? void 0 : _j.name;
Expand All @@ -71,7 +74,7 @@ class GithubHelper {
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;
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;
}
if (github_1.context.eventName === 'push') {
if (['push', 'merge_group'].includes(github_1.context.eventName)) {
this.isPR = false;
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;
this.repo = (_11 = (_10 = github_1.context.payload) === null || _10 === void 0 ? void 0 : _10.repository) === null || _11 === void 0 ? void 0 : _11.name;
Expand Down Expand Up @@ -105,7 +108,18 @@ class GithubHelper {
core.info(`Updated build status: ${params.status}`);
}
catch (error) {
throw new Error(`error while setting context status: ${error.message}`);
/*
There is a point where a merge group has been merged and checks
may be re-run, where this status update does not appear possible
from some context/state reason that is not clear.
Therefore we try to sidestep this a bit and either allow this to
pass or fail without actually updating anything.
*/
const SUCCESS = 'success';
core.warning(`Unable to properly update build status: ${params.status}`);
if (params.status !== SUCCESS) {
throw new Error(`Check ended with status: ${params.status}`);
}
}
});
}
Expand Down Expand Up @@ -455,8 +469,10 @@ const github = __importStar(__nccwpck_require__(5438));
function validateEventType() {
return __awaiter(this, void 0, void 0, function* () {
if (github.context.eventName !== 'pull_request' &&
github.context.eventName !== 'pull_request_target' &&
github.context.eventName !== 'merge_group' &&
github.context.eventName !== 'push') {
throw new Error('Error, action only works for pull_request or push events!');
throw new Error('Error, action only works for pull_request, pull_request_target, merge_group or push events!');
}
});
}
Expand Down
Loading