feat: Add JavaScript action template

https://github.com/actions/javascript-action
This commit is contained in:
peaceiris 2019-09-15 16:52:29 +09:00
parent 2905a7fc5b
commit 8ffc478ba7
9 changed files with 5537 additions and 5 deletions

17
.eslintrc.json Normal file
View File

@ -0,0 +1,17 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
}

17
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,17 @@
name: "Run JavaScript Action"
on:
push:
branches:
- 'releases/*' # only run in release distribution branches
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: npm ci
- run: npm test
- uses: actions/javascript-action@releases/v1
with:
milliseconds: 1000

61
.gitignore vendored Normal file
View File

@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# next.js build output
.next

View File

@ -1,9 +1,14 @@
name: 'Hugo build action'
description: 'GitHub Actions for Hugo extended and Hugo Modules'
author: 'peaceiris'
inputs:
milliseconds: # id of input
description: 'number of milliseconds to wait'
required: true
default: '1000'
outputs:
time: # output will be available to future steps
description: 'The message to output'
runs:
using: 'docker'
image: 'Dockerfile'
branding:
icon: 'package'
color: 'yellow'
using: 'node12'
main: 'index.js'

22
index.js Normal file
View File

@ -0,0 +1,22 @@
const core = require('@actions/core');
const wait = require('./wait');
// most @actions toolkit packages have async methods
async function run() {
try {
const ms = core.getInput('milliseconds');
console.log(`Waiting ${ms} milliseconds ...`)
core.debug((new Date()).toTimeString())
wait(parseInt(ms));
core.debug((new Date()).toTimeString())
core.setOutput('time', new Date().toTimeString());
}
catch (error) {
core.setFailed(error.message);
}
}
run()

23
index.test.js Normal file
View File

@ -0,0 +1,23 @@
const wait = require('./wait');
const process = require('process');
const cp = require('child_process');
const path = require('path');
test('throws invalid number', async() => {
await expect(wait('foo')).rejects.toThrow('milleseconds not a number');
});
test('wait 500 ms', async() => {
const start = new Date();
await wait(500);
const end = new Date();
var delta = Math.abs(end - start);
expect(delta).toBeGreaterThan(450);
});
// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
process.env['INPUT_MILLISECONDS'] = 500;
const ip = path.join(__dirname, 'index.js');
console.log(cp.execSync(`node ${ip}`).toString());
})

5344
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

32
package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "javascript-action",
"version": "1.0.0",
"description": "JavaScript Action Template",
"main": "index.js",
"scripts": {
"lint": "eslint index.js",
"test": "eslint index.js && jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/actions/javascript-action.git"
},
"keywords": [
"GitHub",
"Actions",
"JavaScript"
],
"author": "GitHub",
"license": "MIT",
"bugs": {
"url": "https://github.com/actions/javascript-action/issues"
},
"homepage": "https://github.com/actions/javascript-action#readme",
"dependencies": {
"@actions/core": "^1.1.0"
},
"devDependencies": {
"eslint": "^6.3.0",
"jest": "^24.9.0"
}
}

11
wait.js Normal file
View File

@ -0,0 +1,11 @@
let wait = function(milliseconds) {
return new Promise((resolve, reject) => {
if (typeof(milliseconds) !== 'number') {
throw new Error('milleseconds not a number');
}
setTimeout(() => resolve("done!"), milliseconds)
});
}
module.exports = wait;