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

Commit

Permalink
Merge pull request #10 from Sibz/releases/next
Browse files Browse the repository at this point in the history
Releases/next
  • Loading branch information
Sibz authored May 1, 2020
2 parents da0fa43 + b564c40 commit faaa4d9
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 111 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/smoke-screen-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "smoke-screen-tests"
on:
push:
branches-ignore:
- master

jobs:
sst:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
npm install
npm test
32 changes: 28 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,34 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run the action
- name: Test min args
uses: ./
with:
authToken: ${{secrets.GITHUB_TOKEN}}
context: 'Test run'
description: 'Passed'
state: 'success'
state: 'success'
- name: Test with all args except owner/repo (success)
uses: ./
with:
authToken: ${{secrets.GITHUB_TOKEN}}
context: "Test run"
description: "Test with all args"
target_url: "https://github.com/Sibz/github-status-action"
sha: ${{github.event.pull_request.head.sha || github.sha}}
state: 'success'
- name: Test failing action
uses: ./
with:
authToken: ${{secrets.GITHUB_TOKEN}}
context: "Test run failed"
description: "Failed test"
sha: ${{github.event.pull_request.head.sha || github.sha}}
state: 'failure'
- name: Test failing action now succeeded
uses: ./
with:
authToken: ${{secrets.GITHUB_TOKEN}}
context: "Test run failed"
description: "Failed test now succeeded"
sha: ${{github.event.pull_request.head.sha || github.sha}}
state: 'success'

45 changes: 21 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,32 @@
<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>
</p>

# Github Status Action
# GitHub Status Action

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

## Usage

### Inputs
```yml
authToken:
description: 'Use secrets.GITHUB_TOKEN or your own token if you need to trigger other workflows the use "on: status"'
required: true
context:
description: 'The context, this is displayed as the name of the check'
required: true
description:
description: 'Short text explaining the status of the check'
required: true
state:
description: 'The status of the check: success, error, failure or pending'
required: true
owner:
description: 'Repostory onwer, defaults to context github.repository_owner if ommited'
default: ${{ github.repository_owner }}
repository:
description: 'Repository, default to context github.repository if ommited'
default: ${{ github.repository }}
sha:
description: 'SHA of commit to update status on, defaults to context github.sha'
default: ${{ github.sha }}
```

* `authToken` (required)
Use secrets.GITHUB_TOKEN or your own token if you need to trigger other workflows that use "on: status"'
* `state` (required)
The status of the check should only be `success`, `error`, `failure` or `pending`
* `context`
The context, this is displayed as the name of the check
* `description`
Short text explaining the status of the check
* `owner`
Repostory onwer, defaults to context github.repository_owner if omited
* `repository`
Repository, default to context github.repository if omited
* `sha`
SHA of commit to update status on, defaults to context github.sha
*If using `on: pull_request` use `github.event.pull_request.head.sha`*
* `target_url`
Url to use for the details link. If omited no link is shown.

### Outputs
None.

