Skip to content

Commit 59c2f52

Browse files
Refactor Main.ts to use Env Files
1 parent c2455e1 commit 59c2f52

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

src/main.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
import * as core from '@actions/core'
2-
import fs from 'fs'
3-
import util from 'util'
1+
import * as core from '@actions/core';
2+
import fs from 'fs';
3+
import util from 'util';
44

55
async function run(): Promise<void> {
66
try {
7-
const filePath = core.getInput('path')
8-
const encoding = core.getInput('encoding')
9-
const readFile = util.promisify(fs.readFile)
10-
const contents = await readFile(filePath, encoding)
11-
core.info(`File contents:\n${contents}`)
12-
core.setOutput('contents', contents)
7+
const filePath = core.getInput('path');
8+
const encoding = core.getInput('encoding');
9+
const readFile = util.promisify(fs.readFile);
10+
const contents = await readFile(filePath, encoding);
11+
core.info(`File contents:\n${contents}`);
12+
13+
// Write to environment file
14+
const outputFilePath = process.env.GITHUB_ENV || '';
15+
if (outputFilePath) {
16+
const output = `contents<<EOF\n${contents}\nEOF`;
17+
await fs.promises.appendFile(outputFilePath, output + '\n');
18+
} else {
19+
core.warning('GITHUB_ENV not defined. Cannot write to environment file.');
20+
}
1321
} catch (error) {
14-
core.setFailed(error.message)
22+
core.setFailed(error.message);
1523
}
1624
}
1725

18-
run()
26+
run();

0 commit comments

Comments
 (0)