Compare commits

...

31 Commits
0.6.0 ... 0.9.0

Author SHA1 Message Date
Jonathan Clem
5d03ada4b0 0.9.0 2020-03-24 15:14:05 -04:00
Jonathan Clem
293ee0ca2d Uninstall/reinstall ts-jest 2020-03-24 15:07:44 -04:00
Jonathan Clem
67d29bab15 Merge pull request #36 from actions/bump-dependencies
Uninstall/reinstall Jest (for minimist update)
2020-03-24 15:00:02 -04:00
Jonathan Clem
0baa1791ca Merge pull request #35 from actions/bump-dependencies
Bump outdated npm packages
2020-03-24 14:58:02 -04:00
Jonathan Clem
b4fd05ccdf Uninstall/reinstall Jest (for minimist update) 2020-03-24 14:57:31 -04:00
Jonathan Clem
2ccd1edaf4 Update ncc 2020-03-24 14:38:07 -04:00
Jonathan Clem
a59996ab35 Update TypeScript 2020-03-24 14:37:22 -04:00
Jonathan Clem
7ca8635cd0 Bump @types/jest 2020-03-24 14:36:26 -04:00
Jonathan Clem
8117de6119 Bump @actions/core 2020-03-24 14:35:48 -04:00
Jonathan Clem
3f4f5a83e8 Merge pull request #34 from actions/dependabot/npm_and_yarn/acorn-6.4.1
Bump acorn from 6.4.0 to 6.4.1
2020-03-24 14:14:58 -04:00
dependabot[bot]
0e2c0d5c7c Bump acorn from 6.4.0 to 6.4.1
Bumps [acorn](https://github.com/acornjs/acorn) from 6.4.0 to 6.4.1.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](https://github.com/acornjs/acorn/compare/6.4.0...6.4.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-03-24 18:11:43 +00:00
Jonathan Clem
0d15461bee Merge pull request #33 from actions/add-core
Add core to execution context
2020-03-24 14:08:04 -04:00
Jonathan Clem
e4cc5a8d47 Add core to README 2020-03-24 14:06:45 -04:00
Jonathan Clem
dc16f26602 Add core to integration test 2020-03-24 14:02:45 -04:00
Jonathan Clem
8982156783 Add core to the script context 2020-03-24 13:57:27 -04:00
Jonathan Clem
80a5e943b4 v0.8.0 2020-02-28 09:18:07 -05:00
Jonathan Clem
0cb5c91bd3 Update README.md 2020-02-28 09:12:55 -05:00
Jonathan Clem
493b839630 Remove output log 2020-02-28 09:09:06 -05:00
Jonathan Clem
904b439f45 Set output 2020-02-28 09:07:52 -05:00
Jonathan Clem
1e169ae445 Remove result temporarily 2020-02-28 09:06:03 -05:00
Jonathan Clem
62fdca610c Remove log result 2020-02-28 08:54:30 -05:00
Jonathan Clem
26ee3d2d09 Test log result 2020-02-28 08:52:13 -05:00
Jonathan Clem
be5d094bf9 Remove async from callAsyncFunction 2020-02-28 08:51:05 -05:00
Jonathan Clem
3758c2b05b Add result log 2020-02-28 08:50:21 -05:00
Jonathan Clem
317a0746d1 Remove core again for now 2020-02-28 08:49:25 -05:00
Jonathan Clem
ec171b8961 Use master 2020-02-27 17:53:27 -05:00
Jonathan Clem
d73e75dea8 Separate integration workflow 2020-02-27 17:52:43 -05:00
Jonathan Clem
7afad1e364 Add core 2020-02-27 17:43:18 -05:00
Jonathan Clem
ebe3cb13e0 Add some test workflows 2020-02-27 17:39:50 -05:00
Jonathan Clem
38e3ffe4c6 Add tests for the AsyncFunction 2020-02-27 17:27:49 -05:00
Jonathan Clem
6eefe48bc9 Update @actions NPM dependencies 2020-02-27 16:52:48 -05:00
10 changed files with 19488 additions and 700 deletions

18
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,18 @@
on:
push: {branches: master}
pull_request: {branches: master}
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with: {node-version: 13.x}
- uses: actions/cache@v1
with:
path: ~/.npm
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
restore-keys: ${{runner.os}}-npm-
- run: npm ci
- run: npm test

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

@@ -0,0 +1,17 @@
on:
push: {branches: master}
jobs:
integration:
runs-on: ubuntu-latest
steps:
- id: output-set
uses: actions/github-script@master
with:
script: return core.getInput('input-value')
result-encoding: string
input-value: output
- run: |
if [[ "${{steps.output-set.outputs.result}}" != "output" ]]; then
exit 1
fi

View File

@@ -1,4 +1,4 @@
# github-script
# github-script ![.github/workflows/integration.yml](https://github.com/actions/github-script/workflows/.github/workflows/integration.yml/badge.svg?event=push) ![.github/workflows/ci.yml](https://github.com/actions/github-script/workflows/.github/workflows/ci.yml/badge.svg?event=push)
This action makes it easy to quickly write a script in your workflow that
uses the GitHub API and the workflow run context.
@@ -11,6 +11,7 @@ be provided:
[octokit/rest.js](https://github.com/octokit/rest.js) client
- `context` An object containing the [context of the workflow
run](https://github.com/actions/toolkit/tree/master/packages/github)
- `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/master/packages/core) package
Since the `script` is just a function body, these values will already be
defined, so you don't have to (see examples below).
@@ -19,7 +20,7 @@ See [octokit/rest.js](https://octokit.github.io/rest.js/) for the API client
documentation.
**Note** This action is still a bit of an experiment—the API may change in
*future versions. 🙂
future versions. 🙂
## Development
@@ -42,7 +43,7 @@ jobs:
comment:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@0.6.0
- uses: actions/github-script@0.9.0
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
@@ -64,7 +65,7 @@ jobs:
apply-label:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@0.6.0
- uses: actions/github-script@0.9.0
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
@@ -85,7 +86,7 @@ jobs:
welcome:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@0.6.0
- uses: actions/github-script@0.9.0
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
@@ -123,14 +124,13 @@ You can use the `github` object to access the Octokit API. For
instance, `github.request`
```yaml
on:
pull_request
on: pull_request
jobs:
diff:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@0.6.0
- uses: actions/github-script@0.9.0
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
@@ -148,9 +148,8 @@ By default, the JSON-encoded return value of the function is set as the "result"
output of a github-script step. For some workflows, string encoding is preferred. This option can be set using the
`result-encoding` input:
```yaml
- uses: actions/github-script@0.6.0
- uses: actions/github-script@0.9.0
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string

View File

@@ -0,0 +1,26 @@
import {callAsyncFunction} from '../src/async-function'
describe('callAsyncFunction', () => {
test('calls the function with its arguments', async () => {
const result = await callAsyncFunction({foo: 'bar'}, 'return foo')
expect(result).toEqual('bar')
})
test('throws on ReferenceError', async () => {
expect.assertions(1)
try {
await callAsyncFunction({}, 'proces')
} catch (err) {
expect(err).toBeInstanceOf(ReferenceError)
}
})
test('can access process', async () => {
await callAsyncFunction({}, 'process')
})
test('can access console', async () => {
await callAsyncFunction({}, 'console')
})
})

15276
dist/index.js vendored

File diff suppressed because one or more lines are too long

4761
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,24 +1,43 @@
{
"name": "github-script",
"version": "0.6.0",
"private": true,
"main": "dist/index.js",
"scripts": {
"build": "ncc build src/main.ts"
},
"description": "A GitHub action for executing a simple script",
"version": "0.9.0",
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.1.0",
"@actions/github": "^1.1.0"
"@actions/core": "^1.2.3",
"@actions/github": "^2.1.1"
},
"devDependencies": {
"@zeit/ncc": "^0.20.5",
"husky": "^4.0.1"
"@types/jest": "^25.1.4",
"@zeit/ncc": "^0.22.0",
"husky": "^4.2.3",
"jest": "^25.1.0",
"ts-jest": "^25.2.1",
"typescript": "^3.8.3"
},
"husky": {
"hooks": {
"pre-commit": "npm run build && git add dist/"
}
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"globals": {
"ts-jest": {
"diagnostics": {
"ignoreCodes": [
"151001"
]
}
}
}
},
"license": "MIT",
"main": "dist/index.js",
"private": true,
"scripts": {
"build": "ncc build src/main.ts",
"test": "jest"
}
}

11
src/async-function.ts Normal file
View File

@@ -0,0 +1,11 @@
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor
type AsyncFunctionArguments = {[key: string]: any}
export function callAsyncFunction(
args: AsyncFunctionArguments,
source: string
): Promise<any> {
const fn = new AsyncFunction(...Object.keys(args), source)
return fn(...Object.values(args))
}

View File

@@ -1,11 +1,11 @@
import * as core from '@actions/core'
import {context, GitHub} from '@actions/github'
import {callAsyncFunction} from './async-function'
process.on('unhandledRejection', handleError)
main().catch(handleError)
async function main() {
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor
const token = core.getInput('github-token', {required: true})
const debug = core.getInput('debug')
const userAgent = core.getInput('user-agent')
@@ -14,10 +14,14 @@ async function main() {
if (debug === 'true') opts.log = console
if (userAgent != null) opts.userAgent = userAgent
if (previews != null) opts.previews = previews.split(',')
const client = new GitHub(token, opts)
const github = new GitHub(token, opts)
const script = core.getInput('script', {required: true})
const fn = new AsyncFunction('require', 'github', 'context', script)
const result = await fn(require, client, context)
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilatin errors.
const result = await callAsyncFunction(
{require: require, github, context, core},
script
)
let encoding = core.getInput('result-encoding')
encoding = encoding ? encoding : 'json'

View File

@@ -1,8 +1,9 @@
{
"compilerOptions": {
"target": "es2018",
"target": "es2018",
"moduleResolution": "node",
"strict": true,
"strict": true,
"forceConsistentCasingInFileNames": true
}
},
"exclude": ["__test__"]
}