Skip to content

Commit 227b70b

Browse files
committed
Merge branch 'main' into codespaces-universe-megabranch
2 parents 980cc55 + e773d1f commit 227b70b

651 files changed

Lines changed: 4102 additions & 3556 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { readFileSync } from 'fs'
2+
3+
// Parses the action event payload sets repo and owner to an object from runner environment
4+
export function getActionContext() {
5+
const context = JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8'))
6+
if (context.repository) {
7+
context.owner = context.repository.owner.login
8+
context.repo = context.repository.name
9+
} else {
10+
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/')
11+
context.owner = owner
12+
context.repo = repo
13+
}
14+
return context
15+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const timeInstances = new Map()
2+
3+
/* Meant to be called before debugTimeEnd with the same instanceName to behave like console.time() */
4+
export function debugTimeStart(core, instanceName) {
5+
if (timeInstances.has(instanceName)) {
6+
core.warn(`instanceName: ${instanceName} has already been used for a debug instance.`)
7+
return
8+
}
9+
10+
timeInstances.set(instanceName, new Date())
11+
}
12+
13+
/* Meant to be called after debugTimeStart with the same instanceName to behave like console.timeEnd() */
14+
export function debugTimeEnd(core, instanceName) {
15+
if (!timeInstances.has(instanceName)) {
16+
core.warn(
17+
`Invalid instanceName: ${instanceName} in debugTimeEnd. Did you call debugTimeStart first with the same instanceName?`
18+
)
19+
return
20+
}
21+
const startTime = timeInstances.get(instanceName)
22+
const ms = new Date().getTime() - startTime.getTime()
23+
const seconds = ms / 1000
24+
const minutes = seconds / 60
25+
let display = `${ms.toFixed(1)} ms`
26+
if (minutes > 1) {
27+
display = `${minutes.toFixed(1)} minutes`
28+
} else if (seconds > 1) {
29+
display = `${seconds.toFixed(1)} seconds`
30+
}
31+
core.debug(`Completed ${instanceName} in ${display}`)
32+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Validates and returns an object of expected environment variables
3+
*
4+
* @param {Array<string>} options - Array of environment variables expected
5+
*
6+
* @returns {Object} - key value of expected env variables and their values
7+
*/
8+
export function getEnvInputs(options) {
9+
return Object.fromEntries(
10+
options.map((envVarName) => {
11+
const envVarValue = process.env[envVarName]
12+
if (!envVarValue) {
13+
throw new Error(`You must supply a ${envVarName} environment variable`)
14+
}
15+
return [envVarName, envVarValue]
16+
})
17+
)
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
import fs from 'fs'
3+
4+
/* Writes string to file to be uploaded as an action artifact.
5+
* Useful for debugging or passing results to downstream action
6+
*
7+
* @param {string} name - name of artifact
8+
* @param {string} contents - string contents of artifact
9+
*/
10+
export async function uploadArtifact(name, contents) {
11+
if (!fs.existsSync('./artifacts')) {
12+
fs.mkdirSync('./artifacts/')
13+
}
14+
const filePath = `./artifacts/${name}`
15+
fs.writeFileSync(filePath, contents)
16+
}

0 commit comments

Comments
 (0)