Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ce2a079

Browse files
authoredApr 24, 2023
Initial commit
0 parents  commit ce2a079

25 files changed

+15014
-0
lines changed
 

‎.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
lib/
3+
node_modules/
4+
jest.config.js

‎.eslintrc.json

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"plugins": ["jest", "@typescript-eslint"],
3+
"extends": ["plugin:github/recommended"],
4+
"parser": "@typescript-eslint/parser",
5+
"parserOptions": {
6+
"ecmaVersion": 9,
7+
"sourceType": "module",
8+
"project": "./tsconfig.json"
9+
},
10+
"rules": {
11+
"i18n-text/no-en": "off",
12+
"eslint-comments/no-use": "off",
13+
"import/no-namespace": "off",
14+
"no-unused-vars": "off",
15+
"@typescript-eslint/no-unused-vars": "error",
16+
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
17+
"@typescript-eslint/no-require-imports": "error",
18+
"@typescript-eslint/array-type": "error",
19+
"@typescript-eslint/await-thenable": "error",
20+
"@typescript-eslint/ban-ts-comment": "error",
21+
"camelcase": "off",
22+
"@typescript-eslint/consistent-type-assertions": "error",
23+
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
24+
"@typescript-eslint/func-call-spacing": ["error", "never"],
25+
"@typescript-eslint/no-array-constructor": "error",
26+
"@typescript-eslint/no-empty-interface": "error",
27+
"@typescript-eslint/no-explicit-any": "error",
28+
"@typescript-eslint/no-extraneous-class": "error",
29+
"@typescript-eslint/no-for-in-array": "error",
30+
"@typescript-eslint/no-inferrable-types": "error",
31+
"@typescript-eslint/no-misused-new": "error",
32+
"@typescript-eslint/no-namespace": "error",
33+
"@typescript-eslint/no-non-null-assertion": "warn",
34+
"@typescript-eslint/no-unnecessary-qualifier": "error",
35+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
36+
"@typescript-eslint/no-useless-constructor": "error",
37+
"@typescript-eslint/no-var-requires": "error",
38+
"@typescript-eslint/prefer-for-of": "warn",
39+
"@typescript-eslint/prefer-function-type": "warn",
40+
"@typescript-eslint/prefer-includes": "error",
41+
"@typescript-eslint/prefer-string-starts-ends-with": "error",
42+
"@typescript-eslint/promise-function-async": "error",
43+
"@typescript-eslint/require-array-sort-compare": "error",
44+
"@typescript-eslint/restrict-plus-operands": "error",
45+
"semi": "off",
46+
"@typescript-eslint/semi": ["error", "never"],
47+
"@typescript-eslint/type-annotation-spacing": "error",
48+
"@typescript-eslint/unbound-method": "error"
49+
},
50+
"env": {
51+
"node": true,
52+
"es6": true,
53+
"jest/globals": true
54+
}
55+
}

