Skip to content

Commit cedbec9

Browse files
authored
Merge pull request #5 from mncorreia/feat/prefix-as-optional
feature: prefix as optional
2 parents 531e978 + 4c885ea commit cedbec9

File tree

4 files changed

+89
-83
lines changed

4 files changed

+89
-83
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The prefix. Default value `json`.
3636
uses: antifree/[email protected]
3737
with:
3838
filename: 'test.json'
39-
prefix: test
39+
prefix: ''
4040
- name: Show output
4141
run: echo "The time was ${{ env.test_value }}, ${{ env.test_array_0_value }}, ${{ env.test_obj_value1 }}"
4242
```

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ inputs:
1111
prefix:
1212
description: 'The prefix for variables.'
1313
required: false
14-
default: 'json'
14+
default: ''
1515
runs:
1616
using: 'node16'
1717
main: 'dist/index.js'

dist/index.js

Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,7 @@
1-
module.exports =
21
/******/ (() => { // webpackBootstrap
32
/******/ var __webpack_modules__ = ({
43

5-
/***/ 718:
6-
/***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => {
7-
8-
const fs = __nccwpck_require__(747);
9-
const path = __nccwpck_require__(622);
10-
const core = __nccwpck_require__(979);
11-
12-
try {
13-
const fileName = core.getInput('filename', { required: true });
14-
const prefix = core.getInput('prefix') || 'json';
15-
16-
const fullPath = path.resolve(fileName);
17-
core.info(`Processing file: ${fullPath}`);
18-
19-
const rawdata = fs.readFileSync(fullPath);
20-
const rootObj = JSON.parse(rawdata);
21-
22-
const processVariable = (variable, name) => {
23-
24-
if (typeof variable === 'undefined' || variable === null) {
25-
return;
26-
}
27-
28-
if (Array.isArray(variable)) {
29-
variable.forEach((value, index) => {
30-
processVariable(value, `${name}_${index}`);
31-
});
32-
}
33-
else if (typeof variable === 'object') {
34-
for(const field in variable) {
35-
processVariable(variable[field], `${name}_${field}`);
36-
}
37-
}
38-
else {
39-
core.info(`SET ENV '${name}' = ${variable}`);
40-
core.exportVariable(name, variable.toString());
41-
}
42-
};
43-
44-
processVariable(rootObj, prefix);
45-
46-
} catch (error) {
47-
core.setFailed(error.message);
48-
}
49-
50-
/***/ }),
51-
52-
/***/ 301:
4+
/***/ 207:
535
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
546

557
"use strict";
@@ -62,8 +14,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
6214
return result;
6315
};
6416
Object.defineProperty(exports, "__esModule", ({ value: true }));
65-
const os = __importStar(__nccwpck_require__(87));
66-
const utils_1 = __nccwpck_require__(721);
17+
const os = __importStar(__nccwpck_require__(37));
18+
const utils_1 = __nccwpck_require__(645);
6719
/**
6820
* Commands
6921
*
@@ -135,7 +87,7 @@ function escapeProperty(s) {
13587

13688
/***/ }),
13789

138-
/***/ 979:
90+
/***/ 695:
13991
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
14092

14193
"use strict";
@@ -157,11 +109,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
157109
return result;
158110
};
159111
Object.defineProperty(exports, "__esModule", ({ value: true }));
160-
const command_1 = __nccwpck_require__(301);
161-
const file_command_1 = __nccwpck_require__(689);
162-
const utils_1 = __nccwpck_require__(721);
163-
const os = __importStar(__nccwpck_require__(87));
164-
const path = __importStar(__nccwpck_require__(622));
112+
const command_1 = __nccwpck_require__(207);
113+
const file_command_1 = __nccwpck_require__(271);
114+
const utils_1 = __nccwpck_require__(645);
115+
const os = __importStar(__nccwpck_require__(37));
116+
const path = __importStar(__nccwpck_require__(17));
165117
/**
166118
* The code to exit an action
167119
*/
@@ -380,7 +332,7 @@ exports.getState = getState;
380332

381333
/***/ }),
382334

383-
/***/ 689:
335+
/***/ 271:
384336
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
385337

386338
"use strict";
@@ -396,9 +348,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
396348
Object.defineProperty(exports, "__esModule", ({ value: true }));
397349
// We use any as a valid input type
398350
/* eslint-disable @typescript-eslint/no-explicit-any */
399-
const fs = __importStar(__nccwpck_require__(747));
400-
const os = __importStar(__nccwpck_require__(87));
401-
const utils_1 = __nccwpck_require__(721);
351+
const fs = __importStar(__nccwpck_require__(147));
352+
const os = __importStar(__nccwpck_require__(37));
353+
const utils_1 = __nccwpck_require__(645);
402354
function issueCommand(command, message) {
403355
const filePath = process.env[`GITHUB_${command}`];
404356
if (!filePath) {
@@ -416,7 +368,7 @@ exports.issueCommand = issueCommand;
416368

417369
/***/ }),
418370

419-
/***/ 721:
371+
/***/ 645:
420372
/***/ ((__unused_webpack_module, exports) => {
421373

422374
"use strict";
@@ -442,27 +394,27 @@ exports.toCommandValue = toCommandValue;
442394

443395
/***/ }),
444396

445-
/***/ 747:
397+
/***/ 147:
446398
/***/ ((module) => {
447399

448400
"use strict";
449-
module.exports = require("fs");;
401+
module.exports = require("fs");
450402

451403
/***/ }),
452404

453-
/***/ 87:
405+
/***/ 37:
454406
/***/ ((module) => {
455407

456408
"use strict";
457-
module.exports = require("os");;
409+
module.exports = require("os");
458410

459411
/***/ }),
460412

461-
/***/ 622:
413+
/***/ 17:
462414
/***/ ((module) => {
463415

464416
"use strict";
465-
module.exports = require("path");;
417+
module.exports = require("path");
466418

467419
/***/ })
468420

@@ -474,8 +426,9 @@ module.exports = require("path");;
474426
/******/ // The require function
475427
/******/ function __nccwpck_require__(moduleId) {
476428
/******/ // Check if module is in cache
477-
/******/ if(__webpack_module_cache__[moduleId]) {
478-
/******/ return __webpack_module_cache__[moduleId].exports;
429+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
430+
/******/ if (cachedModule !== undefined) {
431+
/******/ return cachedModule.exports;
479432
/******/ }
480433
/******/ // Create a new module (and put it into the cache)
481434
/******/ var module = __webpack_module_cache__[moduleId] = {
@@ -500,10 +453,59 @@ module.exports = require("path");;
500453
/************************************************************************/
501454
/******/ /* webpack/runtime/compat */
502455
/******/
503-
/******/ __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
504-
/******/ // module exports must be returned from runtime so entry inlining is disabled
505-
/******/ // startup
506-
/******/ // Load entry module and return exports
507-
/******/ return __nccwpck_require__(718);
456+
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
457+
/******/
458+
/************************************************************************/
459+
var __webpack_exports__ = {};
460+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
461+
(() => {
462+
const fs = __nccwpck_require__(147);
463+
const path = __nccwpck_require__(17);
464+
const core = __nccwpck_require__(695);
465+
466+
try {
467+
const fileName = core.getInput('filename', { required: true });
468+
const prefix = core.getInput('prefix') || '';
469+
const fullPath = path.resolve(fileName);
470+
core.info(`Processing file: ${fullPath}`);
471+
472+
const rawdata = fs.readFileSync(fullPath);
473+
const rootObj = JSON.parse(rawdata);
474+
475+
const processVariable = (variable, name) => {
476+
477+
if (typeof variable === 'undefined' || variable === null) {
478+
return;
479+
}
480+
481+
if (Array.isArray(variable)) {
482+
variable.forEach((value, index) => {
483+
processVariable(value, `${name}_${index}`);
484+
});
485+
}
486+
else if (typeof variable === 'object') {
487+
for(const key in variable) {
488+
if(rootObj.hasOwnProperty(key)){
489+
processVariable(variable[key], `key`);
490+
}
491+
else {
492+
processVariable(variable[key], `${name}_${key}`);
493+
}
494+
}
495+
}
496+
else {
497+
core.info(`SET ENV '${prefix}${name}' = ${variable}`);
498+
core.exportVariable(name, variable.toString());
499+
}
500+
};
501+
502+
processVariable(rootObj);
503+
504+
} catch (error) {
505+
core.setFailed(error.message);
506+
}
507+
})();
508+
509+
module.exports = __webpack_exports__;
508510
/******/ })()
509511
;

index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const core = require('@actions/core');
44

55
try {
66
const fileName = core.getInput('filename', { required: true });
7-
const prefix = core.getInput('prefix') || 'json';
8-
7+
const prefix = core.getInput('prefix') || '';
98
const fullPath = path.resolve(fileName);
109
core.info(`Processing file: ${fullPath}`);
1110

@@ -24,17 +23,22 @@ try {
2423
});
2524
}
2625
else if (typeof variable === 'object') {
27-
for(const field in variable) {
28-
processVariable(variable[field], `${name}_${field}`);
26+
for(const key in variable) {
27+
if(rootObj.hasOwnProperty(key)){
28+
processVariable(variable[key], key);
29+
}
30+
else {
31+
processVariable(variable[key], `${name}_${key}`);
32+
}
2933
}
3034
}
3135
else {
32-
core.info(`SET ENV '${name}' = ${variable}`);
36+
core.info(`SET ENV '${prefix}${name}' = ${variable}`);
3337
core.exportVariable(name, variable.toString());
3438
}
3539
};
3640

37-
processVariable(rootObj, prefix);
41+
processVariable(rootObj);
3842

3943
} catch (error) {
4044
core.setFailed(error.message);

0 commit comments

Comments
 (0)