Skip to content

Commit d642bf1

Browse files
committed
Initial commit
0 parents  commit d642bf1

11 files changed

+5681
-0
lines changed

.eslintrc.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"env": {
3+
"commonjs": true,
4+
"es6": true,
5+
"node": true
6+
},
7+
"extends": "eslint:recommended",
8+
"globals": {
9+
"Atomics": "readonly",
10+
"SharedArrayBuffer": "readonly"
11+
},
12+
"parserOptions": {
13+
"ecmaVersion": 2018
14+
},
15+
"rules": {
16+
}
17+
}

.github/workflows/test.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: "test-local"
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- 'releases/*'
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v1
14+
15+
- run: npm ci
16+
- run: npm test
17+
- uses: ./
18+
with:
19+
milliseconds: 1000

.gitignore

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# comment this out distribution branches
2+
node_modules/
3+
4+
# Editors
5+
.vscode
6+
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
*.pid.lock
19+
20+
# Directory for instrumented libs generated by jscoverage/JSCover
21+
lib-cov
22+
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Other Dependency directories
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# Optional npm cache directory
48+
.npm
49+
50+
# Optional eslint cache
51+
.eslintcache
52+
53+
# Optional REPL history
54+
.node_repl_history
55+
56+
# Output of 'npm pack'
57+
*.tgz
58+
59+
# Yarn Integrity file
60+
.yarn-integrity
61+
62+
# dotenv environment variables file
63+
.env
64+
65+
# next.js build output
66+
.next

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 GitHub Actions
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
<p align="center">
3+
<a href="https://github.com/actions/javascript-action"><img alt="GitHub Actions status" src="https://github.com/actions/javascript-action/workflows/test-local/badge.svg"></a>
4+
</p>
5+
6+
# Create a JavaScript Action
7+
8+
Use this template to bootstrap the creation of a JavaScript action.:rocket:
9+
10+
This template includes tests, linting, a validation workflow, publishing, and versioning guidance.
11+
12+
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
13+
14+
## Create an action from this template
15+
16+
Click the `Use this Template` and provide the new repo details for your action
17+
18+
## Code in Master
19+
20+
Install the dependencies
21+
```bash
22+
$ npm install
23+
```
24+
25+
Run the tests :heavy_check_mark:
26+
```bash
27+
$ npm test
28+
29+
PASS ./index.test.js
30+
✓ throws invalid number (3ms)
31+
wait 500 ms (504ms)
32+
test runs (95ms)
33+
34+
...
35+
```
36+
37+
## Change action.yml
38+
39+
The action.yml contains defines the inputs and output for your action.
40+
41+
Update the action.yml with your name, description, inputs and outputs for your action.
42+
43+
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
44+
45+
## Change the Code
46+
47+
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
48+
49+
```javascript
50+
const core = require('@actions/core');
51+
...
52+
53+
async function run() {
54+
try {
55+
...
56+
}
57+
catch (error) {
58+
core.setFailed(error.message);
59+
}
60+
}
61+
62+
run()
63+
```
64+
65+
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
66+
67+
## Publish to a distribution branch
68+
69+
Actions are run from GitHub repos. We will create a releases branch and only checkin production modules (core in this case).
70+
71+
Comment out node_modules in .gitignore and create a releases/v1 branch
72+
```bash
73+
# comment this out distribution branches
74+
# node_modules/
75+
```
76+
77+
```bash
78+
$ git checkout -b releases/v1
79+
$ git commit -a -m "prod dependencies"
80+
```
81+
82+
```bash
83+
$ npm prune --production
84+
$ git add node_modules
85+
$ git commit -a -m "prod dependencies"
86+
$ git push origin releases/v1
87+
```
88+
89+
Your action is now published! :rocket:
90+
91+
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
92+
93+
## Validate
94+
95+
You can now validate the action by referencing the releases/v1 branch
96+
97+
```yaml
98+
uses: actions/javascript-action@releases/v1
99+
with:
100+
milliseconds: 1000
101+
```
102+
103+
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:
104+
105+
## Usage:
106+
107+
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and tested action
108+
109+
```yaml
110+
uses: actions/javascript-action@v1
111+
with:
112+
milliseconds: 1000
113+
```

action.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'Wait'
2+
description: 'Wait a designated number of milliseconds'
3+
inputs:
4+
milliseconds: # id of input
5+
description: 'number of milliseconds to wait'
6+
required: true
7+
default: '1000'
8+
outputs:
9+
time: # output will be available to future steps
10+
description: 'The message to output'
11+
runs:
12+
using: 'node12'
13+
main: 'index.js'

index.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const core = require('@actions/core');
2+
const wait = require('./wait');
3+
4+
5+
// most @actions toolkit packages have async methods
6+
async function run() {
7+
try {
8+
const ms = core.getInput('milliseconds');
9+
console.log(`Waiting ${ms} milliseconds ...`)
10+
11+
core.debug((new Date()).toTimeString())
12+
wait(parseInt(ms));
13+
core.debug((new Date()).toTimeString())
14+
15+
core.setOutput('time', new Date().toTimeString());
16+
}
17+
catch (error) {
18+
core.setFailed(error.message);
19+
}
20+
}
21+
22+
run()

index.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const wait = require('./wait');
2+
const process = require('process');
3+
const cp = require('child_process');
4+
const path = require('path');
5+
6+
test('throws invalid number', async() => {
7+
await expect(wait('foo')).rejects.toThrow('milleseconds not a number');
8+
});
9+
10+
test('wait 500 ms', async() => {
11+
const start = new Date();
12+
await wait(500);
13+
const end = new Date();
14+
var delta = Math.abs(end - start);
15+
expect(delta).toBeGreaterThan(450);
16+
});
17+
18+
// shows how the runner will run a javascript action with env / stdout protocol
19+
test('test runs', () => {
20+
process.env['INPUT_MILLISECONDS'] = 500;
21+
const ip = path.join(__dirname, 'index.js');
22+
console.log(cp.execSync(`node ${ip}`).toString());
23+
})

0 commit comments

Comments
 (0)