-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
121 lines (113 loc) · 4.87 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: "Run a TypeScript function"
description: "Runs a TypeScript script using actions/github-script"
inputs:
github-token:
description: The GitHub token used to create an authenticated client
default: ${{ github.token }}
path:
description: "Path to the functions"
default: ./.github
required: true
module:
description: The generated file exporting all of the functions from the module. Defaults to 'src/index.js'.
default: src/index.js
build:
description: Build command. This command is expected to generate an index.js in the path directory.
default: npm run build
function:
description: "Name of the function to call"
default: ""
args:
description: "Arguments to pass to the function"
default: "{github, context, core, exec, io, fetch}"
debug:
description: Whether to tell the GitHub client to log details of its requests. true or false. Default is to run in debug mode when the GitHub Actions step debug logging is turned on.
default: ${{ runner.debug == '1' }}
user-agent:
description: An optional user-agent string
default: actions/github-script
previews:
description: A comma-separated list of API previews to accept
result-encoding:
description: |
How the result will be encoded. Either "string" or "json" (default "string").
default: string
retries:
description: The number of times to retry a request
default: "0"
retry-exempt-status-codes:
description: A comma separated list of status codes that will NOT be retried e.g. "400,500". No effect unless `retries` is set
default: 400,401,403,404,422 # from https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14
outputs:
result:
description: "Result of the script"
value: ${{ steps.script.outputs.result }}
runs:
using: "composite"
steps:
- name: Setup environment
if: inputs.function == ''
shell: bash
run: |
test -f .nvmrc || exit 0
NODE_VERSION=$(cat .nvmrc | xargs)
echo "node_version=$NODE_VERSION" >> $GITHUB_ENV
- name: Setup node
if: inputs.function == ''
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: ${{ env.node_version }}
cache: npm
cache-dependency-path: ${{ inputs.path }}/package-lock.json
- name: Get npm cache directory
if: inputs.function == ''
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
if: inputs.function == ''
id: npm-cache
with:
path: |
${{ steps.npm-cache-dir.outputs.dir }}
key: |
github-script-ts-npm-v2-${{ runner.os }}-${{ hashFiles(format('{0}/{1}', inputs.path, 'package-lock.json')) }}
restore-keys: |
github-script-ts-npm-v2-${{ runner.os }}-
- name: Install dependencies
if: inputs.function == ''
shell: bash
run: |
cd ${{ inputs.path }}
npm ci
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
if: inputs.function == ''
id: build-cache
with:
path: |
${{ inputs.path }}
key: |
github-script-ts-build-v2-${{ runner.os }}-${{ hashFiles(format('{0}/{1}', inputs.path, 'package-lock.json')) }}-${{ hashFiles(format('{0}/{1}', inputs.path, '**/*.ts')) }}
- name: Build
if: inputs.function == '' && steps.build-cache.outputs.cache-hit != 'true'
shell: bash
working-directory: ${{ inputs.path }}
run: |
${{ inputs.build }}
- name: "Execute script"
if: inputs.function != ''
id: script
uses: "actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410" # v6.4.1
env:
FUNCTION_NAME: ${{ inputs.function }}
with:
result-encoding: ${{ inputs.result-encoding }}
retries: ${{ inputs.retries }}
user-agent: ${{ inputs.user-agent }}
debug: ${{ inputs.debug }}
github-token: ${{ inputs.github-token }}
previews: ${{ inputs.previews }}
retry-exempt-status-codes: ${{ inputs.retry-exempt-status-codes }}
script: |
const { ${{ env.FUNCTION_NAME }} } = await import('${{ github.workspace }}/${{ inputs.path }}/${{ inputs.module }}')
return await ${{ env.FUNCTION_NAME }}(${{ inputs.args }});