add ci_hostname variable, split up collection of data
This commit is contained in:
parent
68341bd8b8
commit
494a52a721
@ -45,7 +45,7 @@ outputs:
|
|||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "node20"
|
using: "node20"
|
||||||
main: ./dist/index.js
|
main: ./dist/action.js
|
||||||
|
|
||||||
branding:
|
branding:
|
||||||
icon: git-branch
|
icon: git-branch
|
||||||
|
|||||||
98
dist/index.js
vendored
98
dist/index.js
vendored
@ -556,8 +556,8 @@ class OidcClient {
|
|||||||
const res = yield httpclient
|
const res = yield httpclient
|
||||||
.getJson(id_token_url)
|
.getJson(id_token_url)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
throw new Error(`Failed to get ID Token. \n
|
throw new Error(`Failed to get ID Token. \n
|
||||||
Error Code : ${error.statusCode}\n
|
Error Code : ${error.statusCode}\n
|
||||||
Error Message: ${error.message}`);
|
Error Message: ${error.message}`);
|
||||||
});
|
});
|
||||||
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
|
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
|
||||||
@ -30753,7 +30753,7 @@ module.exports = parseParams
|
|||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/******/ // The module cache
|
/******/ // The module cache
|
||||||
/******/ var __webpack_module_cache__ = {};
|
/******/ var __webpack_module_cache__ = {};
|
||||||
/******/
|
/******/
|
||||||
/******/ // The require function
|
/******/ // The require function
|
||||||
/******/ function __nccwpck_require__(moduleId) {
|
/******/ function __nccwpck_require__(moduleId) {
|
||||||
/******/ // Check if module is in cache
|
/******/ // Check if module is in cache
|
||||||
@ -30767,7 +30767,7 @@ module.exports = parseParams
|
|||||||
/******/ // no module.loaded needed
|
/******/ // no module.loaded needed
|
||||||
/******/ exports: {}
|
/******/ exports: {}
|
||||||
/******/ };
|
/******/ };
|
||||||
/******/
|
/******/
|
||||||
/******/ // Execute the module function
|
/******/ // Execute the module function
|
||||||
/******/ var threw = true;
|
/******/ var threw = true;
|
||||||
/******/ try {
|
/******/ try {
|
||||||
@ -30776,11 +30776,11 @@ module.exports = parseParams
|
|||||||
/******/ } finally {
|
/******/ } finally {
|
||||||
/******/ if(threw) delete __webpack_module_cache__[moduleId];
|
/******/ if(threw) delete __webpack_module_cache__[moduleId];
|
||||||
/******/ }
|
/******/ }
|
||||||
/******/
|
/******/
|
||||||
/******/ // Return the exports of the module
|
/******/ // Return the exports of the module
|
||||||
/******/ return module.exports;
|
/******/ return module.exports;
|
||||||
/******/ }
|
/******/ }
|
||||||
/******/
|
/******/
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/******/ /* webpack/runtime/make namespace object */
|
/******/ /* webpack/runtime/make namespace object */
|
||||||
/******/ (() => {
|
/******/ (() => {
|
||||||
@ -30792,11 +30792,11 @@ module.exports = parseParams
|
|||||||
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
/******/ };
|
/******/ };
|
||||||
/******/ })();
|
/******/ })();
|
||||||
/******/
|
/******/
|
||||||
/******/ /* webpack/runtime/compat */
|
/******/ /* webpack/runtime/compat */
|
||||||
/******/
|
/******/
|
||||||
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
|
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
|
||||||
/******/
|
/******/
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
var __webpack_exports__ = {};
|
var __webpack_exports__ = {};
|
||||||
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
|
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
|
||||||
@ -30811,6 +30811,51 @@ var core = __nccwpck_require__(2186);
|
|||||||
var github = __nccwpck_require__(5438);
|
var github = __nccwpck_require__(5438);
|
||||||
;// CONCATENATED MODULE: external "process"
|
;// CONCATENATED MODULE: external "process"
|
||||||
const external_process_namespaceObject = require("process");
|
const external_process_namespaceObject = require("process");
|
||||||
|
;// CONCATENATED MODULE: ./src/lib.js
|
||||||
|
|
||||||
|
function result_to_output(results) {
|
||||||
|
for (const key in results) {
|
||||||
|
if (!results.hasOwnProperty(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const value = results[key];
|
||||||
|
if (typeof value !== 'string') {
|
||||||
|
core.setOutput(key, JSON.stringify(value)); // TODO support nested objects with key chaining
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.setOutput(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
;// CONCATENATED MODULE: ./src/collect_ci.js
|
||||||
|
|
||||||
|
|
||||||
|
function collect_ci(debug = false, output = false) {
|
||||||
|
const r = {
|
||||||
|
ci_hostname: false
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const url = new URL(github.context.serverUrl);
|
||||||
|
r.ci_hostname = url.hostname;
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
console.log('results for output:', JSON.stringify(r, null, 2));
|
||||||
|
}
|
||||||
|
if (output) {
|
||||||
|
result_to_output(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log('partial results before error: ', JSON.stringify(r, null, 2));
|
||||||
|
core.setFailed(error.message);
|
||||||
|
external_process_namespaceObject.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ./node_modules/semver-parser/modules/common.js
|
;// CONCATENATED MODULE: ./node_modules/semver-parser/modules/common.js
|
||||||
/**
|
/**
|
||||||
* common.js
|
* common.js
|
||||||
@ -31082,28 +31127,10 @@ const promises = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
;// CONCATENATED MODULE: ./src/collect_git.js
|
||||||
;// CONCATENATED MODULE: ./src/gather.js
|
|
||||||
|
|
||||||
|
|
||||||
|
function collect_git(debug = false, output = false) {
|
||||||
|
|
||||||
|
|
||||||
function result_to_output(results) {
|
|
||||||
for (const key in results) {
|
|
||||||
if (!results.hasOwnProperty(key)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const value = results[key];
|
|
||||||
if (typeof value !== "string") {
|
|
||||||
core.setOutput(key, JSON.stringify(value)); // TODO support nested objects with key chaining
|
|
||||||
} else {
|
|
||||||
core.setOutput(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function gather_information(debug = false, output = false) {
|
|
||||||
const r = {
|
const r = {
|
||||||
git_is_branch: false,
|
git_is_branch: false,
|
||||||
git_is_tag: false,
|
git_is_tag: false,
|
||||||
@ -31196,10 +31223,19 @@ function gather_information(debug = false, output = false) {
|
|||||||
;// CONCATENATED MODULE: ./src/index.js
|
;// CONCATENATED MODULE: ./src/index.js
|
||||||
|
|
||||||
|
|
||||||
gather_information(true, true);
|
function collect_all(debug = false, output = false) {
|
||||||
|
collect_ci(debug, output);
|
||||||
|
collect_git(debug, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
;// CONCATENATED MODULE: ./src/action.js
|
||||||
|
|
||||||
|
|
||||||
|
collect_all(true, true);
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
module.exports = __webpack_exports__;
|
module.exports = __webpack_exports__;
|
||||||
/******/ })()
|
/******/ })()
|
||||||
;
|
;
|
||||||
|
|||||||
@ -2,20 +2,20 @@
|
|||||||
"name": "information",
|
"name": "information",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "action.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"bundle": "npm run format:write && npm run package",
|
"bundle": "npm run package",
|
||||||
"ci-test": "jest",
|
"ci-test": "jest",
|
||||||
"format:write": "prettier --write **/*.js",
|
"format:write": "prettier --write **/*.js",
|
||||||
"format:check": "prettier --check **/*.js",
|
"format:check": "prettier --check **/*.js",
|
||||||
"lint": "npx eslint . -c ./.github/linters/.eslintrc.yml",
|
"lint": "npx eslint . -c ./.github/linters/.eslintrc.yml",
|
||||||
"package": "ncc build src/index.js",
|
"package": "ncc build src/action.js",
|
||||||
"package:watch": "npm run package -- --watch",
|
"package:watch": "npm run package -- --watch",
|
||||||
"test": "(jest && make-coverage-badge --output-path ./badges/coverage.svg) || make-coverage-badge --output-path ./badges/coverage.svg",
|
"test": "(jest && make-coverage-badge --output-path ./badges/coverage.svg) || make-coverage-badge --output-path ./badges/coverage.svg",
|
||||||
"all": "npm run format:write && npm run lint && npm run test && npm run package"
|
"all": "npm run format:write && npm run lint && npm run test && npm run package"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./dist/index.js"
|
".": "./src/index.js"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
|||||||
3
src/action.js
Normal file
3
src/action.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import {collect_all} from './index';
|
||||||
|
|
||||||
|
collect_all(true, true);
|
||||||
29
src/collect_ci.js
Normal file
29
src/collect_ci.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import * as core from '@actions/core';
|
||||||
|
import * as github from '@actions/github';
|
||||||
|
import * as process from 'process';
|
||||||
|
import {result_to_output} from './lib';
|
||||||
|
|
||||||
|
export function collect_ci(debug = false, output = false) {
|
||||||
|
const r = {
|
||||||
|
ci_hostname: false
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const url = new URL(github.context.serverUrl);
|
||||||
|
r.ci_hostname = url.hostname;
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
console.log('results for output:', JSON.stringify(r, null, 2));
|
||||||
|
}
|
||||||
|
if (output) {
|
||||||
|
result_to_output(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log('partial results before error: ', JSON.stringify(r, null, 2));
|
||||||
|
core.setFailed(error.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
112
src/collect_git.js
Normal file
112
src/collect_git.js
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
import * as core from '@actions/core';
|
||||||
|
import * as github from '@actions/github';
|
||||||
|
import * as process from 'process';
|
||||||
|
import * as semverParser from 'semver-parser';
|
||||||
|
import {result_to_output} from './lib';
|
||||||
|
|
||||||
|
export function collect_git(debug = false, output = false) {
|
||||||
|
const r = {
|
||||||
|
git_is_branch : false,
|
||||||
|
git_is_tag : false,
|
||||||
|
git_is_pull_request : false,
|
||||||
|
git_current_branch : false,
|
||||||
|
git_ref_branch : false,
|
||||||
|
git_is_default_branch: false,
|
||||||
|
git_tag : false,
|
||||||
|
semver_valid : false,
|
||||||
|
semver_major : false,
|
||||||
|
semver_minor : false,
|
||||||
|
semver_patch : false,
|
||||||
|
semver_build : false,
|
||||||
|
semver_pre : false
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const stripTagPrefix = core.getInput('strip_tag_prefix');
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
console.log(JSON.stringify(github.context, null, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
r.git_is_tag = github.context.ref.startsWith('refs/tags/');
|
||||||
|
r.git_default_branch = github.context.payload?.repository?.defaultBranch;
|
||||||
|
r.git_is_pull_request = github.context.payload.pull_request != null;
|
||||||
|
|
||||||
|
if (r.git_is_pull_request) {
|
||||||
|
const baseRef = github.context.baseRef || process.env.BODY_REF;
|
||||||
|
const headRef =
|
||||||
|
github.context.payload?.pull_request?.head?.ref || process.env.HEAD_REF;
|
||||||
|
if (debug) {
|
||||||
|
console.log('baseRef=' + baseRef);
|
||||||
|
}
|
||||||
|
if (debug) {
|
||||||
|
console.log('headRef=' + headRef);
|
||||||
|
}
|
||||||
|
// TODO support PR data
|
||||||
|
}
|
||||||
|
else if (!r.git_is_tag) {
|
||||||
|
// regular branches
|
||||||
|
r.git_is_branch = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// gather regular branch info
|
||||||
|
if (r.git_is_branch) {
|
||||||
|
if (!github.context.ref.startsWith('refs/heads/')) {
|
||||||
|
throw new Error(
|
||||||
|
'Failed to determine branch for non-PR and non-Tag action'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
r.git_current_branch = github.context.ref.slice('refs/heads/'.length);
|
||||||
|
r.git_ref_branch = r.git_current_branch; // same as current branch for non-PR, non-Tag
|
||||||
|
r.git_is_default_branch = r.git_current_branch == r.git_default_branch;
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse semver for tags
|
||||||
|
if (r.git_is_tag) {
|
||||||
|
r.git_tag = github.context.ref.slice('refs/tags/'.length);
|
||||||
|
|
||||||
|
const parsed = semverParser.parseSemVer(r.git_tag);
|
||||||
|
if (debug) {
|
||||||
|
console.log('semver=' + JSON.stringify(parsed));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsed.matches) {
|
||||||
|
r.semver_valid = parsed.matches;
|
||||||
|
r.semver_major = parsed.major;
|
||||||
|
r.semver_minor = parsed.minor;
|
||||||
|
r.semver_patch = parsed.patch;
|
||||||
|
r.semver_build = parsed.build;
|
||||||
|
r.semver_pre = parsed.pre;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (r.git_is_branch) {
|
||||||
|
const parsed = semverParser.parseSemVer(r.git_current_branch);
|
||||||
|
if (debug) {
|
||||||
|
console.log('semver=' + JSON.stringify(parsed));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsed.matches) {
|
||||||
|
r.semver_valid = parsed.matches;
|
||||||
|
r.semver_major = parsed.major;
|
||||||
|
r.semver_minor = parsed.minor;
|
||||||
|
r.semver_patch = parsed.patch;
|
||||||
|
r.semver_build = parsed.build;
|
||||||
|
r.semver_pre = parsed.pre;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
console.log('results for output:', JSON.stringify(r, null, 2));
|
||||||
|
}
|
||||||
|
if (output) {
|
||||||
|
result_to_output(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("partial results before error: ", JSON.stringify(r, null, 2));
|
||||||
|
core.setFailed(error.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
108
src/gather.js
108
src/gather.js
@ -1,108 +0,0 @@
|
|||||||
import * as core from "@actions/core";
|
|
||||||
import * as github from "@actions/github";
|
|
||||||
import * as process from "process";
|
|
||||||
import * as semverParser from "semver-parser";
|
|
||||||
|
|
||||||
export function result_to_output(results) {
|
|
||||||
for (const key in results) {
|
|
||||||
if (!results.hasOwnProperty(key)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const value = results[key];
|
|
||||||
if (typeof value !== "string") {
|
|
||||||
core.setOutput(key, JSON.stringify(value)); // TODO support nested objects with key chaining
|
|
||||||
} else {
|
|
||||||
core.setOutput(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function gather_information(debug = false, output = false) {
|
|
||||||
const r = {
|
|
||||||
git_is_branch: false,
|
|
||||||
git_is_tag: false,
|
|
||||||
git_is_pull_request: false,
|
|
||||||
git_current_branch: false,
|
|
||||||
git_ref_branch: false,
|
|
||||||
git_is_default_branch: false,
|
|
||||||
git_tag: false,
|
|
||||||
semver_valid: false,
|
|
||||||
semver_major: false,
|
|
||||||
semver_minor: false,
|
|
||||||
semver_patch: false,
|
|
||||||
semver_build: false,
|
|
||||||
semver_pre: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const stripTagPrefix = core.getInput("strip_tag_prefix");
|
|
||||||
|
|
||||||
if (debug) console.log(JSON.stringify(github.context, null, 2));
|
|
||||||
|
|
||||||
r.git_is_tag = github.context.ref.startsWith("refs/tags/");
|
|
||||||
r.git_default_branch = github.context.payload?.repository?.defaultBranch;
|
|
||||||
r.git_is_pull_request = github.context.payload.pull_request != null;
|
|
||||||
|
|
||||||
if (r.git_is_pull_request) {
|
|
||||||
const baseRef = github.context.baseRef || process.env.BODY_REF;
|
|
||||||
const headRef =
|
|
||||||
github.context.payload?.pull_request?.head?.ref || process.env.HEAD_REF;
|
|
||||||
if (debug) console.log("baseRef=" + baseRef);
|
|
||||||
if (debug) console.log("headRef=" + headRef);
|
|
||||||
// TODO support PR data
|
|
||||||
} else if (!r.git_is_tag) {
|
|
||||||
// regular branches
|
|
||||||
r.git_is_branch = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// gather regular branch info
|
|
||||||
if (r.git_is_branch) {
|
|
||||||
if (!github.context.ref.startsWith("refs/heads/")) {
|
|
||||||
throw new Error(
|
|
||||||
"Failed to determine branch for non-PR and non-Tag action",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
r.git_current_branch = github.context.ref.slice("refs/heads/".length);
|
|
||||||
r.git_ref_branch = r.git_current_branch; // same as current branch for non-PR, non-Tag
|
|
||||||
r.git_is_default_branch = r.git_current_branch == r.git_default_branch;
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse semver for tags
|
|
||||||
if (r.git_is_tag) {
|
|
||||||
r.git_tag = github.context.ref.slice("refs/tags/".length);
|
|
||||||
|
|
||||||
const parsed = semverParser.parseSemVer(r.git_tag);
|
|
||||||
if (debug) console.log("semver=" + JSON.stringify(parsed));
|
|
||||||
|
|
||||||
if (parsed.matches) {
|
|
||||||
r.semver_valid = parsed.matches;
|
|
||||||
r.semver_major = parsed.major;
|
|
||||||
r.semver_minor = parsed.minor;
|
|
||||||
r.semver_patch = parsed.patch;
|
|
||||||
r.semver_build = parsed.build;
|
|
||||||
r.semver_pre = parsed.pre;
|
|
||||||
}
|
|
||||||
} else if (r.git_is_branch) {
|
|
||||||
const parsed = semverParser.parseSemVer(r.git_current_branch);
|
|
||||||
if (debug) console.log("semver=" + JSON.stringify(parsed));
|
|
||||||
|
|
||||||
if (parsed.matches) {
|
|
||||||
r.semver_valid = parsed.matches;
|
|
||||||
r.semver_major = parsed.major;
|
|
||||||
r.semver_minor = parsed.minor;
|
|
||||||
r.semver_patch = parsed.patch;
|
|
||||||
r.semver_build = parsed.build;
|
|
||||||
r.semver_pre = parsed.pre;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (debug) console.log("results for output:", JSON.stringify(r, null, 2));
|
|
||||||
if (output) result_to_output(r);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
} catch (error) {
|
|
||||||
console.log("partial results before error: ", JSON.stringify(r, null, 2));
|
|
||||||
core.setFailed(error.message);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
13
src/index.js
13
src/index.js
@ -1,3 +1,12 @@
|
|||||||
import * as gather from "./gather";
|
import {collect_ci} from './collect_ci';
|
||||||
|
import {collect_git} from './collect_git';
|
||||||
|
|
||||||
|
export {result_to_output} from './lib';
|
||||||
|
export {collect_git} from './collect_git';
|
||||||
|
export {collect_ci} from './collect_ci';
|
||||||
|
|
||||||
|
export function collect_all(debug = false, output = false) {
|
||||||
|
collect_ci(debug, output);
|
||||||
|
collect_git(debug, output);
|
||||||
|
}
|
||||||
|
|
||||||
gather.gather_information(true, true);
|
|
||||||
|
|||||||
16
src/lib.js
Normal file
16
src/lib.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
|
export function result_to_output(results) {
|
||||||
|
for (const key in results) {
|
||||||
|
if (!results.hasOwnProperty(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const value = results[key];
|
||||||
|
if (typeof value !== 'string') {
|
||||||
|
core.setOutput(key, JSON.stringify(value)); // TODO support nested objects with key chaining
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.setOutput(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user