-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
335 lines (293 loc) · 12.3 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions
---
name: Debug GitHub Action
description: Dump GitHub contexts and Runner environment, post action webhook payload to the SMEE.io
author: Dariusz Porowski
branding:
icon: info # https://feathericons.com
color: gray-dark
inputs:
vars-context:
description: vars context
required: false
default: ${{ null }}
secrets-context:
description: secrets context
required: false
default: ${{ null }}
needs-context:
description: needs context
required: false
default: ${{ null }}
inputs-context:
description: inputs context
required: false
default: ${{ null }}
smee:
description: Use SMEE to proxy payloads to SMEE.io. By default, it will not use SMEE.
required: false
default: ${{ false }}
smee-channel:
description: The SMEE channel ID to use. If not provided, ID of the repository will be used.
required: false
default: ${{ null }}
outputs:
smee:
description: SMEE used? If SMEE is not used, it will be false.
value: ${{ steps.smee.outputs.smee }}
smee-url:
description: The SMEE URL to use. If SMEE is not used, it will be empty.
value: ${{ steps.smee.outputs.url }}
runs:
using: composite
steps:
- uses: actions/github-script@v7
if: ${{ always() }}
with:
script: |
// dependencies
const fs = require('fs')
// constraints
const color = '\x1b[34m' // blue
const reset = '\x1b[0m'
const emoji = '⬇️'
const expand = 'expand for details'
const platform = process.platform
// helpers
function groupHeader (group) {
return `${color}${emoji} ${group}${reset} ${expand}`
}
function jsonLogOutput (jsonObj, parse = true) {
const jsonObjParsed = parse ? JSON.parse(jsonObj) : jsonObj
return JSON.stringify(jsonObjParsed, null, 2)
}
// os env vars
await core.group(groupHeader('OS (environment variables)'), async () => {
const envVars = {}
Object.keys(process.env)
.filter(key => !key.startsWith('INPUT_') && !key.startsWith('ACTION_DUMP_'))
.sort()
.forEach(key => {
envVars[key] = process.env[key]
})
core.info(jsonLogOutput(envVars, false))
})
// github context
await core.group(groupHeader('GitHub (github context)'), async () => {
core.info(jsonLogOutput(process.env.ACTION_DUMP_CONTEXT_GITHUB))
})
// env context
await core.group(groupHeader('GitHub (env context)'), async () => {
core.info(jsonLogOutput(process.env.ACTION_DUMP_CONTEXT_ENV))
})
// vars context
const varsContext = process.env.ACTION_DUMP_CONTEXT_VARS
if (varsContext !== '') {
await core.group(groupHeader('GitHub (vars context)'), async () => {
core.info(jsonLogOutput(varsContext))
})
}
// job context
await core.group(groupHeader('GitHub (job context)'), async () => {
core.info(jsonLogOutput(process.env.ACTION_DUMP_CONTEXT_JOB))
})
// steps context
await core.group(groupHeader('GitHub (steps context)'), async () => {
core.info(jsonLogOutput(process.env.ACTION_DUMP_CONTEXT_STEPS))
})
// runner context
await core.group(groupHeader('GitHub (runner context)'), async () => {
core.info(jsonLogOutput(process.env.ACTION_DUMP_CONTEXT_RUNNER))
})
// secrets context
const secretsContext = process.env.ACTION_DUMP_CONTEXT_SECRETS
if (secretsContext !== '') {
await core.group(groupHeader('GitHub (secrets context)'), async () => {
core.info(jsonLogOutput(secretsContext))
})
}
// strategy context
await core.group(groupHeader('GitHub (strategy context)'), async () => {
core.info(jsonLogOutput(process.env.ACTION_DUMP_CONTEXT_STRATEGY))
})
// matrix context
await core.group(groupHeader('GitHub (matrix context)'), async () => {
core.info(jsonLogOutput(process.env.ACTION_DUMP_CONTEXT_MATRIX))
})
// needs context
const needsContext = process.env.ACTION_DUMP_CONTEXT_NEEDS
if (needsContext !== '') {
await core.group(groupHeader('GitHub (needs context)'), async () => {
core.info(jsonLogOutput(needsContext))
})
}
// inputs context
const inputsContext = process.env.ACTION_DUMP_CONTEXT_INPUTS
if (inputsContext !== '') {
await core.group(groupHeader('GitHub (inputs context)'), async () => {
core.info(jsonLogOutput(inputsContext))
})
}
// event file
await core.group(groupHeader('GitHub (event file)'), async () => {
core.info(`path: ${process.env.GITHUB_EVENT_PATH}`)
core.info(jsonLogOutput(fs.readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf-8' }).trim()))
})
// docker
let dockerBinary = 'docker'
if (platform === 'win32') {
dockerBinary = 'docker.exe'
}
let dockerExists = false
try {
await io.which(dockerBinary, true)
dockerExists = true
} catch (err) {
dockerExists = false
}
if (dockerExists) {
// docker version
await core.group(groupHeader('Docker (version)'), async () => {
const { stdout } = await exec.getExecOutput('docker', ['version', '--format', '{{json . }}'], { silent: true, ignoreReturnCode: true })
core.info(jsonLogOutput(stdout.trim()))
})
// docker info
await core.group(groupHeader('Docker (info)'), async () => {
const { stdout } = await exec.getExecOutput('docker', ['info', '--format', '{{json . }}'], { silent: true, ignoreReturnCode: true })
core.info(jsonLogOutput(stdout.trim()))
})
// TODO json output - pretty print
// docker images
await core.group(groupHeader('Docker (images)'), async () => {
const { stdout } = await exec.getExecOutput('docker', ['image', 'ls', '--format', '{{json . }}'], { silent: true, ignoreReturnCode: true })
core.info(stdout.trim())
})
// docker daemon config
let dockerDaemonConfigPath = '/etc/docker/daemon.json'
if (platform === 'win32') {
dockerDaemonConfigPath = `${process.env.ProgramData}\\docker\\config\\daemon.json`
}
if(fs.existsSync(dockerDaemonConfigPath)){
await core.group(groupHeader('Docker (daemon config)'), async () => {
core.info(`path: ${dockerDaemonConfigPath}`)
core.info(jsonLogOutput(fs.readFileSync(core.toPlatformPath(dockerDaemonConfigPath), { encoding: 'utf-8' }).trim()))
})
}
}
if (platform === 'linux' || platform === 'darwin') {
await core.group(groupHeader('OS (file system)'), async () => {
await exec.exec('sh -e -c "df -aPh | jq -R -s \'[split(\\"\\n\\") | .[] | gsub(\\" +\\"; \\" \\") | split(\\" \\") | {filesystem: .[0], size: .[1], used: .[2], avail: .[3], use: .[4], mounted_on: .[5]}]\'"')
})
await core.group(groupHeader('OS (mounts)'), async () => {
await exec.exec('mount')
})
}
// TODO json output
// processor linux
if (platform === 'linux') {
await core.group(groupHeader('OS (processor)'), async () => {
await exec.exec('lscpu')
})
}
// TODO json output
// processor macos
if (platform === 'darwin') {
await core.group(groupHeader('OS (processor)'), async () => {
await exec.exec('sh -e -c "sysctl -a | grep machdep.cpu"')
})
}
if (platform === 'win32') {
// processor windows
await core.group(groupHeader('OS (processor)'), async () => {
await exec.exec('pwsh.exe', ['-Command', 'Get-CimInstance -Class Win32_Processor | Select-Object * -ExcludeProperty Cim* | ConvertTo-Json'])
})
await core.group(groupHeader('OS (computer system)'), async () => {
await exec.exec('pwsh.exe', ['-Command', 'Get-CimInstance -Class Win32_ComputerSystem | Select-Object * -ExcludeProperty Cim* | ConvertTo-Json'])
})
await core.group(groupHeader('OS (operating system)'), async () => {
await exec.exec('pwsh.exe', ['-Command', 'Get-CimInstance -Class Win32_OperatingSystem | Select-Object * -ExcludeProperty Cim* | ConvertTo-Json'])
})
}
env:
# https://docs.github.com/en/actions/learn-github-actions/contexts
ACTION_DUMP_CONTEXT_GITHUB: ${{ toJson(github) }}
ACTION_DUMP_CONTEXT_ENV: ${{ toJson(env) }}
ACTION_DUMP_CONTEXT_VARS: ${{ inputs.vars-context }}
ACTION_DUMP_CONTEXT_JOB: ${{ toJson(job) }}
# ACTION_DUMP_CONTEXT_JOBS: ${{ inputs.jobs-context }}
ACTION_DUMP_CONTEXT_STEPS: ${{ toJson(steps) }}
ACTION_DUMP_CONTEXT_RUNNER: ${{ toJson(runner) }}
ACTION_DUMP_CONTEXT_SECRETS: ${{ inputs.secrets-context }}
ACTION_DUMP_CONTEXT_STRATEGY: ${{ toJson(strategy) }}
ACTION_DUMP_CONTEXT_MATRIX: ${{ toJson(matrix) }}
ACTION_DUMP_CONTEXT_NEEDS: ${{ inputs.needs-context }}
ACTION_DUMP_CONTEXT_INPUTS: ${{ inputs.inputs-context }}
- uses: actions/github-script@v7
if: ${{ inputs.smee == 'true' }}
id: smee
with:
script: |
// helpers
function niceHeader(label, color, emoji, group = false) {
const colors = {
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m'
}
const emojis = {
arrowDown: '⬇️',
stop: '🛑',
warning: '⚠️',
error: '❌',
check: '✅'
}
const reset = '\x1b[0m'
let expand = ''
if (group) {
expand = ' expand for details...'
}
return `${colors[color]}${emojis[emoji]} ${label}${reset}${expand}`
}
const { INPUT_SMEE_CHANNEL, GITHUB_EVENT_NAME, GITHUB_RUN_ID } = process.env
let channel = `${context.repo.owner}-${context.repo.repo}`
if (INPUT_SMEE_CHANNEL !== '' && INPUT_SMEE_CHANNEL !== 'null') {
channel = INPUT_SMEE_CHANNEL
}
// https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#delivery-headers
const headers = {
'X-GitHub-Event': GITHUB_EVENT_NAME,
'X-GitHub-Delivery': GITHUB_RUN_ID
}
const payload = {
...context.payload,
'debug-action': {
eventName: context.eventName,
sha: context.sha,
ref: context.ref,
workflow: context.workflow,
action: context.action,
actor: context.actor,
job: context.job,
runNumber: context.runNumber,
runId: context.runId,
apiUrl: context.apiUrl,
serverUrl: context.serverUrl,
graphqlUrl: context.graphqlUrl
}
}
const url = `https://smee.io/${channel}`
await fetch(url, {
method: 'POST',
body: JSON.stringify(payload),
headers: {
...headers,
'Content-Type': 'application/json'
}
})
core.info(niceHeader(`Your SMEE URL is: ${url}`, 'green', 'check'))
core.info(niceHeader('SMEE only works when your browser tab is active.', 'yellow', 'warning'))
core.setOutput('smee', 'true')
core.setOutput('url', url)
env:
INPUT_SMEE_CHANNEL: ${{ inputs.smee-channel }}