Skip to content

Commit

Permalink
Merge branch 'migrate-sf-plugin' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Sep 4, 2024
2 parents 05be583 + 860ed25 commit eeb0c92
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 41 deletions.
7 changes: 4 additions & 3 deletions src/commands/hardis/org/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default class SandboxCreate extends SfCommand<any> {
const createCommand =
'sf org create sandbox --set-default ' +
`--definition-file ${projectSandboxDefLocal} ` +
`--set-alias ${this.sandboxOrgAlias} ` +
`--alias ${this.sandboxOrgAlias} ` +
`--wait ${waitTime} ` +
`--target-org ${this.devHubAlias} `;
const createResult = await execSfdxJson(createCommand, this, {
Expand Down Expand Up @@ -219,8 +219,9 @@ export default class SandboxCreate extends SfCommand<any> {
(this.projectSandboxDef.features || []).includes('StateAndCountryPicklist') &&
userQueryRes.result.CountryCode == null
) {
updatedUserValues += ` CountryCode='${config.defaultCountryCode || 'FR'}' Country='${config.defaultCountry || 'France'
}'`;
updatedUserValues += ` CountryCode='${config.defaultCountryCode || 'FR'}' Country='${
config.defaultCountry || 'France'
}'`;
}
if (
(this.projectSandboxDef.features || []).includes('MarketingUser') &&
Expand Down
29 changes: 15 additions & 14 deletions src/commands/hardis/scratch/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ export default class ScratchCreate extends SfCommand<any> {
uxLog(
this,
'[pool] ' +
c.yellow('Put back scratch org in the scratch orgs pool. ') +
c.grey({ result: this.scratchOrgFromPool })
c.yellow('Put back scratch org in the scratch orgs pool. ') +
c.grey({ result: this.scratchOrgFromPool })
);
await addScratchOrgToPool(this.scratchOrgFromPool, { position: 'first' });
} else if (isCI && this.scratchOrgUsername) {
Expand Down Expand Up @@ -225,10 +225,10 @@ export default class ScratchCreate extends SfCommand<any> {
this.scratchOrgDuration = process.env?.SCRATCH_ORG_DURATION
? process.env.SCRATCH_ORG_DURATION // Priority to global variable if defined
: isCI && this.pool === false
? 1 // If CI and not during pool feed job, default is 1 day because the scratch will not be used after the job
: this.configInfo?.scratchOrgDuration
? this.configInfo.scratchOrgDuration // Override default value in scratchOrgDuration
: 30; // Default value: 30
? 1 // If CI and not during pool feed job, default is 1 day because the scratch will not be used after the job
: this.configInfo?.scratchOrgDuration
? this.configInfo.scratchOrgDuration // Override default value in scratchOrgDuration
: 30; // Default value: 30

this.userEmail = process.env.USER_EMAIL || process.env.GITLAB_USER_EMAIL || this.configInfo.userEmail;

Expand Down Expand Up @@ -281,16 +281,16 @@ export default class ScratchCreate extends SfCommand<any> {
uxLog(
this,
'[pool] ' +
c.cyan(
`Fetched org ${c.green(this.scratchOrgAlias)} from pool with user ${c.green(this.scratchOrgUsername)}`
)
c.cyan(
`Fetched org ${c.green(this.scratchOrgAlias)} from pool with user ${c.green(this.scratchOrgUsername)}`
)
);
if (!isCI) {
uxLog(
this,
c.cyan('Now opening org...') +
' ' +
c.yellow('(The org is not ready to work in until this script is completed !)')
' ' +
c.yellow('(The org is not ready to work in until this script is completed !)')
);
await execSfdxJson('sf org open', this, {
fail: true,
Expand All @@ -317,7 +317,7 @@ export default class ScratchCreate extends SfCommand<any> {
const createCommand =
'sf org create scratch --set-default ' +
`--definition-file ${projectScratchDefLocal} ` +
`--set-alias ${this.scratchOrgAlias} ` +
`--alias ${this.scratchOrgAlias} ` +
`--wait ${waitTime} ` +
`--target-org ${this.devHubAlias} ` +
`--duration-days ${this.scratchOrgDuration}`;
Expand Down Expand Up @@ -454,8 +454,9 @@ export default class ScratchCreate extends SfCommand<any> {
(this.projectScratchDef.features || []).includes('StateAndCountryPicklist') &&
userQueryRes.result.CountryCode == null
) {
updatedUserValues += ` CountryCode='${config.defaultCountryCode || 'FR'}' Country='${config.defaultCountry || 'France'
}'`;
updatedUserValues += ` CountryCode='${config.defaultCountryCode || 'FR'}' Country='${
config.defaultCountry || 'France'
}'`;
}
if (
(this.projectScratchDef.features || []).includes('MarketingUser') &&
Expand Down
59 changes: 36 additions & 23 deletions src/common/utils/authUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import c from 'chalk';
import * as crossSpawn from 'cross-spawn';
import fs from 'fs-extra';
import * as path from 'path';
import { createTempDir, execCommand, execSfdxJson, getCurrentGitBranch, isCI, promptInstanceUrl, uxLog } from "./index.js";
import {
createTempDir,
execCommand,
execSfdxJson,
getCurrentGitBranch,
isCI,
promptInstanceUrl,
uxLog,
} from './index.js';
import { getConfig } from '../../config/index.js';
import { SfError } from '@salesforce/core';
import { prompts } from './prompts.js';
Expand All @@ -23,16 +31,20 @@ export async function authOrg(orgAlias: string, options: any) {
orgDisplayCommand += ' --target-org ' + orgAlias;
setDefaultOrg = true;
} else {
if (options?.argv.includes('--target-org') || options?.argv.includes('--targetusername') ||
options?.argv.includes('-o') || options?.argv.includes('-u')) {
if (
options?.argv.includes('--target-org') ||
options?.argv.includes('--targetusername') ||
options?.argv.includes('-o') ||
options?.argv.includes('-u')
) {
const posUsername =
options.argv.indexOf('--target-org') > -1
? options.argv.indexOf('--target-org') + 1 :
options.argv.indexOf('--targetusername') > -1
? options.argv.indexOf('--targetusername') + 1 :
options.argv.indexOf('-o') > -1
? options.argv.indexOf('-o') + 1 :
options.argv.indexOf('-u') > -1;
? options.argv.indexOf('--target-org') + 1
: options.argv.indexOf('--targetusername') > -1
? options.argv.indexOf('--targetusername') + 1
: options.argv.indexOf('-o') > -1
? options.argv.indexOf('-o') + 1
: options.argv.indexOf('-u') > -1;
orgDisplayCommand += ' --target-org ' + options.argv[posUsername];
}
}
Expand Down Expand Up @@ -73,8 +85,9 @@ export async function authOrg(orgAlias: string, options: any) {
);
}
if (setDefaultOrg) {
const setDefaultOrgCommand = `sf config set ${isDevHub ? 'target-dev-hub' : 'target-org'}=${orgInfoResult.result.username
}`;
const setDefaultOrgCommand = `sf config set ${isDevHub ? 'target-dev-hub' : 'target-org'}=${
orgInfoResult.result.username
}`;
await execSfdxJson(setDefaultOrgCommand, this, { fail: false });
}
doConnect = false;
Expand Down Expand Up @@ -103,7 +116,7 @@ export async function authOrg(orgAlias: string, options: any) {
const authCommand =
`sf org login sfdx-url -f ${authFile}` +
(isDevHub ? ` --set-default-dev-hub` : ` --set-default`) +
(!orgAlias.includes('force://') ? ` --set-alias ${orgAlias}` : '');
(!orgAlias.includes('force://') ? ` --alias ${orgAlias}` : '');
await execCommand(authCommand, this, { fail: true, output: false });
uxLog(this, c.cyan('Successfully logged using sfdxAuthUrl'));
await fs.remove(authFile);
Expand All @@ -115,8 +128,8 @@ export async function authOrg(orgAlias: string, options: any) {
typeof options.Command.flags?.targetusername === 'string'
? options.Command.flags?.targetusername
: process.env.TARGET_USERNAME || isDevHub
? config.devHubUsername
: config.targetUsername;
? config.devHubUsername
: config.targetUsername;
if (username == null && isCI) {
const gitBranchFormatted = await getCurrentGitBranch({ formatted: true });
console.error(
Expand All @@ -125,22 +138,22 @@ export async function authOrg(orgAlias: string, options: any) {
isDevHub
? 'devHubUsername in .sfdx-hardis.yml'
: options.scratch
? 'cache between your CI jobs: folder ".cache/sfdx-hardis/.sfdx"'
: `targetUsername in config/branches/.sfdx-hardis.${gitBranchFormatted}.yml`
? 'cache between your CI jobs: folder ".cache/sfdx-hardis/.sfdx"'
: `targetUsername in config/branches/.sfdx-hardis.${gitBranchFormatted}.yml`
)} `
)
);
process.exit(1);
}
let instanceUrl =
typeof options.Command?.flags?.instanceurl === 'string' &&
(options.Command?.flags?.instanceurl || '').startsWith('https')
(options.Command?.flags?.instanceurl || '').startsWith('https')
? options.Command.flags.instanceurl
: (process.env.INSTANCE_URL || '').startsWith('https')
? process.env.INSTANCE_URL
: config.instanceUrl
? config.instanceUrl
: 'https://login.salesforce.com';
? process.env.INSTANCE_URL
: config.instanceUrl
? config.instanceUrl
: 'https://login.salesforce.com';
// Get JWT items clientId and certificate key
const sfdxClientId = await getSfdxClientId(orgAlias, config);
const crtKeyfile = await getCertificateKeyFile(orgAlias, config);
Expand All @@ -154,7 +167,7 @@ export async function authOrg(orgAlias: string, options: any) {
` --jwt-key-file ${crtKeyfile}` +
` --username ${username}` +
` --instance-url ${instanceUrl}` +
(orgAlias !== 'MY_ORG' ? ` --set-alias ${orgAlias}` : '');
(orgAlias !== 'MY_ORG' ? ` --alias ${orgAlias}` : '');
const jwtAuthRes = await execSfdxJson(loginCommand, this, {
fail: false,
});
Expand Down Expand Up @@ -405,4 +418,4 @@ async function getCertificateKeyFile(orgAlias: string, config: any) {
console.error(c.red(`See CI authentication doc at https://sfdx-hardis.cloudity.com/salesforce-ci-cd-setup-auth/`));
}
return null;
}
}
2 changes: 1 addition & 1 deletion src/common/utils/poolUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export async function tryFetchScratchOrg(options: any) {
return null;
}
await fs.writeFile(tmpAuthFile, authFileContent, 'utf8');
const authCommand = `sf org login sfdx-url --sfdx-url-file ${tmpAuthFile} --set-default --set-alias ${scratchOrg.scratchOrgAlias}`;
const authCommand = `sf org login sfdx-url --sfdx-url-file ${tmpAuthFile} --set-default --alias ${scratchOrg.scratchOrgAlias}`;
const authRes = await execSfdxJson(authCommand, this, { fail: false, output: false });
if (authRes.status !== 0) {
uxLog(
Expand Down

0 comments on commit eeb0c92

Please sign in to comment.