Skip to content

Commit

Permalink
use appendFileSync() to set output #3481
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-dmlr committed Oct 28, 2024
1 parent b853eac commit 0a232f9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
1 change: 0 additions & 1 deletion github-actions/scan/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
runtime/
dist/
18 changes: 14 additions & 4 deletions github-actions/scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28268,6 +28268,8 @@ function ensureJsonReportAtBeginning(reportFormats) {

// EXTERNAL MODULE: ./node_modules/@actions/artifact/lib/artifact-client.js
var artifact_client = __nccwpck_require__(2605);
// EXTERNAL MODULE: external "os"
var external_os_ = __nccwpck_require__(2037);
// EXTERNAL MODULE: external "child_process"
var external_child_process_ = __nccwpck_require__(2081);
;// CONCATENATED MODULE: ./src/shell-arg-sanitizer.ts
Expand Down Expand Up @@ -28439,6 +28441,7 @@ function getFieldFromJson(field, jsonData) {




const NEW_LINE_SEPARATOR = '\n';
/**
* Collect all necessary report data, downloads additional report formats (e.g. 'html') if necessary
Expand Down Expand Up @@ -28661,8 +28664,17 @@ function buildSummary(trafficLight, totalFindings, findings) {
*/
function setOutput(field, value, dataFormat) {
value = value !== null && value !== void 0 ? value : (dataFormat === 'number' ? 0 : 'FAILURE');
core.debug(`Output ${field} set to ${value}`);
core.setOutput(field, value.toString()); // Ensure value is converted to a string as GitHub Actions expects output variables to be strings.
let valuestring = value.toString();
core.debug(`Output ${field}=${valuestring}`);
const filePath = process.env[`GITHUB_OUTPUT`];
if (!filePath) {
throw new Error(`Empty environment variable GITHUB_OUTPUT`);
}
if (!external_fs_.existsSync(filePath)) {
throw new Error(`No access to file ${filePath}`);
}
external_fs_.appendFileSync(filePath, `${field}=${valuestring}${external_os_.EOL}`);
// core.setOutput(field, value.toString()); // Ensure value is converted to a string as GitHub Actions expects output variables to be strings.
}

;// CONCATENATED MODULE: ./src/projectname-resolver.ts
Expand Down Expand Up @@ -28699,8 +28711,6 @@ function projectname_resolver_asJsonObject(text) {
}
}

// EXTERNAL MODULE: external "os"
var external_os_ = __nccwpck_require__(2037);
;// CONCATENATED MODULE: ./src/platform-helper.ts

function getPlatform() {
Expand Down
15 changes: 13 additions & 2 deletions github-actions/scan/src/post-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as artifact from '@actions/artifact';
import * as core from '@actions/core';
import * as fs from 'fs';
import * as os from 'os';
import { getWorkspaceDir } from './fs-helper';
import { LaunchContext } from './launcher';
import { logExitCode } from './exitcode';
Expand Down Expand Up @@ -278,7 +279,17 @@ function buildSummary(trafficLight: string, totalFindings: number, findings: { m
function setOutput(field: string, value: any, dataFormat: string) {

value = value ?? (dataFormat === 'number' ? 0 : 'FAILURE');
let valuestring = value.toString()

core.debug(`Output ${field} set to ${value}`);
core.setOutput(field, value.toString()); // Ensure value is converted to a string as GitHub Actions expects output variables to be strings.
core.debug(`Output ${field}=${valuestring}`);

const filePath = process.env[`GITHUB_OUTPUT`];
if (!filePath) {
throw new Error(`Empty environment variable GITHUB_OUTPUT`);
}
if (!fs.existsSync(filePath)) {
throw new Error(`No access to file ${filePath}`);
}
fs.appendFileSync(filePath, `${field}=${valuestring}${os.EOL}`);
// core.setOutput(field, value.toString()); // Ensure value is converted to a string as GitHub Actions expects output variables to be strings.
}

0 comments on commit 0a232f9

Please sign in to comment.