From 5111ba3ee7952e28ed60b1906144c3d82c10583a Mon Sep 17 00:00:00 2001 From: Philipp Horstenkamp Date: Thu, 23 May 2024 23:17:28 +0200 Subject: [PATCH] Add an replacement for the {{hostname}} token. --- index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index cfab3d4..0985e29 100644 --- a/index.js +++ b/index.js @@ -17,12 +17,13 @@ const path = require("path"); * @param {string} content - The string content in which placeholders are to be replaced. * @returns {string} The content with placeholders replaced by their respective dynamic values. */ -function replacePlaceholders(content) { +function replacePlaceholders(content, hostname) { const deployTime = new Date().toISOString(); return content .replace(/{{gitHash}}/g, process.env.GITHUB_SHA) .replace(/{{gitRef}}/g, process.env.GITHUB_REF) - .replace(/{{deployTime}}/g, deployTime); + .replace(/{{deployTime}}/g, deployTime) + .replace(/{{hostname}}/g, hostname); } /** @@ -36,7 +37,7 @@ function replacePlaceholders(content) { * @param {string} [prefix] - An optional directory prefix to prepend to the glob pattern. This allows searching within a specific directory. * @returns {Promise} A promise that resolves with an array of file paths that were processed, or rejects with an error if the process fails. */ -async function readReplaceAndWriteFiles(pattern, prefix) { +async function readReplaceAndWriteFiles(pattern, prefix, hostname) { return new Promise((resolve, reject) => { const globPattern = prefix ? path.join(prefix, pattern) : pattern; @@ -50,7 +51,7 @@ async function readReplaceAndWriteFiles(pattern, prefix) { let processPromise = fs.promises .readFile(file, "utf8") .then((content) => { - content = replacePlaceholders(content); + content = replacePlaceholders(content, hostname); return fs.promises.writeFile(file, content); }); @@ -154,7 +155,7 @@ async function postCode() { const gitReplace = core.getInput("git-replace") || null; if (gitReplace) { - await readReplaceAndWriteFiles(gitReplace, prefix); + await readReplaceAndWriteFiles(gitReplace, prefix, hostname); } const files_to_push = await readFilesIntoDict(pattern, prefix); @@ -188,9 +189,8 @@ async function postCode() { core.info(JSON.stringify(response, null, 2)); console.log(`Code set successfully to ${branch}`); } else { - let response; core.info(`Logging in as user ${username}`); - response = await Promise.resolve() + await Promise.resolve() .then(() => api.auth(username, password, login_arguments)) .then(() => { api.code.set(branch, files_to_push); -- 2.47.2