Skip to content

Commit

Permalink
Override git branch config (#35)
Browse files Browse the repository at this point in the history
* Connected App profile assistance

* Reuse msTeamsWebhookUrl during sfdx:org:configure:monitoring prompts

* allow to override CONFIG_BRANCH to get forced .sfdx.hardis.BRANCH.yml
  • Loading branch information
nvuillam authored Feb 25, 2021
1 parent 48e88b6 commit 4a618de
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 4 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

## [insiders] (master)

Note: Can be used with `sfdx plugins:install sfdx-hardis@beta` and docker image
Note: Can be used with `sfdx plugins:install sfdx-hardis@beta` and docker image `hardisgroupcom/sfdx-hardis@beta`

## [1.3.4] 2021-02-25

- Reuse msTeamsWebhookUrl during sfdx:org:configure:monitoring prompts
- Allow to override CONFIG_BRANCH to get forced .sfdx.hardis.BRANCH.yml

## [1.3.3] 2021-02-24

Expand All @@ -12,6 +17,10 @@ Note: Can be used with `sfdx plugins:install sfdx-hardis@beta` and docker image

- Guide user to assign rights to Connected App in **sfdx:org:configure:monitoring**

## [1.3.2] 2021-02-24

- Guide user to assign rights to Connected App in **sfdx:org:configure:monitoring**

## [1.3.1] 2021-02-24

- Manage git clone & push for **sfdx:org:configure:monitoring**
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN apk add --update --no-cache \
npm

# Add node packages to path #
# hadolint ignore=DL3044
ENV PATH="/node_modules/.bin:${PATH}"

ARG SFDX_HARDIS_VERSION=latest
Expand Down
3 changes: 3 additions & 0 deletions defaults/ci/.gitlab-ci-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Vous pouvez personnaliser l'éxécution de votre pipeline ici
variables:
DEPLOY_BRANCHES: /(developpement|integration|recette|preprod|master)/ # Regex contenant la liste des branches où un push va déclencher un déploiement
200 changes: 200 additions & 0 deletions defaults/ci/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
---
##################################################################
# Pipeline de test et déploiement d'un projet DX géré en CI/CD #
# NE PAS MODIFIER !! #
##################################################################

# Ce pipeline est mis à jour automatiquement par sfdx-hardis
# Vous ne pouvez donc pas le modifier sous peine de voir ces modifications ultérieurement écrasées
# Cependant, vous pouvez configurer des comportements dynamiques en modifiant le fichier ".gitlab-ci-config.yml"
# .gitlab-ci-config.yml ne sera jamais écrasé par sfdx-hardis
include:
- local: ".gitlab-ci-config.yml"

# Liste ordonnée des étapes du pipeline
stages:
- build # Controle de qualité des sources et création d'une scratch org CI
- test # Tests effectués sur la scratch org effectuée lors de l'étape précédente
- clean # Suppression de la scratch org CI
- check_deploy # Simulation de déploiement du contenu de la branche vers l'org (Sandbox ou autre) associée
- deploy # Déploiement du contenu de la branche vers l'org (Sandbox ou autre) associée

# On execute les jobs sur l'image hardisgroupcom/sfdx-hardis qui contient les applications necessaires
# Version latest recommandée, cependant beta et alpha peuvent être utilisées pour les tests
image: hardisgroupcom/sfdx-hardis:alpha

# Variables globales aux jobs
variables:
FORCE_COLOR: '1'

# Décommenter pour utiliser un des 2 trucs commencés en dessous :)
#default:

# décommenter le jour ou on a un vrai cache pour les runners gitlab concurrents
# En attendant on utilise les artifacts, même si c est pas joli joli...
# cache:
# key: toto #${CI_COMMIT_REF_SLUG}_CACHE_SFDX_HARDIS
# paths:
# - .cache/sfdx-hardis/.sfdx
# - .sfdx/
# - config/user/
# policy: pull

# Décommenter pour tester une version de sfdx-hardis en cours de dev
# before_script:
# - apk add tree
# - npm install -g typescript
# - git clone --branch NOM_DE_LA_BRANCHE_GIT https://github.com/hardisgroupcom/sfdx-hardis.git
# - cd sfdx-hardis
# - yarn
# - tsc
# - sfdx plugins:link
# - cd ..

# Controle de la qualité des sources avec Mega-Linter, qui contient sfdx-scanner (apex PMD),
# mais aussi d'autres linters et détecteurs de mauvaises pratiques
check_quality:
stage: build
tags:
- ubuntu
only:
- pushes
- merge_requests
- web
image: nvuillam/mega-linter-salesforce:latest
script: [ "true" ]
variables:
# All available variables are described in documentation
# https://nvuillam.github.io/mega-linter/configuration/
DEFAULT_WORKSPACE: $CI_PROJECT_DIR
DEFAULT_BRANCH: master
# ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
artifacts:
when: always
paths:
- report
expire_in: 1 week

# Check du déploiement dans l'org cible de la merge request
check_deploy_to_target_branch_org:
stage: build
tags:
- ubuntu
only:
refs:
- merge_requests
- web
variables:
CONFIG_BRANCH: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
ORG_ALIAS: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
script:
- '[ -z "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ] && exit 0;' # Skip this job if it is launched from web UI and we are not in merge request context
- sfdx hardis:auth:login
- sfdx hardis:project:deploy:sources:dx --check

# Création d'une scratch org, pour:
# - vérifier que les métadatas se déploient bien
# - exécuter les classes de test Apex
# - executer les tests automatisés
create_scratch_org:
stage: build
tags:
- ubuntu
only:
- merge_requests
- web
script:
- sfdx hardis:auth:login --devhub
- sfdx hardis:scratch:create
artifacts:
when: always
expire_in: 60 minutes
paths:
- .cache/sfdx-hardis/.sfdx
- .sfdx
- config/user

# Execution des classes de test Apex dans la scratch org créée par le job
test_apex:
stage: test
tags:
- ubuntu
only:
- merge_requests
- web
needs:
- job: create_scratch_org
artifacts: true
script:
- sfdx hardis:auth:login --scratchorg || true
- sfdx hardis:org:test:apex
artifacts:
when: always
paths:
- hardis-report
expire_in: 1 week

# Execution des tests automatisés
#test_automation:
# stage: test
# tags:
# - ubuntu
# only:
# - merge_requests
# - web
# needs:
# - job: create_scratch_org
# artifacts: true
# script:
# - sfdx hardis:auth:login --scratchorg
# - echo "Automated tests not implemented yet"

# Suppression de la scratch org de test temporaire
clean:
stage: clean
tags:
- ubuntu
when: on_success
only:
- merge_requests
- web
needs:
- job: create_scratch_org
- job: test_apex
script:
- sfdx hardis:auth:login --devhub
- sfdx hardis:auth:login --scratchorg || true
- sfdx force:org:delete --noprompt || true

# Simulation de déploiement vers l'org Salesforce cible
# Se déclenche en cas de planification ou lancement manuel
check_deploy_to_current_branch_org:
stage: deploy
tags:
- ubuntu
only:
- pushes
- schedules
- web
except:
variables:
- $CI_COMMIT_REF_NAME !~ $DEPLOY_BRANCHES
script:
- sfdx hardis:auth:login
- sfdx hardis:project:deploy:sources:dx --check

# Déploiement vers l'org Salesforce cible
# Se déclenche en cas de push vers une des branches décrites dans la regex DEPLOY_BRANCHES de .gitlab-ci-config.yml
deploy_to_org:
stage: deploy
tags:
- ubuntu
only:
- pushes
- web
except:
variables:
- $CI_COMMIT_REF_NAME !~ $DEPLOY_BRANCHES
script:
- sfdx hardis:auth:login
- sfdx hardis:project:deploy:sources:dx
5 changes: 3 additions & 2 deletions src/commands/hardis/org/configure/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default class OrgConfigureMonitoring extends SfdxCommand {
{
type: 'text',
name: 'teamsHook',
initial: config.msTeamsWebhookUrl,
message: c.cyanBright('If you want notifications of updates in orgs in a Microsoft Teams channel:\n- Create the WebHook: https://docs.microsoft.com/fr-fr/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook#add-an-incoming-webhook-to-a-teams-channel\n- paste the hook Url here\nIf you do not want Ms Team notifications, just leave empty and hit ENTER')
}
]);
Expand All @@ -114,7 +115,7 @@ export default class OrgConfigureMonitoring extends SfdxCommand {
// Generate SSL certificate (requires openssl to be installed on computer)
await generateSSLCertificate(branchName, './.ssh', this);

uxLog(this, 'You can customize monitoring updating .gitlab-ci-config.yml');
uxLog(this, c.italic('You can customize monitoring by updating .gitlab-ci-config.yml'));

// Confirm & push on server
const confirmPush = await prompts({
Expand All @@ -130,7 +131,7 @@ export default class OrgConfigureMonitoring extends SfdxCommand {
} else {
uxLog(this, c.yellow('Please manually git add, commit and push to the remote repository :)'));
}
uxLog(this, c.greenBright('You may schedule monitoring to be automatically run every day. To do that, go in Project -> CI -> Schedules -> New schedule'));
uxLog(this, c.greenBright(`You may schedule monitoring to be automatically run every day. To do that, go in ${c.bold('Project -> CI -> Schedules -> New schedule')}`));
// Return an object to be displayed with --json
return { outputString: 'Configured branch for authentication' };
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function getBranchConfigFiles() {
if (!isGitRepo()) {
return [];
}
const gitBranchFormatted = await getCurrentGitBranch({ formatted: true });
const gitBranchFormatted = process.env.CONFIG_BRANCH || (await getCurrentGitBranch({ formatted: true }));
const branchConfigFiles = [
`config/branches/.${moduleName}.${gitBranchFormatted}.yaml`,
`config/branches/.${moduleName}.${gitBranchFormatted}.yml`
Expand Down

0 comments on commit 4a618de

Please sign in to comment.