Skip to content

Commit

Permalink
Add support to deploy preview other releases
Browse files Browse the repository at this point in the history
  • Loading branch information
andreslucena committed Jul 10, 2023
1 parent da305e9 commit 8de555e
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions bin/playbook-changer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,39 @@ let url;

console.log(process.env);

if (process.env.CI === "true") {
headRef = process.env.HEAD;
// FIXME: change this depending on the branch
baseRef = "develop";
// 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 || process.env.GITHUB_HEAD_REF;
if (process.env.GITHUB_BASE_REF != undefined) {
baseRef = process.env.GITHUB_BASE_REF
} else {
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 = ".";
Expand Down

0 comments on commit 8de555e

Please sign in to comment.