Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7d9110

Browse files
committed
Initial commit
0 parents  commit b7d9110

14 files changed

Lines changed: 5729 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "Test typescript-action"
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 run build
17+
- run: npm test
18+
- uses: ./
19+
with:
20+
milliseconds: 1000

.gitignore

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
__tests__/runner/*
2+
3+
# comment out in distribution branches
4+
node_modules/
5+
6+
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
15+
# Diagnostic reports (https://nodejs.org/api/report.html)
16+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
17+
18+
# Runtime data
19+
pids
20+
*.pid
21+
*.seed
22+
*.pid.lock
23+
24+
# Directory for instrumented libs generated by jscoverage/JSCover
25+
lib-cov
26+
27+
# Coverage directory used by tools like istanbul
28+
coverage
29+
*.lcov
30+
31+
# nyc test coverage
32+
.nyc_output
33+
34+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
35+
.grunt
36+
37+
# Bower dependency directory (https://bower.io/)
38+
bower_components
39+
40+
# node-waf configuration
41+
.lock-wscript
42+
43+
# Compiled binary addons (https://nodejs.org/api/addons.html)
44+
build/Release
45+
46+
# Dependency directories
47+
jspm_packages/
48+
49+
# TypeScript v1 declaration files
50+
typings/
51+
52+
# TypeScript cache
53+
*.tsbuildinfo
54+
55+
# Optional npm cache directory
56+
.npm
57+
58+
# Optional eslint cache
59+
.eslintcache
60+
61+
# Optional REPL history
62+
.node_repl_history
63+
64+
# Output of 'npm pack'
65+
*.tgz
66+
67+
# Yarn Integrity file
68+
.yarn-integrity
69+
70+
# dotenv environment variables file
71+
.env
72+
.env.test
73+
74+
# parcel-bundler cache (https://parceljs.org/)
75+
.cache
76+
77+
# next.js build output
78+
.next
79+
80+
# nuxt.js build output
81+
.nuxt
82+
83+
# vuepress build output
84+
.vuepress/dist
85+
86+
# Serverless directories
87+
.serverless/
88+
89+
# FuseBox cache
90+
.fusebox/
91+
92+
# DynamoDB Local files
93+
.dynamodb/

LICENSE

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

README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Create a JavaScript Action using TypeScript
2+
3+
Use this template to bootstrap the creation of a JavaScript action.:rocket:
4+
5+
This template includes compilication support, tests, a validation workflow, publishing, and versioning guidance.
6+
7+
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
8+
9+
## Create an action from this template
10+
11+
Click the `Use this Template` and provide the new repo details for your action
12+
13+
## Code in Master
14+
15+
Install the dependencies
16+
```bash
17+
$ npm install
18+
```
19+
20+
Build the typescript
21+
```bash
22+
$ npm run build
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+
import * as core from '@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 out in 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/typescript-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/typescript-action@v1
111+
with:
112+
milliseconds: 1000
113+
```

__tests__/main.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {wait} from '../src/wait'
2+
import * as process from 'process'
3+
import * as cp from 'child_process'
4+
import * as path from '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.getTime() - start.getTime());
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, '..', 'lib', 'main.js');
22+
console.log(cp.execSync(`node ${ip}`).toString());
23+
})

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: 'Your name here'
2+
description: 'Provide a description here'
3+
author: 'Your name or organization here'
4+
inputs:
5+
myInput: # change this
6+
description: 'input description here'
7+
default: 'default value if applicable'
8+
runs:
9+
using: 'node12'
10+
main: 'lib/main.js'

jest.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
clearMocks: true,
3+
moduleFileExtensions: ['js', 'ts'],
4+
testEnvironment: 'node',
5+
testMatch: ['**/*.test.ts'],
6+
testRunner: 'jest-circus/runner',
7+
transform: {
8+
'^.+\\.ts$': 'ts-jest'
9+
},
10+
verbose: true
11+
}

lib/main.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
return new (P || (P = Promise))(function (resolve, reject) {
4+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7+
step((generator = generator.apply(thisArg, _arguments || [])).next());
8+
});
9+
};
10+
var __importStar = (this && this.__importStar) || function (mod) {
11+
if (mod && mod.__esModule) return mod;
12+
var result = {};
13+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
14+
result["default"] = mod;
15+
return result;
16+
};
17+
Object.defineProperty(exports, "__esModule", { value: true });
18+
const core = __importStar(require("@actions/core"));
19+
const wait_1 = require("./wait");
20+
function run() {
21+
return __awaiter(this, void 0, void 0, function* () {
22+
try {
23+
const ms = core.getInput('milliseconds');
24+
console.log(`Waiting ${ms} milliseconds ...`);
25+
core.debug((new Date()).toTimeString());
26+
wait_1.wait(parseInt(ms));
27+
core.debug((new Date()).toTimeString());
28+
core.setOutput('time', new Date().toTimeString());
29+
}
30+
catch (error) {
31+
core.setFailed(error.message);
32+
}
33+
});
34+
}
35+
run();

lib/wait.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
function wait(milliseconds) {
4+
return new Promise((resolve, reject) => {
5+
if (typeof (milliseconds) !== 'number') {
6+
throw new Error('milleseconds not a number');
7+
}
8+
setTimeout(() => resolve("done!"), milliseconds);
9+
});
10+
}
11+
exports.wait = wait;

0 commit comments

Comments
 (0)