Skip to content

Commit 0a8f661

Browse files
authored
major: update dependencies and node (#521)
* 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
1 parent 3870873 commit 0a8f661

File tree

14 files changed

+28132
-39374
lines changed

14 files changed

+28132
-39374
lines changed

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"project": "./tsconfig.json"
1414
},
1515
"rules": {
16+
"filenames/match-regex": "off",
17+
"i18n-text/no-en": "off",
18+
"no-console": "off",
1619
"object-shorthand": [
1720
2,
1821
"consistent"

.github/workflows/pull_request.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ name: PR Build and test
22

33
on: [pull_request]
44

5+
permissions:
6+
statuses: write
7+
pull-requests: write
8+
59
jobs:
610
build:
711
runs-on: ubuntu-latest
812
steps:
9-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1014
- uses: ./
1115
with:
1216
addHoldComment: "true"
@@ -23,3 +27,4 @@ jobs:
2327
with:
2428
addHoldComment: "true"
2529
status: "${{ job.status }}"
30+

.github/workflows/push.yml renamed to .github/workflows/release.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and test
1+
name: Release commit-status-updater
22

33
on:
44
push:
@@ -11,7 +11,9 @@ jobs:
1111
env:
1212
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
1517
- uses: ./
1618
with:
1719
name: "release"

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,17 @@ install-npm-check-updates:
4444
.PHONY: update-dependencies
4545
update-dependencies: install-npm-check-updates
4646
ncu -u
47-
npm install
47+
npm install
48+
49+
.PHONY: tag-major
50+
tag-major: check-version
51+
$(eval TAG := $(call split-by-dot,$(VERSION),1))
52+
@echo "Tagging major version $(TAG)"
53+
git tag -f $(TAG)
54+
git push -f origin $(TAG)
55+
56+
.PHONY: check-version
57+
check-version:
58+
ifndef VERSION
59+
$(error VERSION not defined)
60+
endif

README.md

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ _These parameters are all optional and are used only for pull requests_
4545
| `successComment` | Default is `/hold cancel`. This is the message to add to the pull request when the status is `success`. |
4646
| `failComment` | Default is `/hold`. This is the message to add to the pull request when the status is `failure`, `error` or `cancelled`. |
4747

48+
## Workflow permissions
49+
50+
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:
51+
52+
* 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`
53+
* If we want to add a comment we need to be sure the job (or the whole workflow) has the permissions: `pull-requests: write`
54+
4855
## Examples
4956

5057
### Action sets push commit to pending status
@@ -58,10 +65,29 @@ jobs:
5865
build:
5966
runs-on: ubuntu-latest
6067
steps:
61-
- uses: actions/checkout@v2
62-
- uses: ouzi-dev/commit-status-updater@v1.1.0
68+
- uses: actions/checkout@v3
69+
- uses: ouzi-dev/commit-status-updater@v2
70+
```
71+
72+
### Action sets push commit to pending status with specific permissions
73+
74+
```
75+
name: Test
76+
77+
on: [push]
78+
79+
permissions:
80+
statuses: write
81+
82+
jobs:
83+
build:
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v3
87+
- uses: ouzi-dev/commit-status-updater@v2
6388
```
6489

90+
6591
### Action sets push commit to pending status with custom name
6692

6793
```
@@ -73,8 +99,8 @@ jobs:
7399
build:
74100
runs-on: ubuntu-latest
75101
steps:
76-
- uses: actions/checkout@v2
77-
- uses: ouzi-dev/commit-status-updater@v1.1.0
102+
- uses: actions/checkout@v3
103+
- uses: ouzi-dev/commit-status-updater@v2
78104
with:
79105
name: "name of my status check"
80106
```
@@ -90,10 +116,10 @@ jobs:
90116
build:
91117
runs-on: ubuntu-latest
92118
steps:
93-
- uses: actions/checkout@v2
94-
- uses: ouzi-dev/commit-status-updater@v1.1.0
119+
- uses: actions/checkout@v3
120+
- uses: ouzi-dev/commit-status-updater@v2
95121
- if: always()
96-
uses: ouzi-dev/commit-status-updater@v1.1.0
122+
uses: ouzi-dev/commit-status-updater@v2
97123
with:
98124
status: "${{ job.status }}"
99125
```
@@ -109,8 +135,8 @@ jobs:
109135
build:
110136
runs-on: ubuntu-latest
111137
steps:
112-
- uses: actions/checkout@v2
113-
- uses: ouzi-dev/commit-status-updater@v1.1.0
138+
- uses: actions/checkout@v3
139+
- uses: ouzi-dev/commit-status-updater@v2
114140
```
115141

116142
### Action sets pull request commit to error status without comment
@@ -124,8 +150,8 @@ jobs:
124150
build:
125151
runs-on: ubuntu-latest
126152
steps:
127-
- uses: actions/checkout@v2
128-
- uses: ouzi-dev/commit-status-updater@v1.1.0
153+
- uses: actions/checkout@v3
154+
- uses: ouzi-dev/commit-status-updater@v2
129155
with:
130156
status: "error"
131157
```
@@ -141,12 +167,38 @@ jobs:
141167
build:
142168
runs-on: ubuntu-latest
143169
steps:
144-
- uses: actions/checkout@v2
145-
- uses: ouzi-dev/commit-status-updater@v1.1.0
170+
- uses: actions/checkout@v3
171+
- uses: ouzi-dev/commit-status-updater@v2
172+
with:
173+
addHoldComment: "true"
174+
- if: always()
175+
uses: ouzi-dev/commit-status-updater@v2
176+
with:
177+
addHoldComment: "true"
178+
status: "${{ job.status }}"
179+
```
180+
181+
### 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
182+
183+
```
184+
name: Test
185+
186+
on: [pull_request]
187+
188+
permissions:
189+
statuses: write
190+
pull-requests: write
191+
192+
jobs:
193+
build:
194+
runs-on: ubuntu-latest
195+
steps:
196+
- uses: actions/checkout@v3
197+
- uses: ouzi-dev/commit-status-updater@v2
146198
with:
147199
addHoldComment: "true"
148200
- if: always()
149-
uses: ouzi-dev/commit-status-updater@v1.1.0
201+
uses: ouzi-dev/commit-status-updater@v2
150202
with:
151203
addHoldComment: "true"
152204
status: "${{ job.status }}"
@@ -163,8 +215,8 @@ jobs:
163215
build:
164216
runs-on: ubuntu-latest
165217
steps:
166-
- uses: actions/checkout@v2
167-
- uses: ouzi-dev/commit-status-updater@v1.1.0
218+
- uses: actions/checkout@v3
219+
- uses: ouzi-dev/commit-status-updater@v2
168220
with:
169221
status: "pending"
170222
addHoldComment: "true"
@@ -184,8 +236,8 @@ jobs:
184236
build:
185237
runs-on: ubuntu-latest
186238
steps:
187-
- uses: actions/checkout@v2
188-
- uses: ouzi-dev/commit-status-updater@v1.1.0
239+
- uses: actions/checkout@v3
240+
- uses: ouzi-dev/commit-status-updater@v2
189241
with:
190242
status: "error"
191243
url: http://myurl.io/
@@ -204,8 +256,8 @@ jobs:
204256
build:
205257
runs-on: ubuntu-latest
206258
steps:
207-
- uses: actions/checkout@v2
208-
- uses: ouzi-dev/commit-status-updater@v1.1.0
259+
- uses: actions/checkout@v3
260+
- uses: ouzi-dev/commit-status-updater@v2
209261
with:
210262
token: "my_custom_token"
211263
ignoreForks: "false"

__test__/runner.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('runner tests', () => {
3737
})
3838

3939
it('on push run sets status', async () => {
40-
const params = ({} as unknown) as IParams
40+
const params = {} as unknown as IParams
4141
params.token = 'bleh'
4242
params.ignoreForks = true
4343
params.addHoldComment = true
@@ -55,7 +55,7 @@ describe('runner tests', () => {
5555
})
5656

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

7070
expect(mockUtils.validateEventType).toHaveBeenCalled()
7171
expect(mockIGithubHelper.setStatus).toHaveBeenCalledWith(params)
72-
expect(mockIGithubHelper.addComment).toHaveBeenCalledWith('my comment')
72+
expect(mockIGithubHelper.addComment).toHaveBeenCalledWith(
73+
'bleh',
74+
'my comment'
75+
)
7376
})
7477

7578
it('on PR run sets status and no comment', async () => {
76-
const params = ({} as unknown) as IParams
79+
const params = {} as unknown as IParams
7780
params.token = 'bleh'
7881
params.ignoreForks = true
7982
params.addHoldComment = false
@@ -91,7 +94,7 @@ describe('runner tests', () => {
9194
})
9295

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

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

129132
it('on PR run sets status if ignore fork false', async () => {
130-
const params = ({} as unknown) as IParams
133+
const params = {} as unknown as IParams
131134
params.token = 'bleh'
132135
params.ignoreForks = false
133136
params.addHoldComment = true

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ inputs:
6565
Will be used only for pull requests.
6666
default: "/hold"
6767
runs:
68-
using: node12
68+
using: node16
6969
main: dist/index.js

0 commit comments

Comments
 (0)