mirror of
https://github.com/actions/github-script.git
synced 2026-10-15 20:06:55 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f05a81df23 | ||
|
|
74ae80c200 | ||
|
|
7488ca4f39 | ||
|
|
8920b9a6ed | ||
|
|
8685086334 | ||
|
|
01dfe2e0c1 | ||
|
|
934655b9e0 | ||
|
|
a56d4504de | ||
|
|
3d069b2f0c | ||
|
|
77c8747753 | ||
|
|
e86864dfd7 | ||
|
|
58e7e1dbfa | ||
|
|
b251c3e139 | ||
|
|
5b5c43cb7b | ||
|
|
74776b4afc | ||
|
|
01904b97ff | ||
|
|
315fb4f388 | ||
|
|
5c9e354ff0 | ||
|
|
2f21207c8d | ||
|
|
1318dc37ba | ||
|
|
f4f25ebaab | ||
|
|
b91d578158 | ||
|
|
a52e7f4cf4 | ||
|
|
b714c526d7 | ||
|
|
96374ece58 |
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
|
name: Pull Request Test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: main
|
branches: main
|
||||||
@@ -22,18 +24,22 @@ jobs:
|
|||||||
const botComment = comments.find(comment => comment.user.id === 41898282)
|
const botComment = comments.find(comment => comment.user.id === 41898282)
|
||||||
const commentBody = "Hello from actions/github-script! (${{ github.sha }})"
|
const commentBody = "Hello from actions/github-script! (${{ github.sha }})"
|
||||||
|
|
||||||
if (botComment) {
|
if (context.payload.pull_request.head.repo.full_name !== 'actions/github-script') {
|
||||||
await github.issues.updateComment({
|
console.log('Not attempting to write comment on PR from fork');
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
comment_id: botComment.id,
|
|
||||||
body: commentBody
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
await github.issues.createComment({
|
if (botComment) {
|
||||||
owner: context.repo.owner,
|
await github.issues.updateComment({
|
||||||
repo: context.repo.repo,
|
owner: context.repo.owner,
|
||||||
issue_number: context.payload.number,
|
repo: context.repo.repo,
|
||||||
body: commentBody
|
comment_id: botComment.id,
|
||||||
})
|
body: commentBody
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await github.issues.createComment({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: context.payload.number,
|
||||||
|
body: commentBody
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
* @actions/actions-experience
|
||||||
@@ -16,6 +16,7 @@ arguments will be provided:
|
|||||||
- `context` An object containing the [context of the workflow
|
- `context` An object containing the [context of the workflow
|
||||||
run](https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts)
|
run](https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts)
|
||||||
- `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package
|
- `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package
|
||||||
|
- `glob` A reference to the [@actions/glob](https://github.com/actions/toolkit/tree/main/packages/glob) package
|
||||||
- `io` A reference to the [@actions/io](https://github.com/actions/toolkit/tree/main/packages/io) package
|
- `io` A reference to the [@actions/io](https://github.com/actions/toolkit/tree/main/packages/io) package
|
||||||
|
|
||||||
Since the `script` is just a function body, these values will already be
|
Since the `script` is just a function body, these values will already be
|
||||||
@@ -71,6 +72,15 @@ in case you need to use a non-default token.
|
|||||||
|
|
||||||
By default, github-script will use the token provided to your workflow.
|
By default, github-script will use the token provided to your workflow.
|
||||||
|
|
||||||
|
### Print the available attributes of context
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: View context attributes
|
||||||
|
uses: actions/github-script@v3
|
||||||
|
with:
|
||||||
|
script: console.log(context)
|
||||||
|
```
|
||||||
|
|
||||||
### Comment on an issue
|
### Comment on an issue
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@@ -191,16 +201,15 @@ contain the actual diff text.
|
|||||||
You can use the `github.graphql` object to run custom GraphQL queries against the GitHub API.
|
You can use the `github.graphql` object to run custom GraphQL queries against the GitHub API.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
list-packages:
|
list-issues:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v3
|
- uses: actions/github-script@v3
|
||||||
with:
|
with:
|
||||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
script: |
|
script: |
|
||||||
const query = `query($owner:String!, $name:String!) {
|
const query = `query($owner:String!, $name:String!, $label:String!) {
|
||||||
repository(owner:$owner, name:$name){
|
repository(owner:$owner, name:$name){
|
||||||
issues(first:100, labels: [$label]) {
|
issues(first:100, labels: [$label]) {
|
||||||
nodes {
|
nodes {
|
||||||
@@ -216,7 +225,6 @@ jobs:
|
|||||||
}
|
}
|
||||||
const result = await github.graphql(query, variables)
|
const result = await github.graphql(query, variables)
|
||||||
console.log(result)
|
console.log(result)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run a separate file
|
### Run a separate file
|
||||||
@@ -232,7 +240,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/github-script@v2
|
- uses: actions/github-script@v3
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`)
|
const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`)
|
||||||
@@ -259,3 +267,53 @@ external function.
|
|||||||
Additionally, you'll want to use the [checkout
|
Additionally, you'll want to use the [checkout
|
||||||
action](https://github.com/actions/checkout) to make sure your script file is
|
action](https://github.com/actions/checkout) to make sure your script file is
|
||||||
available.
|
available.
|
||||||
|
|
||||||
|
### Use npm packages
|
||||||
|
|
||||||
|
Like importing your own files above, you can also use installed modules:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
echo-input:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 14
|
||||||
|
- run: npm ci
|
||||||
|
# or one-off:
|
||||||
|
- run: npm install execa
|
||||||
|
- uses: actions/github-script@v3
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const execa = require(`${process.env.GITHUB_WORKSPACE}/node_modules/execa`)
|
||||||
|
|
||||||
|
const { stdout } = await execa('echo', ['hello', 'world'])
|
||||||
|
|
||||||
|
console.log(stdout)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Use env as input
|
||||||
|
|
||||||
|
You can set env vars to use them in your script:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
echo-input:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/github-script@v3
|
||||||
|
env:
|
||||||
|
FIRST_NAME: Mona
|
||||||
|
LAST_NAME: Octocat
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const { FIRST_NAME, LAST_NAME } = process.env
|
||||||
|
|
||||||
|
console.log(`Hello ${FIRST_NAME} ${LAST_NAME}`)
|
||||||
|
```
|
||||||
Vendored
+2211
-1
File diff suppressed because it is too large.
Load diff
Generated
+9120
-26
File diff suppressed because it is too large.
Load diff
+2
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "github-script",
|
"name": "github-script",
|
||||||
"description": "A GitHub action for executing a simple script",
|
"description": "A GitHub action for executing a simple script",
|
||||||
"version": "3.1.0",
|
"version": "3.1.1",
|
||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/github": "^4.0.0",
|
"@actions/github": "^4.0.0",
|
||||||
|
"@actions/glob": "^0.1.1",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"@octokit/core": "^3.2.1",
|
"@octokit/core": "^3.2.1",
|
||||||
"@octokit/plugin-paginate-rest": "^2.6.0",
|
"@octokit/plugin-paginate-rest": "^2.6.0",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {Context} from '@actions/github/lib/context'
|
import {Context} from '@actions/github/lib/context'
|
||||||
import {GitHub} from '@actions/github/lib/utils'
|
import {GitHub} from '@actions/github/lib/utils'
|
||||||
|
import * as glob from '@actions/glob'
|
||||||
import * as io from '@actions/io'
|
import * as io from '@actions/io'
|
||||||
|
|
||||||
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor
|
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor
|
||||||
@@ -9,6 +10,7 @@ type AsyncFunctionArguments = {
|
|||||||
context: Context
|
context: Context
|
||||||
core: typeof core
|
core: typeof core
|
||||||
github: InstanceType<typeof GitHub>
|
github: InstanceType<typeof GitHub>
|
||||||
|
glob: typeof glob
|
||||||
io: typeof io
|
io: typeof io
|
||||||
require: NodeRequire
|
require: NodeRequire
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {context, getOctokit} from '@actions/github'
|
import {context, getOctokit} from '@actions/github'
|
||||||
|
import * as glob from '@actions/glob'
|
||||||
import * as io from '@actions/io'
|
import * as io from '@actions/io'
|
||||||
import {callAsyncFunction} from './async-function'
|
import {callAsyncFunction} from './async-function'
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ async function main(): Promise<void> {
|
|||||||
|
|
||||||
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
||||||
const result = await callAsyncFunction(
|
const result = await callAsyncFunction(
|
||||||
{require: require, github, context, core, io},
|
{require: require, github, context, core, glob, io},
|
||||||
script
|
script
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user