Skip to content

Commit 37335c7

Browse files
authored
Swap to Environment Files (actions#76)
* Swap to env files
1 parent 7ff6287 commit 37335c7

File tree

5 files changed

+106
-44
lines changed

5 files changed

+106
-44
lines changed

.licenses/npm/@actions/core.dep.yml

Lines changed: 10 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__tests__/setup-go.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ describe('setup-go', () => {
3535
let execSpy: jest.SpyInstance;
3636
let getManifestSpy: jest.SpyInstance;
3737

38+
beforeAll(() => {
39+
process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
40+
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
41+
});
42+
3843
beforeEach(() => {
3944
// @actions/core
4045
inputs = {};
@@ -90,7 +95,9 @@ describe('setup-go', () => {
9095
//jest.restoreAllMocks();
9196
});
9297

93-
afterAll(async () => {}, 100000);
98+
afterAll(async () => {
99+
console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions
100+
}, 100000);
94101

95102
it('can find 1.9.7 from manifest on osx', async () => {
96103
os.platform = 'darwin';

dist/index.js

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,13 +1067,75 @@ exports._readLinuxVersionFile = _readLinuxVersionFile;
10671067

10681068
/***/ }),
10691069

1070+
/***/ 82:
1071+
/***/ (function(__unusedmodule, exports) {
1072+
1073+
"use strict";
1074+
1075+
// We use any as a valid input type
1076+
/* eslint-disable @typescript-eslint/no-explicit-any */
1077+
Object.defineProperty(exports, "__esModule", { value: true });
1078+
/**
1079+
* Sanitizes an input into a string so it can be passed into issueCommand safely
1080+
* @param input input to sanitize into a string
1081+
*/
1082+
function toCommandValue(input) {
1083+
if (input === null || input === undefined) {
1084+
return '';
1085+
}
1086+
else if (typeof input === 'string' || input instanceof String) {
1087+
return input;
1088+
}
1089+
return JSON.stringify(input);
1090+
}
1091+
exports.toCommandValue = toCommandValue;
1092+
//# sourceMappingURL=utils.js.map
1093+
1094+
/***/ }),
1095+
10701096
/***/ 87:
10711097
/***/ (function(module) {
10721098

10731099
module.exports = require("os");
10741100

10751101
/***/ }),
10761102

1103+
/***/ 102:
1104+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
1105+
1106+
"use strict";
1107+
1108+
// For internal use, subject to change.
1109+
var __importStar = (this && this.__importStar) || function (mod) {
1110+
if (mod && mod.__esModule) return mod;
1111+
var result = {};
1112+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
1113+
result["default"] = mod;
1114+
return result;
1115+
};
1116+
Object.defineProperty(exports, "__esModule", { value: true });
1117+
// We use any as a valid input type
1118+
/* eslint-disable @typescript-eslint/no-explicit-any */
1119+
const fs = __importStar(__webpack_require__(747));
1120+
const os = __importStar(__webpack_require__(87));
1121+
const utils_1 = __webpack_require__(82);
1122+
function issueCommand(command, message) {
1123+
const filePath = process.env[`GITHUB_${command}`];
1124+
if (!filePath) {
1125+
throw new Error(`Unable to find environment variable for file command ${command}`);
1126+
}
1127+
if (!fs.existsSync(filePath)) {
1128+
throw new Error(`Missing file at path: ${filePath}`);
1129+
}
1130+
fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
1131+
encoding: 'utf8'
1132+
});
1133+
}
1134+
exports.issueCommand = issueCommand;
1135+
//# sourceMappingURL=file-command.js.map
1136+
1137+
/***/ }),
1138+
10771139
/***/ 129:
10781140
/***/ (function(module) {
10791141

@@ -3150,6 +3212,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
31503212
};
31513213
Object.defineProperty(exports, "__esModule", { value: true });
31523214
const os = __importStar(__webpack_require__(87));
3215+
const utils_1 = __webpack_require__(82);
31533216
/**
31543217
* Commands
31553218
*
@@ -3203,28 +3266,14 @@ class Command {
32033266
return cmdStr;
32043267
}
32053268
}
3206-
/**
3207-
* Sanitizes an input into a string so it can be passed into issueCommand safely
3208-
* @param input input to sanitize into a string
3209-
*/
3210-
function toCommandValue(input) {
3211-
if (input === null || input === undefined) {
3212-
return '';
3213-
}
3214-
else if (typeof input === 'string' || input instanceof String) {
3215-
return input;
3216-
}
3217-
return JSON.stringify(input);
3218-
}
3219-
exports.toCommandValue = toCommandValue;
32203269
function escapeData(s) {
3221-
return toCommandValue(s)
3270+
return utils_1.toCommandValue(s)
32223271
.replace(/%/g, '%25')
32233272
.replace(/\r/g, '%0D')
32243273
.replace(/\n/g, '%0A');
32253274
}
32263275
function escapeProperty(s) {
3227-
return toCommandValue(s)
3276+
return utils_1.toCommandValue(s)
32283277
.replace(/%/g, '%25')
32293278
.replace(/\r/g, '%0D')
32303279
.replace(/\n/g, '%0A')
@@ -3258,6 +3307,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
32583307
};
32593308
Object.defineProperty(exports, "__esModule", { value: true });
32603309
const command_1 = __webpack_require__(431);
3310+
const file_command_1 = __webpack_require__(102);
3311+
const utils_1 = __webpack_require__(82);
32613312
const os = __importStar(__webpack_require__(87));
32623313
const path = __importStar(__webpack_require__(622));
32633314
/**
@@ -3284,9 +3335,17 @@ var ExitCode;
32843335
*/
32853336
// eslint-disable-next-line @typescript-eslint/no-explicit-any
32863337
function exportVariable(name, val) {
3287-
const convertedVal = command_1.toCommandValue(val);
3338+
const convertedVal = utils_1.toCommandValue(val);
32883339
process.env[name] = convertedVal;
3289-
command_1.issueCommand('set-env', { name }, convertedVal);
3340+
const filePath = process.env['GITHUB_ENV'] || '';
3341+
if (filePath) {
3342+
const delimiter = '_GitHubActionsFileCommandDelimeter_';
3343+
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
3344+
file_command_1.issueCommand('ENV', commandValue);
3345+
}
3346+
else {
3347+
command_1.issueCommand('set-env', { name }, convertedVal);
3348+
}
32903349
}
32913350
exports.exportVariable = exportVariable;
32923351
/**
@@ -3302,7 +3361,13 @@ exports.setSecret = setSecret;
33023361
* @param inputPath
33033362
*/
33043363
function addPath(inputPath) {
3305-
command_1.issueCommand('add-path', {}, inputPath);
3364+
const filePath = process.env['GITHUB_PATH'] || '';
3365+
if (filePath) {
3366+
file_command_1.issueCommand('PATH', inputPath);
3367+
}
3368+
else {
3369+
command_1.issueCommand('add-path', {}, inputPath);
3370+
}
33063371
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
33073372
}
33083373
exports.addPath = addPath;

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"author": "GitHub",
2424
"license": "MIT",
2525
"dependencies": {
26-
"@actions/core": "^1.2.3",
26+
"@actions/core": "^1.2.6",
2727
"@actions/http-client": "^1.0.6",
2828
"@actions/io": "^1.0.2",
2929
"@actions/tool-cache": "^1.5.5",

0 commit comments

Comments
 (0)