Skip to content

Commit

Permalink
Refactor Main.ts to use Env Files
Browse files Browse the repository at this point in the history
  • Loading branch information
wsargent-emcins authored Jun 25, 2024
1 parent c2455e1 commit 59c2f52
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import * as core from '@actions/core'
import fs from 'fs'
import util from 'util'
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}`)
core.setOutput('contents', contents)
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)
core.setFailed(error.message);
}
}

run()
run();

0 comments on commit 59c2f52

Please sign in to comment.