Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hall committed Nov 19, 2019
0 parents commit bc0c93c
Show file tree
Hide file tree
Showing 454 changed files with 124,236 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 LIFX Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# LIFX Buildlight Action

This GitHub Action is built to allow you to indicate the status of a build on a LIFX device.

## Usage

This action allows you to represent three states of build, `in_progress`, `success` and `failure`. It is intended that at the start of the build you trigger the `in_progress` state, then once the build status has been decided you set it to either `success` or `failure`. You can use the [`job` context](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#job-context) to gather this information automatically.

Such an example workflow might look like this:

```yaml
steps:
- uses: LIFX/buildlight-action@master
with:
lifx-token: ${{ secrets.LIFX_TOKEN }}
selector: 'location:Work'
status: 'in_progress'
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- run: npm install
- run: npm test
- uses: LIFX/buildlight-action@master
if: always()
with:
lifx-token: ${{ secrets.LIFX_TOKEN }}
selector: 'location:Work'
status: ${{ job.status }}
```
## Options
This action _requires_ the following arguments.
### lifx-token
The `lifx-token` argument must be a valid LIFX personal access token. You can get a personal access token by going to [https://cloud.lifx.com/settings](https://cloud.lifx.com/settings), logging in, and creating a token. More information can be found on our [API documentation usage page](https://api.developer.lifx.com/docs/how-to-use-the-following-examples).

### selector

The selector allows you to select which devices will react to the pipeline. Using selectors you can change a single light, a single zone on a strip or beam, a group, a location or your entire account. You can read more about selectors on the [API documentation selectors page](https://api.developer.lifx.com/docs/selectors).

Some example selectors are:

* `all` - All lights on the account.
* `label:Build` - All lights labelled 'build'.
* `location:Home` - All lights in the location named 'Home'.
* `id:d073d52988f3` - The light with the serial number `d073d52988f3`.
* `id:d073d52988f3|5` - The light zone `5` on the device with the serial number `d073d52988f3`.

### status

Status can be set to one of `in_progress`, `success`, `failure`, `cancelled`, `timed_out`, `neutral`, `timed_out` or `action_required`. This will cause the lights to change status. Each status appears as follows:

#### in_progress, neutral

The selected lights will 'breathe' slowly between the previous state and orange. This will continue either for 30 minutes, or until another change is made.

#### success

The selected lights will turn green.

#### failure, timed_out, action_required

The selected lights will turn red.

#### cancelled

The selected lights will turn orange.
20 changes: 20 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: 'LIFX Build Light'
description: 'Use your LIFX light to represent the state of your builds'
author: 'LIFX Inc <support@lifx.com>'
inputs:
lifx-token:
description: 'A token from your LIFX Cloud account'
required: true
selector:
description: 'The selector to choose which light, see: https://api.developer.lifx.com/docs/selectors'
required: true
status:
description: 'Either in_progress, success, failure or cancelled'
required: true
runs:
using: 'node12'
main: 'index.js'
branding:
icon: 'sun'
color: 'green'
86 changes: 86 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const https = require('https');
const querystring = require('querystring');
const core = require('@actions/core');

const validStatus = [
"in_progress",
"failure",
"success",
"cancelled",
"neutral",
"action_required",
"timed_out",
]

const options = {
hostname: 'api.lifx.com',
port: 443,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
};

const postData = {}

try {
const token = core.getInput('lifx-token');
const selector = core.getInput('selector');
const status = core.getInput('status');

if (!validStatus.includes(status)) {
throw "Status was not valid";
}

switch (status) {
case 'neutral':
case 'in_progress':
options.method = 'POST';
options.path = '/v1/lights/' + selector + '/effects/breathe';

postData.color = 'orange';
postData.period = 4;
postData.cycles = 450;
postData.power_on = true;
break;

case 'action_required':
case 'timed_out':
case 'failure':
options.method = 'PUT';
options.path = '/v1/lights/' + selector + '/state';

postData.color = 'red';
postData.power = 'on';
postData.fast = true;
break;

case 'success':
options.method = 'PUT';
options.path = '/v1/lights/' + selector + '/state';

postData.color = 'green';
postData.power = 'on';
postData.fast = true;
break;

case 'cancelled':
options.method = 'PUT';
options.path = '/v1/lights/' + selector + '/state';

postData.color = 'orange';
postData.power = 'on';
postData.fast = true;
break;
}

const strPostData = querystring.stringify(postData);
options.headers['Content-Length'] = Buffer.byteLength(strPostData);
options.headers['Authorization'] = 'Bearer ' + token;

const req = https.request(options)
req.write(strPostData)
req.end()

} catch (error) {
core.setFailed(error.message);
}
1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

140 changes: 140 additions & 0 deletions node_modules/@actions/core/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions node_modules/@actions/core/lib/command.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bc0c93c

Please sign in to comment.