-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MILOLIBS RUN : MWPW-141223] Provide support to run nala tests on a g…
…iven milo libs (#240) * update the test files * update the tests * update the failures * update the personalizataion and iframe tests * update wait --------- Co-authored-by: nateekar <[email protected]>
- Loading branch information
Showing
32 changed files
with
663 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,151 @@ | ||
import { exit } from 'process'; | ||
|
||
const { execSync } = require('child_process'); | ||
const { isBranchURLValid } = require('./libs/baseurl.js'); | ||
const axios = require('axios'); | ||
|
||
async function globalSetup() { | ||
console.info('----Executing Global setup---------'); | ||
const MAIN_BRANCH_LIVE_URL = 'https://main--milo--adobecom.hlx.live'; | ||
const STAGE_BRANCH_URL = 'https://milo.stage.adobe.com'; | ||
const LOCALHOST_URL = 'http://localhost:3000'; | ||
|
||
async function getGitHubPRBranchLiveUrl() { | ||
// get the pr number | ||
const prReference = process.env.GITHUB_REF; | ||
const prNumber = prReference.split('/')[2]; | ||
|
||
// get the pr branch name | ||
const branch = process.env.GITHUB_HEAD_REF; | ||
const prBranch = branch.replace(/\//g, '-'); | ||
|
||
// get the org and repo | ||
const repository = process.env.GITHUB_REPOSITORY; | ||
const repoParts = repository.split('/'); | ||
const toRepoOrg = repoParts[0]; | ||
const toRepoName = repoParts[1]; | ||
|
||
// Get the org and repo from the environment variables | ||
const prFromOrg = process.env.prOrg; | ||
const prFromRepoName = process.env.prRepo; | ||
|
||
|
||
let prBranchLiveUrl; | ||
let stageBranchLiveUrl; | ||
let localTestLiveUrl; | ||
let localOrg; | ||
let localRepo; | ||
let prNumber | ||
|
||
// Check if the code is running in a GitHub CI/CD environment | ||
if (process.env.GITHUB_ACTIONS === 'true') { | ||
console.info('---- Running Tests in the GitHub environment ---------'); | ||
|
||
// get the pr number | ||
const prReference = process.env.GITHUB_REF; | ||
prNumber = prReference.split('/')[2]; | ||
|
||
// get the pr branch name | ||
const branch = process.env.GITHUB_HEAD_REF; | ||
const prBranch = branch.replace(/\//g, '-'); | ||
|
||
// get the org and repo | ||
const repository = process.env.GITHUB_REPOSITORY; | ||
const repoParts = repository.split('/'); | ||
const toRepoOrg = repoParts[0]; | ||
const toRepoName = repoParts[1]; | ||
|
||
// Get the org and repo from the environment variables | ||
const prFromOrg = process.env.prOrg; | ||
const prFromRepoName = process.env.prRepo; | ||
|
||
try { | ||
// Construct the pr branch URL | ||
if (toRepoName === 'nala' || toRepoName === 'janus') { | ||
prBranchLiveUrl = `https://main--milo--adobecom.hlx.live`; | ||
} else { | ||
prBranchLiveUrl = `https://${prBranch}--${prFromRepoName}--${prFromOrg}.hlx.live`; | ||
} | ||
if (toRepoName === 'nala' || toRepoName === 'janus') { | ||
prBranchLiveUrl = MAIN_BRANCH_LIVE_URL; | ||
} else { | ||
prBranchLiveUrl = `https://${prBranch}--${prFromRepoName}--${prFromOrg}.hlx.live`; | ||
} | ||
|
||
// Validate the pr branch URL by making an HTTP request | ||
if (await isBranchURLValid(prBranchLiveUrl)) { | ||
process.env.PR_BRANCH_LIVE_URL = prBranchLiveUrl; | ||
} | ||
console.info('PR Repository : ', repository); | ||
console.info('PR TO ORG : ', toRepoOrg); | ||
console.info('PR TO REPO : ', toRepoName); | ||
console.info('PR From ORG : ', prFromOrg); | ||
console.info('PR From REPO : ', prFromRepoName); | ||
console.info('PR Branch : ', branch); | ||
console.info('PR Branch(U) : ', prBranch); | ||
console.info('PR Number : ', prNumber); | ||
console.info('PR From Branch live url : ', prBranchLiveUrl); | ||
} catch (err) { | ||
console.error(`Error => Error in setting PR Branch test URL : ${prBranchLiveUrl}`); | ||
console.info(`Note : PR branch test url ${prBranchLiveUrl} is not valid, Exiting test execution.`); | ||
process.exit(1); | ||
} | ||
} else if (process.env.CIRCLECI) { | ||
console.info('---- Running Tests in the CircleCI environment ---------'); | ||
try { | ||
if (await isBranchURLValid(prBranchLiveUrl)) { | ||
process.env.PR_BRANCH_LIVE_URL = prBranchLiveUrl; | ||
} | ||
console.info('PR Repository : ', repository); | ||
console.info('PR TO ORG : ', toRepoOrg); | ||
console.info('PR TO REPO : ', toRepoName); | ||
console.info('PR From ORG : ', prFromOrg); | ||
console.info('PR From REPO : ', prFromRepoName); | ||
console.info('PR Branch : ', branch); | ||
console.info('PR Branch(U) : ', prBranch); | ||
console.info('PR Number : ', prNumber); | ||
console.info('PR From Branch live url : ', prBranchLiveUrl); | ||
} catch (err) { | ||
console.error(`Error => Error in setting PR Branch test URL : ${prBranchLiveUrl}`); | ||
console.info(`Note: PR branch test url ${prBranchLiveUrl} is not valid, Exiting test execution.`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
async function getGitHubMiloLibsBranchLiveUrl() { | ||
const repository = process.env.GITHUB_REPOSITORY; | ||
|
||
let prBranchLiveUrl; | ||
let miloLibs; | ||
|
||
prBranchLiveUrl = process.env.PR_BRANCH_MILOLIBS_LIVE_URL; | ||
miloLibs = process.env.MILO_LIBS; | ||
|
||
try { | ||
if (await isBranchURLValid(prBranchLiveUrl)) { | ||
process.env.PR_BRANCH_LIVE_URL = prBranchLiveUrl; | ||
} | ||
console.info('PR Repository : ', repository); | ||
console.info('PR Branch live url : ', prBranchLiveUrl); | ||
console.info('Milo Libs : ', miloLibs); | ||
} catch (err) { | ||
console.error(`Error => Error in setting PR Branch test URL : ${prBranchLiveUrl}`); | ||
console.info(`Note: PR branch test url ${prBranchLiveUrl} is not valid, Exiting test execution.`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
stageBranchLiveUrl = 'https://milo.stage.adobe.com'; | ||
|
||
// Validate the stage URL by making an HTTP request | ||
async function getCircleCIBranchLiveUrl() { | ||
const stageBranchLiveUrl = STAGE_BRANCH_URL; | ||
|
||
try { | ||
if (await isBranchURLValid(stageBranchLiveUrl)) { | ||
process.env.PR_BRANCH_LIVE_URL = stageBranchLiveUrl; | ||
} | ||
console.info('Stage Branch Live URL : ', stageBranchLiveUrl); | ||
} catch (err) { | ||
console.error('Error => Error in setting Stage Branch test URL : ', stageBranchLiveUrl); | ||
console.info('Note: Stage branch test url is not valid, Exiting test execution.'); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
} else { | ||
|
||
console.info('---- Running Tests in the Local environment ---------'); | ||
|
||
try { | ||
// Run 'git rev-parse --show-toplevel' to get the root directory of the Git repository | ||
const localGitRootDir = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim(); | ||
|
||
if (localGitRootDir) { | ||
// Get the repository and organization/owner name from the Git remote URL | ||
const gitRemoteOriginUrl = execSync('git config --get remote.origin.url', { cwd: localGitRootDir, encoding: 'utf-8' }).trim(); | ||
const match = gitRemoteOriginUrl.match(/github\.com\/(.*?)\/(.*?)\.git/); | ||
console.info('Git Local Remote Origin : ', gitRemoteOriginUrl ); | ||
if (match) { | ||
localOrg = match[1]; | ||
localRepo = match[2]; | ||
|
||
console.info('Git ORG : ', localOrg ); | ||
console.info('Git REPO : ', localRepo ); | ||
|
||
// get the current local branch name | ||
const localBranch = execSync('git rev-parse --abbrev-ref HEAD', { cwd: localGitRootDir, encoding: 'utf-8' }).trim(); | ||
console.info('Local Branch : ', localBranch ); | ||
|
||
if ( localRepo === 'nala' || localRepo === 'janus'){ | ||
localTestLiveUrl = `https://main--milo--adobecom.hlx.live`; | ||
} else { | ||
localTestLiveUrl = `http://localhost:3000`; | ||
} | ||
|
||
// Validate the pr branch URL by making an HTTP request | ||
if ( await isBranchURLValid(localTestLiveUrl)){ | ||
process.env.LOCAL_TEST_LIVE_URL = localTestLiveUrl; | ||
} | ||
console.info('Local Test Live URL : ', process.env.LOCAL_TEST_LIVE_URL ); | ||
async function getLocalBranchLiveUrl() { | ||
try { | ||
const localGitRootDir = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim(); | ||
|
||
if (localGitRootDir) { | ||
const gitRemoteOriginUrl = execSync('git config --get remote.origin.url', { cwd: localGitRootDir, encoding: 'utf-8' }).trim(); | ||
const match = gitRemoteOriginUrl.match(/github\.com\/(.*?)\/(.*?)\.git/); | ||
|
||
if (match) { | ||
const [localOrg, localRepo] = match.slice(1, 3); | ||
const localBranch = execSync('git rev-parse --abbrev-ref HEAD', { cwd: localGitRootDir, encoding: 'utf-8' }).trim(); | ||
let localTestLiveUrl; | ||
|
||
if (localRepo === 'nala' || localRepo === 'janus') { | ||
localTestLiveUrl = MAIN_BRANCH_LIVE_URL; | ||
} else { | ||
localTestLiveUrl = LOCALHOST_URL; | ||
} | ||
|
||
if (await isBranchURLValid(localTestLiveUrl)) { | ||
process.env.LOCAL_TEST_LIVE_URL = localTestLiveUrl; | ||
} | ||
} | ||
} catch (error) { | ||
console.error(`Error => Error in setting local test URL : ${localTestLiveUrl}`) | ||
console.info(`Note : Local or branch test url ${localTestLiveUrl} is not valid, Exiting test execution.`); | ||
process.exit(1); | ||
console.info('Git ORG : ', localOrg); | ||
console.info('Git REPO : ', localRepo); | ||
console.info('Local Branch : ', localBranch); | ||
console.info('Local Test Live URL : ', process.env.LOCAL_TEST_LIVE_URL); | ||
} | ||
} | ||
} catch (error) { | ||
console.error(`Error => Error in setting local test URL : ${localTestLiveUrl}`); | ||
console.info(`Note: Local or branch test url is not valid, Exiting test execution.`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
async function globalSetup() { | ||
console.info('----Executing Global setup---------'); | ||
|
||
if (process.env.GITHUB_ACTIONS === 'true') { | ||
console.info('---- Running Tests in the GitHub environment ---------'); | ||
|
||
if (process.env.MILO_LIBS_RUN === 'true') { | ||
await getGitHubMiloLibsBranchLiveUrl(); | ||
} else { | ||
await getGitHubPRBranchLiveUrl(); | ||
} | ||
} else if (process.env.CIRCLECI) { | ||
console.info('---- Running Tests in the CircleCI environment ---------'); | ||
await getCircleCIBranchLiveUrl(); | ||
} else { | ||
console.info('---- Running Tests in the Local environment ---------'); | ||
await getLocalBranchLiveUrl(); | ||
} | ||
} | ||
|
||
export default globalSetup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.