From 29eefdd5d84cf51a831c44f5e844db0491c986db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Pereira=20de=20Lucena?= Date: Mon, 10 Jul 2023 15:46:02 +0200 Subject: [PATCH] Add support to deploy preview other releases --- bin/playbook-changer.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/bin/playbook-changer.js b/bin/playbook-changer.js index 48bf147ba5..40bf04ac61 100755 --- a/bin/playbook-changer.js +++ b/bin/playbook-changer.js @@ -15,11 +15,35 @@ let url; console.log(process.env); -if (process.env.CI === "true") { +// Infers base branch reference according to the head reference +// +// If the head reference starts with the version number (i.e. "v0.26/fix/preview"), returns the base branch reference (i.e. "release/0.26-stable") +// If not, then returns "develop" +// +// @param {string} headRef - The head reference. Examples: "v0.26/fix/preview" or "fix/preview" +// @returns {string} The base reference. Examples "release/0.26-stable" or "develop" +function baseFromHead(headRef) { + let baseRef; + + if (headRef.startsWith("v0.")) { + const version = headRef.split("/")[0].replace("v"); + baseRef = `release/${version}-stable`; + } else { + baseRef = "develop"; + }; + + return baseRef; +} + +if (process.env.CONTEXT === "deploy-preview" || process.env.RUNNER_ENVIRONMENT == "github-hosted") { + // We're in CI and we need to adapt the head of the playbook headRef = process.env.HEAD; - // FIXME: change this depending on the branch - baseRef = "develop"; + baseRef = baseFromHead(headRef); +} else if (process.env.CI === "true") { + // We're in production so we don't need to change anything + return; } else { + // We're in development and we need to adapt the head and also the URL headRef = "HEAD"; baseRef = "develop"; url = ".";