Compare commits

..
3 Commits
Author SHA1 Message Date
Francesco Renzi ffc2c79a5b Merge pull request #348 from actions/rentziass/core-v3
Upgrade @actions/core to 1.10.0 for v3
2023-03-10 17:18:05 +00:00
Francesco Renzi 1ef439ceeb Bump version to 3.2.0 2023-03-10 16:57:58 +00:00
Francesco Renzi b86401ed73 Upgrade @actions/core to 1.10.0 2023-03-10 16:53:12 +00:00
15 changed files with 8907 additions and 5467 deletions

No files matched your search

-52
View File
@@ -1,52 +0,0 @@
# `dist/index.js` is a special file in Actions.
# When you reference an action with `uses:` in a workflow,
# `index.js` is the code that will run.
# For our project, we generate this file through a build process
# from other source files.
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
name: Check dist/
on:
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:
jobs:
check-dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install dependencies
run: npm ci
- name: Rebuild the dist/ directory
run: npm run build
- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff
# If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v2
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: dist/
+8 -7
View File
@@ -1,20 +1,21 @@
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
push: {branches: main}
pull_request: {branches: main}
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v1
with: {node-version: 13.x}
- uses: actions/cache@v1
with:
node-version: 12
cache: npm
path: ~/.npm
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
restore-keys: ${{runner.os}}-npm-
- run: npm ci
- run: npm run style:check
- run: npm test
+3 -43
View File
@@ -1,18 +1,14 @@
name: Integration
on:
push:
branches: [main]
pull_request:
branches: [main]
push: {branches: main}
jobs:
test-return:
integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- id: output-set
uses: ./
uses: actions/github-script@main
with:
script: return core.getInput('input-value')
result-encoding: string
@@ -21,39 +17,3 @@ jobs:
if [[ "${{steps.output-set.outputs.result}}" != "output" ]]; then
exit 1
fi
test-relative-require:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- id: output-set
uses: ./
with:
script: return require('./package.json').name
result-encoding: string
input-value: output
- run: |
if [[ "${{steps.output-set.outputs.result}}" != "github-script" ]]; then
exit 1
fi
test-npm-require:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
restore-keys: ${{runner.os}}-npm-
- run: npm ci
- id: output-set
uses: ./
with:
script: return require('@actions/core/package.json').name
result-encoding: string
input-value: output
- run: |
if [[ "${{steps.output-set.outputs.result}}" != "@actions/core" ]]; then
exit 1
fi
+11 -8
View File
@@ -1,12 +1,10 @@
name: Licensed
on:
push:
branches:
- main
pull_request:
branches:
- main
push: {branches: main}
pull_request: {branches: main}
repository_dispatch:
workflow_dispatch:
jobs:
test:
@@ -14,11 +12,16 @@ jobs:
name: Check licenses
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: ~/.npm
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
restore-keys: ${{runner.os}}-npm-
- run: npm ci
- name: Install licensed
run: |
run: |-
cd $RUNNER_TEMP
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.12.2/licensed-2.12.2-linux-x64.tar.gz
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.9.2/licensed-2.9.2-linux-x64.tar.gz
sudo tar -xzf licensed.tar.gz
sudo mv licensed /usr/local/bin/licensed
- run: licensed status
+1 -1
View File
@@ -2,7 +2,7 @@ name: Pull Request Test
on:
pull_request:
branches: [main]
branches: main
types: [opened, synchronize]
jobs:
Binary file not shown.
Binary file not shown.
+25 -88
View File
@@ -12,19 +12,12 @@ input should be the body of an asynchronous function call. The following
arguments will be provided:
- `github` A pre-authenticated
[octokit/rest.js](https://octokit.github.io/rest.js) client with pagination plugins
[octokit/core.js](https://github.com/octokit/core.js#readme) client with REST endpoints and pagination plugins
- `context` An object containing the [context of the workflow
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
- `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
- `exec` A reference to the [@actions/exec](https://github.com/actions/toolkit/tree/main/packages/exec) package
- `require` A proxy wrapper around the normal Node.js `require` to enable
requiring relative paths (relative to the current working directory) and
requiring npm packages installed in the current working directory. If for
some reason you need the non-wrapped `require`, there is an escape hatch
available: `__original_require__` is the original value of `require` without
our wrapping applied.
Since the `script` is just a function body, these values will already be
defined, so you don't have to (see examples below).
@@ -45,7 +38,7 @@ The return value of the script will be in the step's outputs under the
"result" key.
```yaml
- uses: actions/github-script@v4
- uses: actions/github-script@v3
id: set-result
with:
script: return "Hello!"
@@ -64,9 +57,10 @@ output of a github-script step. For some workflows, string encoding is preferred
`result-encoding` input:
```yaml
- uses: actions/github-script@v4
- uses: actions/github-script@v3
id: my-script
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: return "I will be string (not JSON) encoded!"
```
@@ -82,7 +76,7 @@ By default, github-script will use the token provided to your workflow.
```yaml
- name: View context attributes
uses: actions/github-script@v4
uses: actions/github-script@v3
with:
script: console.log(context)
```
@@ -98,8 +92,9 @@ jobs:
comment:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v4
- uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
@@ -120,8 +115,9 @@ jobs:
apply-label:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v4
- uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.addLabels({
issue_number: context.issue.number,
@@ -140,8 +136,9 @@ jobs:
welcome:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v4
- uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// Get a list of all issues created by the PR opener
// See: https://octokit.github.io/rest.js/#pagination
@@ -183,8 +180,9 @@ jobs:
diff:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v4
- uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const diff_url = context.payload.pull_request.diff_url
const result = await github.request(diff_url)
@@ -207,8 +205,9 @@ jobs:
list-issues:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v4
- uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const query = `query($owner:String!, $name:String!, $label:String!) {
repository(owner:$owner, name:$name){
@@ -241,13 +240,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/github-script@v4
- uses: actions/github-script@v3
with:
script: |
const script = require('./path/to/script.js')
const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`)
console.log(script({github, context}))
```
_Note that the script path given to `require()` must be an **absolute path** in this case, hence using [`GITHUB_WORKSPACE`](https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables)._
And then export a function from your module:
```javascript
@@ -256,6 +257,9 @@ module.exports = ({github, context}) => {
}
```
You can also use async functions in this manner, as long as you `await` it in
the inline script.
Note that because you can't `require` things like the GitHub context or
Actions Toolkit libraries, you'll want to pass them as arguments to your
external function.
@@ -264,44 +268,6 @@ Additionally, you'll want to use the [checkout
action](https://github.com/actions/checkout) to make sure your script file is
available.
### Run a separate file with an async function
You can also use async functions in this manner, as long as you `await` it in
the inline script.
In your workflow:
```yaml
on: push
jobs:
echo-input:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/github-script@v4
env:
SHA: '${{env.parentSHA}}'
with:
script: |
const script = require('./path/to/script.js')
await script({github, context, core})
```
And then export an async function from your module:
```javascript
module.exports = async ({github, context, core}) => {
const {SHA} = process.env
const commit = await github.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `${SHA}`
})
core.exportVariable('author', commit.data.commit.author.email)
}
```
### Use npm packages
Like importing your own files above, you can also use installed modules:
@@ -320,10 +286,10 @@ jobs:
- run: npm ci
# or one-off:
- run: npm install execa
- uses: actions/github-script@v4
- uses: actions/github-script@v3
with:
script: |
const execa = require('execa')
const execa = require(`${process.env.GITHUB_WORKSPACE}/node_modules/execa`)
const { stdout } = await execa('echo', ['hello', 'world'])
@@ -341,7 +307,7 @@ jobs:
echo-input:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v4
- uses: actions/github-script@v3
env:
FIRST_NAME: Mona
LAST_NAME: Octocat
@@ -351,32 +317,3 @@ jobs:
console.log(`Hello ${FIRST_NAME} ${LAST_NAME}`)
```
### Using a separate GitHub token
The `GITHUB_TOKEN` used by default is scoped to the current repository, see [Authentication in a workflow](https://docs.github.com/actions/reference/authentication-in-a-workflow).
If you need access to a different repository or an API that the `GITHUB_TOKEN` doesn't have permissions to, you can provide your own [PAT](https://help.github.com/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) as a secret using the `github-token` input.
[Learn more about creating and using encrypted secrets](https://docs.github.com/actions/reference/encrypted-secrets)
```yaml
on:
issues:
types: [opened]
jobs:
apply-label:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v4
with:
github-token: ${{ secrets.MY_PAT }}
script: |
github.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Triage']
})
```
+2188 -923
View File
File diff suppressed because it is too large. Load diff
+6660 -4293
View File
File diff suppressed because it is too large. Load diff
+10 -11
View File
@@ -1,7 +1,7 @@
{
"name": "github-script",
"description": "A GitHub action for executing a simple script",
"version": "4.0.2",
"version": "3.2.0",
"author": "GitHub",
"license": "MIT",
"main": "dist/index.js",
@@ -35,8 +35,7 @@
}
},
"dependencies": {
"@actions/core": "^1.2.7",
"@actions/exec": "^1.1.0",
"@actions/core": "^1.10.0",
"@actions/github": "^4.0.0",
"@actions/glob": "^0.1.1",
"@actions/io": "^1.0.2",
@@ -45,17 +44,17 @@
"@octokit/plugin-rest-endpoint-methods": "4.2.1"
},
"devDependencies": {
"@types/jest": "^26.0.24",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"@types/jest": "^26.0.10",
"@typescript-eslint/eslint-plugin": "^3.9.1",
"@typescript-eslint/parser": "^3.9.1",
"@vercel/ncc": "^0.23.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^6.15.0",
"eslint": "^7.7.0",
"eslint-config-prettier": "^6.11.0",
"husky": "^4.2.5",
"jest": "^26.6.3",
"jest": "^26.4.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.5",
"ts-jest": "^26.5.6",
"typescript": "^4.3.5"
"ts-jest": "^26.2.0",
"typescript": "^4.0.2"
}
}
-3
View File
@@ -1,5 +1,4 @@
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import {Context} from '@actions/github/lib/context'
import {GitHub} from '@actions/github/lib/utils'
import * as glob from '@actions/glob'
@@ -11,11 +10,9 @@ type AsyncFunctionArguments = {
context: Context
core: typeof core
github: InstanceType<typeof GitHub>
exec: typeof exec
glob: typeof glob
io: typeof io
require: NodeRequire
__original_require__: NodeRequire
}
export function callAsyncFunction<T>(
+1 -12
View File
@@ -1,10 +1,8 @@
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import {context, getOctokit} from '@actions/github'
import * as glob from '@actions/glob'
import * as io from '@actions/io'
import {callAsyncFunction} from './async-function'
import {wrapRequire} from './wrap-require'
process.on('unhandledRejection', handleError)
main().catch(handleError)
@@ -31,16 +29,7 @@ async function main(): Promise<void> {
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
const result = await callAsyncFunction(
{
require: wrapRequire,
__original_require__: __non_webpack_require__,
github,
context,
core,
exec,
glob,
io
},
{require: require, github, context, core, glob, io},
script
)
-25
View File
@@ -1,25 +0,0 @@
import * as path from 'path'
export const wrapRequire = new Proxy(__non_webpack_require__, {
apply: (target, thisArg, [moduleID]) => {
if (moduleID.startsWith('.')) {
moduleID = path.resolve(moduleID)
return target.apply(thisArg, [moduleID])
}
const modulePath = target.resolve.apply(thisArg, [
moduleID,
{
// Webpack does not have an escape hatch for getting the actual
// module, other than `eval`.
paths: [process.cwd()]
}
])
return target.apply(thisArg, [modulePath])
},
get: (target, prop, receiver) => {
Reflect.get(target, prop, receiver)
}
})
-1
View File
@@ -1 +0,0 @@
declare const __non_webpack_require__: NodeRequire