Skip to content

Commit

Permalink
major: update dependencies and node (#521)
Browse files Browse the repository at this point in the history
* major: update dependencies and node - test

* fix: trigger action

* fix: test action

* fix: print params to debug error

* fix: add correct object to rest call

* fix: prepare octokit before the call

* fix: remove logs and test workflow default permissions

* fix: test more permissions

* fix: test workflow permissions

* fix: test permissions

* fix: updated dependencies

* fix: update major tag automatically on release

* fix: rename release workflow
  • Loading branch information
belitre authored Oct 20, 2022
1 parent 3870873 commit 0a8f661
Show file tree
Hide file tree
Showing 14 changed files with 28,132 additions and 39,374 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"project": "./tsconfig.json"
},
"rules": {
"filenames/match-regex": "off",
"i18n-text/no-en": "off",
"no-console": "off",
"object-shorthand": [
2,
"consistent"
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ name: PR Build and test

on: [pull_request]

permissions:
statuses: write
pull-requests: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./
with:
addHoldComment: "true"
Expand All @@ -23,3 +27,4 @@ jobs:
with:
addHoldComment: "true"
status: "${{ job.status }}"

6 changes: 4 additions & 2 deletions .github/workflows/push.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and test
name: Release commit-status-updater

on:
push:
Expand All @@ -11,7 +11,9 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ./
with:
name: "release"
Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,17 @@ install-npm-check-updates:
.PHONY: update-dependencies
update-dependencies: install-npm-check-updates
ncu -u
npm install
npm install

.PHONY: tag-major
tag-major: check-version
$(eval TAG := $(call split-by-dot,$(VERSION),1))
@echo "Tagging major version $(TAG)"
git tag -f $(TAG)
git push -f origin $(TAG)

.PHONY: check-version
check-version:
ifndef VERSION
$(error VERSION not defined)
endif
92 changes: 72 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ _These parameters are all optional and are used only for pull requests_
| `successComment` | Default is `/hold cancel`. This is the message to add to the pull request when the status is `success`. |
| `failComment` | Default is `/hold`. This is the message to add to the pull request when the status is `failure`, `error` or `cancelled`. |

## Workflow permissions

By default, if we don't add `permissions` to the workflow or the job, the action will be able to set the status commit and add comments. But if we set any permissions for the workflow/job, then we need to be sure we provide the correct ones for 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

### Action sets push commit to pending status
Expand All @@ -58,10 +65,29 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ouzi-dev/commit-status-updater@v1.1.0
- uses: actions/checkout@v3
- uses: ouzi-dev/commit-status-updater@v2
```

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

```
name: Test
on: [push]
permissions:
statuses: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ouzi-dev/commit-status-updater@v2
```


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

```
Expand All @@ -73,8 +99,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ouzi-dev/commit-status-updater@v1.1.0
- uses: actions/checkout@v3
- uses: ouzi-dev/commit-status-updater@v2
with:
name: "name of my status check"
```
Expand All @@ -90,10 +116,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ouzi-dev/commit-status-updater@v1.1.0
- uses: actions/checkout@v3
- uses: ouzi-dev/commit-status-updater@v2
- if: always()
uses: ouzi-dev/commit-status-updater@v1.1.0
uses: ouzi-dev/commit-status-updater@v2
with:
status: "${{ job.status }}"
```
Expand All @@ -109,8 +135,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ouzi-dev/commit-status-updater@v1.1.0
- uses: actions/checkout@v3
- uses: ouzi-dev/commit-status-updater@v2
```

### Action sets pull request commit to error status without comment
Expand All @@ -124,8 +150,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ouzi-dev/commit-status-updater@v1.1.0
- uses: actions/checkout@v3
- uses: ouzi-dev/commit-status-updater@v2
with:
status: "error"
```
Expand All @@ -141,12 +167,38 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ouzi-dev/commit-status-updater@v1.1.0
- uses: actions/checkout@v3
- uses: ouzi-dev/commit-status-updater@v2
with:
addHoldComment: "true"
- if: always()
uses: ouzi-dev/commit-status-updater@v2
with:
addHoldComment: "true"
status: "${{ job.status }}"
```

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

```
name: Test
on: [pull_request]
permissions:
statuses: write
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ouzi-dev/commit-status-updater@v2
with:
addHoldComment: "true"
- if: always()
uses: ouzi-dev/commit-status-updater@v1.1.0
uses: ouzi-dev/commit-status-updater@v2
with:
addHoldComment: "true"
status: "${{ job.status }}"
Expand All @@ -163,8 +215,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ouzi-dev/commit-status-updater@v1.1.0
- uses: actions/checkout@v3
- uses: ouzi-dev/commit-status-updater@v2
with:
status: "pending"
addHoldComment: "true"
Expand All @@ -184,8 +236,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ouzi-dev/commit-status-updater@v1.1.0
- uses: actions/checkout@v3
- uses: ouzi-dev/commit-status-updater@v2
with:
status: "error"
url: http://myurl.io/
Expand All @@ -204,8 +256,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ouzi-dev/commit-status-updater@v1.1.0
- uses: actions/checkout@v3
- uses: ouzi-dev/commit-status-updater@v2
with:
token: "my_custom_token"
ignoreForks: "false"
Expand Down
17 changes: 10 additions & 7 deletions __test__/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('runner tests', () => {
})

it('on push run sets status', async () => {
const params = ({} as unknown) as IParams
const params = {} as unknown as IParams
params.token = 'bleh'
params.ignoreForks = true
params.addHoldComment = true
Expand All @@ -55,7 +55,7 @@ describe('runner tests', () => {
})

it('on PR run sets status and comment', async () => {
const params = ({} as unknown) as IParams
const params = {} as unknown as IParams
params.token = 'bleh'
params.ignoreForks = true
params.addHoldComment = true
Expand All @@ -69,11 +69,14 @@ describe('runner tests', () => {

expect(mockUtils.validateEventType).toHaveBeenCalled()
expect(mockIGithubHelper.setStatus).toHaveBeenCalledWith(params)
expect(mockIGithubHelper.addComment).toHaveBeenCalledWith('my comment')
expect(mockIGithubHelper.addComment).toHaveBeenCalledWith(
'bleh',
'my comment'
)
})

it('on PR run sets status and no comment', async () => {
const params = ({} as unknown) as IParams
const params = {} as unknown as IParams
params.token = 'bleh'
params.ignoreForks = true
params.addHoldComment = false
Expand All @@ -91,7 +94,7 @@ describe('runner tests', () => {
})

it('on PR run does not set status or comment', async () => {
const params = ({} as unknown) as IParams
const params = {} as unknown as IParams
params.token = 'bleh'
params.ignoreForks = true
params.addHoldComment = false
Expand All @@ -109,7 +112,7 @@ describe('runner tests', () => {
})

it('on PR run does not set status or comment when it is a fork and add comment enabled', async () => {
const params = ({} as unknown) as IParams
const params = {} as unknown as IParams
params.token = 'bleh'
params.ignoreForks = true
params.addHoldComment = true
Expand All @@ -127,7 +130,7 @@ describe('runner tests', () => {
})

it('on PR run sets status if ignore fork false', async () => {
const params = ({} as unknown) as IParams
const params = {} as unknown as IParams
params.token = 'bleh'
params.ignoreForks = false
params.addHoldComment = true
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ inputs:
Will be used only for pull requests.
default: "/hold"
runs:
using: node12
using: node16
main: dist/index.js
Loading

0 comments on commit 0a8f661

Please sign in to comment.