Add an replacement for the {{hostname}} token. (#15)
All checks were successful
Lint / pre-commit Linting (push) Successful in 49s
All checks were successful
Lint / pre-commit Linting (push) Successful in 49s
Reviewed-on: #15 Co-authored-by: Philipp Horstenkamp <philipp@horstenkamp.de> Co-committed-by: Philipp Horstenkamp <philipp@horstenkamp.de>
This commit is contained in:
parent
bee951fc34
commit
508eec34d7
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.
|
||||
* @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<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) => {
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user