-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
137 lines (128 loc) · 5.51 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Run a TypeScript function
description: Helper workflow wrapping actions/github-script with TypeScript
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
dist:
description: >
The primary path to the generated files inside your path directory.
Your build script should generate an index.js at this path.
default: dist
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 }}
module:
description: Module to import if calling actions/github-script directly
value: ${{ steps.module.outputs.module }}
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-v3-${{ runner.os }}-${{ hashFiles(format('{0}/{1}', inputs.path, 'package*.json')) }}
restore-keys: |
github-script-ts-npm-v3-${{ runner.os }}-
- name: Install dependencies
if: inputs.function == ''
shell: bash
working-directory: ${{ inputs.path }}
run: |
npm ci
mkdir -p tmp/dist
echo "${{ inputs.build }}" > tmp/dist/inputs.build
echo "${{ inputs.dist }}" > tmp/dist/inputs.dist
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
if: inputs.function == ''
id: build-cache
with:
path: |
${{ inputs.path }}/${{ inputs.dist }}
key: |
github-script-ts-build-v3-${{ runner.os }}-${{ hashFiles(format('{0}/{1}', inputs.path, 'tmp/dist/inputs.*'), format('{0}/{1}', inputs.path, 'package*.json'), format('{0}/{1}', inputs.path, '**/*.ts'), format('{0}/{1}', inputs.path, '**/*.js')) }}
- name: Build
if: inputs.function == '' && steps.build-cache.outputs.cache-hit != 'true'
shell: bash
working-directory: ${{ inputs.path }}
run: |
${{ inputs.build }}
- name: Set module output
id: module
shell: bash
run: |
echo "module=${{ github.workspace }}/${{ inputs.path }}/${{ inputs.dist }}/index.js" >> "$GITHUB_OUTPUT"
- 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('${{ steps.module.outputs.module }}')
return await ${{ env.FUNCTION_NAME }}(${{ inputs.args }});