Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit faaa4d9

Browse files
authored
Merge pull request #10 from Sibz/releases/next
Releases/next
2 parents da0fa43 + b564c40 commit faaa4d9

11 files changed

Lines changed: 364 additions & 111 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: "smoke-screen-tests"
2+
on:
3+
push:
4+
branches-ignore:
5+
- master
6+
7+
jobs:
8+
sst:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- run: |
13+
npm install
14+
npm test

.github/workflows/test.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,34 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v2
13-
- name: Run the action
13+
- name: Test min args
1414
uses: ./
1515
with:
1616
authToken: ${{secrets.GITHUB_TOKEN}}
17-
context: 'Test run'
18-
description: 'Passed'
19-
state: 'success'
17+
state: 'success'
18+
- name: Test with all args except owner/repo (success)
19+
uses: ./
20+
with:
21+
authToken: ${{secrets.GITHUB_TOKEN}}
22+
context: "Test run"
23+
description: "Test with all args"
24+
target_url: "https://github.com/Sibz/github-status-action"
25+
sha: ${{github.event.pull_request.head.sha || github.sha}}
26+
state: 'success'
27+
- name: Test failing action
28+
uses: ./
29+
with:
30+
authToken: ${{secrets.GITHUB_TOKEN}}
31+
context: "Test run failed"
32+
description: "Failed test"
33+
sha: ${{github.event.pull_request.head.sha || github.sha}}
34+
state: 'failure'
35+
- name: Test failing action now succeeded
36+
uses: ./
37+
with:
38+
authToken: ${{secrets.GITHUB_TOKEN}}
39+
context: "Test run failed"
40+
description: "Failed test now succeeded"
41+
sha: ${{github.event.pull_request.head.sha || github.sha}}
42+
state: 'success'
43+

README.md

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,32 @@
44
<a href="https://github.com/Sibz/github-status-action"><img alt="github-status-action status" src="https://github.com/Sibz/github-status-action/workflows/build/badge.svg"></a>
55
</p>
66

7-
# Github Status Action
7+
# GitHub Status Action
88

99
Adds a status update to a commit. GitHub will always show the latest state of a context.
1010

1111
## Usage
1212

1313
### Inputs
14-
```yml
15-
authToken:
16-
description: 'Use secrets.GITHUB_TOKEN or your own token if you need to trigger other workflows the use "on: status"'
17-
required: true
18-
context:
19-
description: 'The context, this is displayed as the name of the check'
20-
required: true
21-
description:
22-
description: 'Short text explaining the status of the check'
23-
required: true
24-
state:
25-
description: 'The status of the check: success, error, failure or pending'
26-
required: true
27-
owner:
28-
description: 'Repostory onwer, defaults to context github.repository_owner if ommited'
29-
default: ${{ github.repository_owner }}
30-
repository:
31-
description: 'Repository, default to context github.repository if ommited'
32-
default: ${{ github.repository }}
33-
sha:
34-
description: 'SHA of commit to update status on, defaults to context github.sha'
35-
default: ${{ github.sha }}
36-
```
14+
15+
* `authToken` (required)
16+
Use secrets.GITHUB_TOKEN or your own token if you need to trigger other workflows that use "on: status"'
17+
* `state` (required)
18+
The status of the check should only be `success`, `error`, `failure` or `pending`
19+
* `context`
20+
The context, this is displayed as the name of the check
21+
* `description`
22+
Short text explaining the status of the check
23+
* `owner`
24+
Repostory onwer, defaults to context github.repository_owner if omited
25+
* `repository`
26+
Repository, default to context github.repository if omited
27+
* `sha`
28+
SHA of commit to update status on, defaults to context github.sha
29+
*If using `on: pull_request` use `github.event.pull_request.head.sha`*
30+
* `target_url`
31+
Url to use for the details link. If omited no link is shown.
32+
3733
### Outputs
3834
None.
3935