Expand All @@ -58,4 +54,5 @@ on: # run on any PRs and main branch changes
context: 'Test run'
description: 'Passed'
state: 'success'
sha: ${{github.event.pull_request.head.sha || github.sha}}
```
106 changes: 106 additions & 0 deletions __tests__/makeStatusRequestTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import test from 'ava';
import makeStatusRequest, { CoreActionsForTesting, CommitState, ERR_INVALID_OWNER, ERR_INVALID_STATE} from '../src/makeStatusRequest'
import inputNames from '../src/inputNames'

const INPUT_CONTEXT = "test context";
const INPUT_OWNER = "TestOwner";
const INPUT_OWNER_INVALID = "-TestOwner";
const INPUT_REPOSITORY = "Test.Repository-1";
const INPUT_REPOSITORY_WITHOWNER = INPUT_OWNER + "/Test.Repository-1";
const INPUT_STATE: CommitState = "success";
const INPUT_STATE_INVALID: CommitState = "failed" as CommitState;
const INPUT_DESC = "Test Description";
const INPUT_SHA = "TestSHA";
const INPUT_TARGETURL = "test/uri";

const actionsCore: CoreActionsForTesting = {
getInput: (arg:string) => {
switch(arg) {
case inputNames.context:
return INPUT_CONTEXT;
case inputNames.owner:
return INPUT_OWNER;
case inputNames.repo:
return INPUT_REPOSITORY;
case inputNames.state:
return INPUT_STATE;
case inputNames.desc:
return INPUT_DESC;
case inputNames.sha:
return INPUT_SHA;
case inputNames.target_url:
return INPUT_TARGETURL;
default:
return "input not in test mock";
}
}
}
const actionsCoreAlt1: CoreActionsForTesting = {
getInput: (arg:string) => {
switch(arg) {
case inputNames.repo:
return INPUT_REPOSITORY_WITHOWNER;
default:
return actionsCore.getInput(arg);
}
}
}

const actionsCoreAlt2: CoreActionsForTesting = {
getInput: (arg:string) => {
switch(arg) {
case inputNames.owner:
return INPUT_OWNER_INVALID;
default:
return actionsCore.getInput(arg);
}
}
}

const actionsCoreAlt3: CoreActionsForTesting = {
getInput: (arg:string) => {
switch(arg) {
case inputNames.state:
return INPUT_STATE_INVALID;
default:
return actionsCore.getInput(arg);
}
}
}


test("should getInput context", t=> {
t.is(makeStatusRequest(actionsCore).context, INPUT_CONTEXT);
});
test("should getInput owner", t=> {
t.is(makeStatusRequest(actionsCore).owner, INPUT_OWNER);
});
test("should getInput repo", t=> {
t.is(makeStatusRequest(actionsCore).repo, INPUT_REPOSITORY);
});
test("should getInput state", t=> {
t.is(makeStatusRequest(actionsCore).state, INPUT_STATE);
});
test("should getInput description", t=> {
t.is(makeStatusRequest(actionsCore).description, INPUT_DESC);
});
test("should getInput sha", t=> {
t.is(makeStatusRequest(actionsCore).sha, INPUT_SHA);
});
test("should getInput target_url", t=> {
t.is(makeStatusRequest(actionsCore).target_url, INPUT_TARGETURL);
});

test("should getInput repo and remove leading owner name", t=> {
t.is(makeStatusRequest(actionsCoreAlt1).repo, INPUT_REPOSITORY);
});

test("when owner is not a valid GitHub username, should throw", t=> {
let err = t.throws(()=> makeStatusRequest(actionsCoreAlt2));
t.is(err.message, ERR_INVALID_OWNER)
});

test("should validate state", t=> {
let err = t.throws(()=> makeStatusRequest(actionsCoreAlt3));
t.is(err.message, ERR_INVALID_STATE)
});
24 changes: 16 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
name: 'github-status-action'
description: 'Adds a check status on a commit, github reports the last status added for a particular context.'
description: 'Adds a check status on a commit, GitHub reports the last status added for a particular context.'
author: 'Sibz@EntityZero'
branding:
icon: 'check'
color: 'green'
inputs:
authToken:
description: 'Use secrets.GITHUB_TOKEN or your own token if you need to trigger other workflows the use "on: status"'
required: true
state:
description: 'The status of the check: success, error, failure or pending'
required: true
context:
description: 'The context, this is displayed as the name of the check'
required: true
default: 'default'
required: false
description:
description: 'Short text explaining the status of the check'
required: true
state:
description: 'The status of the check: success, error, failure or pending'
required: true
default: ''
required: false
owner:
description: 'Repostory onwer, defaults to context github.repository_owner if ommited'
description: 'Repostory onwer, defaults to context github.repository_owner if omited'
default: ${{ github.repository_owner }}
required: false
repository:
description: 'Repository, default to context github.repository if ommited'
description: 'Repository, default to context github.repository if omited'
default: ${{ github.repository }}
required: false
sha:
description: 'SHA of commit to update status on, defaults to context github.sha'
default: ${{ github.sha }}
required: false
target_url:
description: 'URL/URI to use for further details.'
required: false
runs:
using: 'node12'
main: 'dist/index.js'
Loading

0 comments on commit faaa4d9

Please sign in to comment.