more test coverage (#18)
Signed-off-by: Brian DeHamer <[email protected]>
This commit is contained in:
+5
-17
@@ -1,6 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
import type { Predicate } from '@actions/attest'
|
||||
|
||||
// Returns the predicate specified by the action's inputs. The predicate value
|
||||
@@ -14,25 +14,13 @@ export const predicateFromInputs = (): Predicate => {
|
||||
throw new Error('One of predicate-path or predicate must be provided')
|
||||
}
|
||||
|
||||
if (predicatePath && predicateStr) {
|
||||
throw new Error('Only one of predicate-path or predicate may be provided')
|
||||
}
|
||||
|
||||
const params = predicatePath
|
||||
? fs.readFileSync(predicatePath, 'utf-8')
|
||||
: predicateStr
|
||||
|
||||
return { type: predicateType, params: JSON.parse(params) }
|
||||
}
|
||||
|
||||
export const storePredicate = (predicate: Predicate): string => {
|
||||
// random tempfile
|
||||
const basePath = process.env['RUNNER_TEMP']
|
||||
|
||||
if (!basePath) {
|
||||
throw new Error('Missing RUNNER_TEMP environment variable')
|
||||
}
|
||||
|
||||
const tmpDir = fs.mkdtempSync(path.join(basePath, path.sep))
|
||||
const tempFile = path.join(tmpDir, 'predicate.json')
|
||||
|
||||
// write predicate to file
|
||||
fs.writeFileSync(tempFile, JSON.stringify(predicate.params))
|
||||
return tempFile
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user