@@ -58,4 +54,5 @@ on: # run on any PRs and main branch changes
5854
context: 'Test run'
5955
description: 'Passed'
6056
state: 'success'
57+
sha: ${{github.event.pull_request.head.sha || github.sha}}
6158
```
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import test from 'ava';
2+
import makeStatusRequest, { CoreActionsForTesting, CommitState, ERR_INVALID_OWNER, ERR_INVALID_STATE} from '../src/makeStatusRequest'
3+
import inputNames from '../src/inputNames'
4+
5+
const INPUT_CONTEXT = "test context";
6+
const INPUT_OWNER = "TestOwner";
7+
const INPUT_OWNER_INVALID = "-TestOwner";
8+
const INPUT_REPOSITORY = "Test.Repository-1";
9+
const INPUT_REPOSITORY_WITHOWNER = INPUT_OWNER + "/Test.Repository-1";
10+
const INPUT_STATE: CommitState = "success";
11+
const INPUT_STATE_INVALID: CommitState = "failed" as CommitState;
12+
const INPUT_DESC = "Test Description";
13+
const INPUT_SHA = "TestSHA";
14+
const INPUT_TARGETURL = "test/uri";
15+
16+
const actionsCore: CoreActionsForTesting = {
17+
getInput: (arg:string) => {
18+
switch(arg) {
19+
case inputNames.context:
20+
return INPUT_CONTEXT;
21+
case inputNames.owner:
22+
return INPUT_OWNER;
23+
case inputNames.repo:
24+
return INPUT_REPOSITORY;
25+
case inputNames.state:
26+
return INPUT_STATE;
27+
case inputNames.desc:
28+
return INPUT_DESC;
29+
case inputNames.sha:
30+
return INPUT_SHA;
31+
case inputNames.target_url:
32+
return INPUT_TARGETURL;
33+
default:
34+
return "input not in test mock";
35+
}
36+
}
37+
}
38+
const actionsCoreAlt1: CoreActionsForTesting = {
39+
getInput: (arg:string) => {
40+
switch(arg) {
41+
case inputNames.repo:
42+
return INPUT_REPOSITORY_WITHOWNER;
43+
default:
44+
return actionsCore.getInput(arg);
45+
}
46+
}
47+
}
48+
49+
const actionsCoreAlt2: CoreActionsForTesting = {
50+
getInput: (arg:string) => {
51+
switch(arg) {
52+
case inputNames.owner:
53+
return INPUT_OWNER_INVALID;
54+
default:
55+
return actionsCore.getInput(arg);
56+
}
57+
}
58+
}
59+
60+
const actionsCoreAlt3: CoreActionsForTesting = {
61+
getInput: (arg:string) => {
62+
switch(arg) {
63+
case inputNames.state:
64+
return INPUT_STATE_INVALID;
65+
default:
66+
return actionsCore.getInput(arg);
67+
}
68+
}
69+
}
70+
71+
72+
test("should getInput context", t=> {
73+
t.is(makeStatusRequest(actionsCore).context, INPUT_CONTEXT);
74+
});
75+
test("should getInput owner", t=> {
76+
t.is(makeStatusRequest(actionsCore).owner, INPUT_OWNER);
77+
});
78+
test("should getInput repo", t=> {
79+
t.is(makeStatusRequest(actionsCore).repo, INPUT_REPOSITORY);
80+
});
81+
test("should getInput state", t=> {
82+
t.is(makeStatusRequest(actionsCore).state, INPUT_STATE);
83+
});
84+
test("should getInput description", t=> {
85+
t.is(makeStatusRequest(actionsCore).description, INPUT_DESC);
86+
});
87+
test("should getInput sha", t=> {
88+
t.is(makeStatusRequest(actionsCore).sha, INPUT_SHA);
89+
});
90+
test("should getInput target_url", t=> {
91+
t.is(makeStatusRequest(actionsCore).target_url, INPUT_TARGETURL);
92+
});
93+
94+
test("should getInput repo and remove leading owner name", t=> {
95+
t.is(makeStatusRequest(actionsCoreAlt1).repo, INPUT_REPOSITORY);
96+
});
97+
98+
test("when owner is not a valid GitHub username, should throw", t=> {
99+
let err = t.throws(()=> makeStatusRequest(actionsCoreAlt2));
100+
t.is(err.message, ERR_INVALID_OWNER)
101+
});
102+
103+
test("should validate state", t=> {
104+
let err = t.throws(()=> makeStatusRequest(actionsCoreAlt3));
105+
t.is(err.message, ERR_INVALID_STATE)
106+
});

action.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
11
name: 'github-status-action'
2-
description: 'Adds a check status on a commit, github reports the last status added for a particular context.'
2+
description: 'Adds a check status on a commit, GitHub reports the last status added for a particular context.'
33
author: 'Sibz@EntityZero'
44
branding:
55
icon: 'check'
66
color: 'green'
77
inputs:
88
authToken:
99
description: 'Use secrets.GITHUB_TOKEN or your own token if you need to trigger other workflows the use "on: status"'
10+
required: true
11+
state:
12+
description: 'The status of the check: success, error, failure or pending'
1013
required: true
1114
context:
1215
description: 'The context, this is displayed as the name of the check'
13-
required: true
16+
default: 'default'
17+
required: false
1418
description:
1519
description: 'Short text explaining the status of the check'
16-
required: true
17-
state:
18-
description: 'The status of the check: success, error, failure or pending'
19-
required: true
20+
default: ''
21+
required: false
2022
owner:
21-
description: 'Repostory onwer, defaults to context github.repository_owner if ommited'
23+
description: 'Repostory onwer, defaults to context github.repository_owner if omited'
2224
default: ${{ github.repository_owner }}
25+
required: false
2326
repository:
24-
description: 'Repository, default to context github.repository if ommited'
27+
description: 'Repository, default to context github.repository if omited'
2528
default: ${{ github.repository }}
29+
required: false
2630
sha:
2731
description: 'SHA of commit to update status on, defaults to context github.sha'
2832
default: ${{ github.sha }}
33+
required: false
34+
target_url:
35+
description: 'URL/URI to use for further details.'
36+
required: false
2937
runs:
3038
using: 'node12'
3139
main: 'dist/index.js'

0 commit comments

Comments
 (0)