Add an replacement for the {{hostname}} token. #15
14
index.js
14
index.js
@ -17,12 +17,13 @@ const path = require("path");
|
|||||||
* @param {string} content - The string content in which placeholders are to be replaced.
|
* @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.
|
* @returns {string} The content with placeholders replaced by their respective dynamic values.
|
||||||
*/
|
*/
|
||||||
function replacePlaceholders(content) {
|
function replacePlaceholders(content, hostname) {
|
||||||
const deployTime = new Date().toISOString();
|
const deployTime = new Date().toISOString();
|
||||||
return content
|
return content
|
||||||
.replace(/{{gitHash}}/g, process.env.GITHUB_SHA)
|
.replace(/{{gitHash}}/g, process.env.GITHUB_SHA)
|
||||||
.replace(/{{gitRef}}/g, process.env.GITHUB_REF)
|
.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.
|
* @param {string} [prefix] - An optional directory prefix to prepend to the glob pattern. This allows searching within a specific directory.
|
||||||
* @returns {Promise<string[]>} A promise that resolves with an array of file paths that were processed, or rejects with an error if the process fails.
|
* @returns {Promise<string[]>} 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) => {
|
return new Promise((resolve, reject) => {
|
||||||
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ async function readReplaceAndWriteFiles(pattern, prefix) {
|
|||||||
let processPromise = fs.promises
|
let processPromise = fs.promises
|
||||||
.readFile(file, "utf8")
|
.readFile(file, "utf8")
|
||||||
.then((content) => {
|
.then((content) => {
|
||||||
content = replacePlaceholders(content);
|
content = replacePlaceholders(content, hostname);
|
||||||
return fs.promises.writeFile(file, content);
|
return fs.promises.writeFile(file, content);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -154,7 +155,7 @@ async function postCode() {
|
|||||||
const gitReplace = core.getInput("git-replace") || null;
|
const gitReplace = core.getInput("git-replace") || null;
|
||||||
|
|
||||||
if (gitReplace) {
|
if (gitReplace) {
|
||||||
await readReplaceAndWriteFiles(gitReplace, prefix);
|
await readReplaceAndWriteFiles(gitReplace, prefix, hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
const files_to_push = await readFilesIntoDict(pattern, prefix);
|
const files_to_push = await readFilesIntoDict(pattern, prefix);
|
||||||
@ -188,9 +189,8 @@ async function postCode() {
|
|||||||
core.info(JSON.stringify(response, null, 2));
|
core.info(JSON.stringify(response, null, 2));
|
||||||
console.log(`Code set successfully to ${branch}`);
|
console.log(`Code set successfully to ${branch}`);
|
||||||
} else {
|
} else {
|
||||||
let response;
|
|
||||||
core.info(`Logging in as user ${username}`);
|
core.info(`Logging in as user ${username}`);
|
||||||
response = await Promise.resolve()
|
await Promise.resolve()
|
||||||
.then(() => api.auth(username, password, login_arguments))
|
.then(() => api.auth(username, password, login_arguments))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
api.code.set(branch, files_to_push);
|
api.code.set(branch, files_to_push);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user