forked from andstor/file-reader-action
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f25421
commit 437e07d
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as core from '@actions/core'; | ||
import fs from 'fs'; | ||
import util from 'util'; | ||
|
||
async function run(): Promise<void> { | ||
try { | ||
const filePath = core.getInput('path'); | ||
const encoding = core.getInput('encoding'); | ||
const readFile = util.promisify(fs.readFile); | ||
const contents = await readFile(filePath, encoding); | ||
core.info(`File contents:\n${contents}`); | ||
|
||
// Write to environment file | ||
const outputFilePath = process.env.GITHUB_ENV || ''; | ||
if (outputFilePath) { | ||
const output = `contents<<EOF\n${contents}\nEOF`; | ||
await fs.promises.appendFile(outputFilePath, output + '\n'); | ||
} else { | ||
core.warning('GITHUB_ENV not defined. Cannot write to environment file.'); | ||
} | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
run(); |