‎.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/** -diff linguist-generated=true

‎.github/dependabot.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
7+
8+
- package-ecosystem: npm
9+
directory: /
10+
schedule:
11+
interval: daily

‎.github/workflows/check-dist.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# `dist/index.js` is a special file in Actions.
2+
# When you reference an action with `uses:` in a workflow,
3+
# `index.js` is the code that will run.
4+
# For our project, we generate this file through a build process from other source files.
5+
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
6+
name: Check dist/
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- '**.md'
14+
pull_request:
15+
paths-ignore:
16+
- '**.md'
17+
workflow_dispatch:
18+
19+
jobs:
20+
check-dist:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
26+
- name: Set Node.js 16.x
27+
uses: actions/setup-node@v3.6.0
28+
with:
29+
node-version: 16.x
30+
31+
- name: Install dependencies
32+
run: npm ci
33+
34+
- name: Rebuild the dist/ directory
35+
run: |
36+
npm run build
37+
npm run package
38+
39+
- name: Compare the expected and actual dist/ directories
40+
run: |
41+
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
42+
echo "Detected uncommitted changes after build. See status below:"
43+
git diff
44+
exit 1
45+
fi
46+
id: diff
47+
48+
# If index.js was different than expected, upload the expected version as an artifact
49+
- uses: actions/upload-artifact@v3
50+
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
51+
with:
52+
name: dist
53+
path: dist/

‎.github/workflows/codeql-analysis.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ main ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ main ]
20+
schedule:
21+
- cron: '31 7 * * 3'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'TypeScript' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v3
42+
43+
# Initializes the CodeQL tools for scanning.
44+
- name: Initialize CodeQL
45+
uses: github/codeql-action/init@v2
46+
with:
47+
languages: ${{ matrix.language }}
48+
source-root: src
49+
# If you wish to specify custom queries, you can do so here or in a config file.
50+
# By default, queries listed here will override any specified in a config file.
51+
# Prefix the list here with "+" to use these queries and those in the config file.
52+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
53+
54+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55+
# If this step fails, then you should remove it and run the build manually (see below)
56+
- name: Autobuild
57+
uses: github/codeql-action/autobuild@v2
58+
59+
# ℹ️ Command-line programs to run using the OS shell.
60+
# 📚 https://git.io/JvXDl
61+
62+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63+
# and modify them (or add more) to build your code if your project
64+
# uses a compiled language
65+
66+
#- run: |
67+
# make bootstrap
68+
# make release
69+
70+
- name: Perform CodeQL Analysis
71+
uses: github/codeql-action/analyze@v2

‎.github/workflows/test.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'build-test'
2+
on: # rebuild any PRs and main branch changes
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
- 'releases/*'
8+
9+
jobs:
10+
build: # make sure build/ci work properly
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- run: |
15+
npm install
16+
- run: |
17+
npm run all
18+
test: # make sure the action works on a clean machine without building
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: ./
23+
with:
24+
milliseconds: 1000

‎.gitignore

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

‎.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
lib/
3+
node_modules/

‎.prettierrc.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": false,
6+
"singleQuote": true,
7+
"trailingComma": "none",
8+
"bracketSpacing": false,
9+
"arrowParens": "avoid"
10+
}

‎CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @actions/actions-runtime

‎LICENSE

+22
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

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

‎__tests__/main.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
import {expect, test} from '@jest/globals'
6+
7+
test('throws invalid number', async () => {
8+
const input = parseInt('foo', 10)
9+
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
10+
})
11+
12+
test('wait 500 ms', async () => {
13+
const start = new Date()
14+
await wait(500)
15+
const end = new Date()
16+
var delta = Math.abs(end.getTime() - start.getTime())
17+
expect(delta).toBeGreaterThan(450)
18+
})
19+
20+
// shows how the runner will run a javascript action with env / stdout protocol
21+
test('test runs', () => {
22+
process.env['INPUT_MILLISECONDS'] = '500'
23+
const np = process.execPath
24+
const ip = path.join(__dirname, '..', 'lib', 'main.js')
25+
const options: cp.ExecFileSyncOptions = {
26+
env: process.env
27+
}
28+
console.log(cp.execFileSync(np, [ip], options).toString())
29+
})

‎action.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'Your name here'
2+
description: 'Provide a description here'
3+
author: 'Your name or organization here'
4+
inputs:
5+
milliseconds: # change this
6+
required: true
7+
description: 'input description here'
8+
default: 'default value if applicable'
9+
runs:
10+
using: 'node16'
11+
main: 'dist/index.js'

‎dist/index.js

+2,918
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/licenses.txt

+73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/sourcemap-register.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎jest.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
clearMocks: true,
3+
moduleFileExtensions: ['js', 'ts'],
4+
testMatch: ['**/*.test.ts'],
5+
transform: {
6+
'^.+\\.ts$': 'ts-jest'
7+
},
8+
verbose: true
9+
}

‎package-lock.json

+11,430
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "typescript-action",
3+
"version": "0.0.0",
4+
"private": true,
5+
"description": "TypeScript template action",
6+
"main": "lib/main.js",
7+
"scripts": {
8+
"build": "tsc",
9+
"format": "prettier --write '**/*.ts'",
10+
"format-check": "prettier --check '**/*.ts'",
11+
"lint": "eslint src/**/*.ts",
12+
"package": "ncc build --source-map --license licenses.txt",
13+
"test": "jest",
14+
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/actions/typescript-action.git"
19+
},
20+
"keywords": [
21+
"actions",
22+
"node",
23+
"setup"
24+
],
25+
"author": "",
26+
"license": "MIT",
27+
"dependencies": {
28+
"@actions/core": "^1.10.0"
29+
},
30+
"devDependencies": {
31+
"@types/node": "^18.15.13",
32+
"@typescript-eslint/parser": "^5.59.0",
33+
"@vercel/ncc": "^0.36.1",
34+
"eslint": "^8.38.0",
35+
"eslint-plugin-github": "^4.7.0",
36+
"eslint-plugin-jest": "^27.2.1",
37+
"jest": "^29.5.0",
38+
"js-yaml": "^4.1.0",
39+
"prettier": "^2.8.7",
40+
"ts-jest": "^29.1.0",
41+
"typescript": "^5.0.4"
42+
}
43+
}

‎src/main.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as core from '@actions/core'
2+
import {wait} from './wait'
3+
4+
async function run(): Promise<void> {
5+
try {
6+
const ms: string = core.getInput('milliseconds')
7+
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_STEP_DEBUG` to true
8+
9+
core.debug(new Date().toTimeString())
10+
await wait(parseInt(ms, 10))
11+
core.debug(new Date().toTimeString())
12+
13+
core.setOutput('time', new Date().toTimeString())
14+
} catch (error) {
15+
if (error instanceof Error) core.setFailed(error.message)
16+
}
17+
}
18+
19+
run()

‎src/wait.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export async function wait(milliseconds: number): Promise<string> {
2+
return new Promise(resolve => {
3+
if (isNaN(milliseconds)) {
4+
throw new Error('milliseconds not a number')
5+
}
6+
7+
setTimeout(() => resolve('done!'), milliseconds)
8+
})
9+
}

‎tsconfig.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
4+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
5+
"outDir": "./lib", /* Redirect output structure to the directory. */
6+
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
7+
"strict": true, /* Enable all strict type-checking options. */
8+
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
9+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
10+
},
11+
"exclude": ["node_modules", "**/*.test.ts"]
12+
}

0 commit comments

Comments
 (0)
This repository has been archived.