mirror of
https://github.com/actions/toolkit.git
synced 2026-08-12 00:00:17 +02:00
Add File Commands (#571)
* Add File Commands * pr updates w/ feedback * run format * fix lint/format * slight update with an example in the docs * pr feedback
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
// For internal use, subject to change.
|
||||
|
||||
// We use any as a valid input type
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
import * as fs from 'fs'
|
||||
import * as os from 'os'
|
||||
import {toCommandValue} from './utils'
|
||||
|
||||
export function issueCommand(command: string, message: any): void {
|
||||
const filePath = process.env[`GITHUB_${command}`]
|
||||
if (!filePath) {
|
||||
throw new Error(
|
||||
`Unable to find environment variable for file command ${command}`
|
||||
)
|
||||
}
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw new Error(`Missing file at path: ${filePath}`)
|
||||
}
|
||||
|
||||
fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user