From bb50fd0f8fcfa62681106543e0bfbacf59c3591c Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Tue, 17 Mar 2020 15:47:30 -0700 Subject: [PATCH 1/4] Using constants for helm version in pipelines --- src/lib/constants.ts | 2 ++ src/lib/fileutils.ts | 9 +++++---- src/test/mockFactory.ts | 10 +++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lib/constants.ts b/src/lib/constants.ts index a47cc2e06..09d1459e5 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -5,6 +5,8 @@ export const BEDROCK_FILENAME = "bedrock.yaml"; export const BUILD_SCRIPT_URL = "https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh"; +export const HELM_VERSION = "2.16.3"; + export const HLD_COMPONENT_FILENAME = "component.yaml"; export const PROJECT_INIT_DEPENDENCY_ERROR_MESSAGE = diff --git a/src/lib/fileutils.ts b/src/lib/fileutils.ts index 7b8dc7e03..7bc675292 100644 --- a/src/lib/fileutils.ts +++ b/src/lib/fileutils.ts @@ -3,6 +3,7 @@ import yaml from "js-yaml"; import path from "path"; import { ACCESS_FILENAME, + HELM_VERSION, HLD_COMPONENT_FILENAME, PROJECT_PIPELINE_FILENAME, RENDER_HLD_PIPELINE_FILENAME, @@ -162,7 +163,7 @@ export const serviceBuildAndUpdatePipeline = ( { task: "HelmInstaller@1", inputs: { - helmVersionToInstall: "2.16.3" + helmVersionToInstall: HELM_VERSION } }, { @@ -234,7 +235,7 @@ export const serviceBuildAndUpdatePipeline = ( { task: "HelmInstaller@1", inputs: { - helmVersionToInstall: "2.16.3" + helmVersionToInstall: HELM_VERSION } }, { @@ -496,7 +497,7 @@ const manifestGenerationPipelineYaml = (): string => { { task: "HelmInstaller@1", inputs: { - helmVersionToInstall: "2.16.3" + helmVersionToInstall: HELM_VERSION } }, { @@ -696,7 +697,7 @@ const hldLifecyclePipelineYaml = (): string => { { task: "HelmInstaller@1", inputs: { - helmVersionToInstall: "2.16.3" + helmVersionToInstall: HELM_VERSION } }, { diff --git a/src/test/mockFactory.ts b/src/test/mockFactory.ts index e2c83d71d..0459aeda5 100644 --- a/src/test/mockFactory.ts +++ b/src/test/mockFactory.ts @@ -1,5 +1,5 @@ import yaml from "js-yaml"; -import { VM_IMAGE } from "../lib/constants"; +import { HELM_VERSION, VM_IMAGE } from "../lib/constants"; import { BUILD_REPO_NAME, generateYamlScript, @@ -49,7 +49,7 @@ export const createTestServiceBuildAndUpdatePipelineYaml = ( { task: "HelmInstaller@1", inputs: { - helmVersionToInstall: "2.16.3" + helmVersionToInstall: HELM_VERSION } }, { @@ -121,7 +121,7 @@ export const createTestServiceBuildAndUpdatePipelineYaml = ( { task: "HelmInstaller@1", inputs: { - helmVersionToInstall: "2.16.3" + helmVersionToInstall: HELM_VERSION } }, { @@ -325,7 +325,7 @@ export const createTestHldLifecyclePipelineYaml = ( { task: "HelmInstaller@1", inputs: { - helmVersionToInstall: "2.16.3" + helmVersionToInstall: HELM_VERSION } }, { @@ -426,7 +426,7 @@ export const createTestHldAzurePipelinesYaml = ( { task: "HelmInstaller@1", inputs: { - helmVersionToInstall: "2.16.3" + helmVersionToInstall: HELM_VERSION } }, { From 96e5622ade260b9bcce537fa8c32c96cbffaadc5 Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Tue, 17 Mar 2020 16:06:27 -0700 Subject: [PATCH 2/4] updating pipeline commits to use commit function in build.sh to skip commits if there are no changes --- src/lib/fileutils.ts | 16 ++++------------ src/test/mockFactory.ts | 16 ++++------------ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/lib/fileutils.ts b/src/lib/fileutils.ts index 7bc675292..0925a924d 100644 --- a/src/lib/fileutils.ts +++ b/src/lib/fileutils.ts @@ -282,18 +282,14 @@ export const serviceBuildAndUpdatePipeline = ( `cd $(Build.Repository.Name)/$FAB_SAFE_SERVICE_NAME/${SAFE_SOURCE_BRANCH}`, `echo "FAB SET"`, `fab set --subcomponent chart image.tag=$IMAGE_TAG image.repository=$IMAGE_REPO/$BUILD_REPO_NAME`, - `echo "GIT STATUS"`, - `git status`, - `echo "GIT ADD (git add -A)"`, - `git add -A`, ``, `# Set git identity`, `git config user.email "admin@azuredevops.com"`, `git config user.name "Automated Account"`, ``, `# Commit changes`, - `echo "GIT COMMIT"`, - `git commit -m "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}."`, + `echo "GIT ADD and COMMIT -- Will throw error if there is nothing to commit."`, + `git_commit_if_changes "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}." 1`, ``, `# Git Push`, `git_push`, @@ -736,18 +732,14 @@ const hldLifecyclePipelineYaml = (): string => { `git checkout -b "RECONCILE/$(Build.Repository.Name)-$(Build.BuildNumber)"`, `echo "spk hld reconcile $(Build.Repository.Name) $PWD ./.."`, `spk hld reconcile $(Build.Repository.Name) $PWD ./..`, - `echo "GIT STATUS"`, - `git status`, - `echo "GIT ADD (git add -A)"`, - `git add -A`, ``, `# Set git identity`, `git config user.email "admin@azuredevops.com"`, `git config user.name "Automated Account"`, ``, `# Commit changes`, - `echo "GIT COMMIT"`, - `git commit -m "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)."`, + `echo "GIT ADD and COMMIT -- Will NOT throw error if there is nothing to commit."`, + `git_commit_if_changes "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)." 0`, ``, `# Git Push`, `git_push`, diff --git a/src/test/mockFactory.ts b/src/test/mockFactory.ts index 0459aeda5..4a33eabc1 100644 --- a/src/test/mockFactory.ts +++ b/src/test/mockFactory.ts @@ -168,18 +168,14 @@ export const createTestServiceBuildAndUpdatePipelineYaml = ( `cd $(Build.Repository.Name)/$FAB_SAFE_SERVICE_NAME/${SAFE_SOURCE_BRANCH}`, `echo "FAB SET"`, `fab set --subcomponent chart image.tag=$IMAGE_TAG image.repository=$IMAGE_REPO/$BUILD_REPO_NAME`, - `echo "GIT STATUS"`, - `git status`, - `echo "GIT ADD (git add -A)"`, - `git add -A`, ``, `# Set git identity`, `git config user.email "admin@azuredevops.com"`, `git config user.name "Automated Account"`, ``, `# Commit changes`, - `echo "GIT COMMIT"`, - `git commit -m "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}."`, + `echo "GIT ADD and COMMIT -- Will throw error if there is nothing to commit."`, + `git_commit_if_changes "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}." 1`, ``, `# Git Push`, `git_push`, @@ -364,18 +360,14 @@ export const createTestHldLifecyclePipelineYaml = ( `git checkout -b "RECONCILE/$(Build.Repository.Name)-$(Build.BuildNumber)"`, `echo "spk hld reconcile $(Build.Repository.Name) $PWD ./.."`, `spk hld reconcile $(Build.Repository.Name) $PWD ./..`, - `echo "GIT STATUS"`, - `git status`, - `echo "GIT ADD (git add -A)"`, - `git add -A`, ``, `# Set git identity`, `git config user.email "admin@azuredevops.com"`, `git config user.name "Automated Account"`, ``, `# Commit changes`, - `echo "GIT COMMIT"`, - `git commit -m "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)."`, + `echo "GIT ADD and COMMIT -- Will NOT throw error if there is nothing to commit."`, + `git_commit_if_changes "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)." 0`, ``, `# Git Push`, `git_push`, From 240c01f2b93513c6210a93cedb9c808aff838317 Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Fri, 20 Mar 2020 00:41:36 -0700 Subject: [PATCH 3/4] Modifying lifecycle pipeline to skip pushing empty branches and opening PRs with no changes if there are no updates --- src/lib/fileutils.ts | 9 ++++++++- src/test/mockFactory.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib/fileutils.ts b/src/lib/fileutils.ts index 0925a924d..f628f49d1 100644 --- a/src/lib/fileutils.ts +++ b/src/lib/fileutils.ts @@ -739,7 +739,14 @@ const hldLifecyclePipelineYaml = (): string => { ``, `# Commit changes`, `echo "GIT ADD and COMMIT -- Will NOT throw error if there is nothing to commit."`, - `git_commit_if_changes "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)." 0`, + `didCommit=0`, + `git_commit_if_changes "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)." 0 didCommit`, + ``, + `# Skip push and opening PR steps if there were no changes changes to commit.`, + `if [ $didCommit == 0 ]; then`, + `echo "DID NOT FIND CHANGES TO COMMIT. EXITING."`, + `exit 0`, + `fi`, ``, `# Git Push`, `git_push`, diff --git a/src/test/mockFactory.ts b/src/test/mockFactory.ts index 4a33eabc1..8f1ba5080 100644 --- a/src/test/mockFactory.ts +++ b/src/test/mockFactory.ts @@ -367,7 +367,14 @@ export const createTestHldLifecyclePipelineYaml = ( ``, `# Commit changes`, `echo "GIT ADD and COMMIT -- Will NOT throw error if there is nothing to commit."`, - `git_commit_if_changes "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)." 0`, + `didCommit=0`, + `git_commit_if_changes "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)." 0 didCommit`, + ``, + `# Skip push and opening PR steps if there were no changes changes to commit.`, + `if [ $didCommit == 0 ]; then`, + `echo "DID NOT FIND CHANGES TO COMMIT. EXITING."`, + `exit 0`, + `fi`, ``, `# Git Push`, `git_push`, From 9ffb188dc37a5de3b1dab7bf9ed4257700443e92 Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Fri, 20 Mar 2020 01:14:11 -0700 Subject: [PATCH 4/4] fixing pipeline --- src/lib/fileutils.ts | 2 +- src/test/mockFactory.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/fileutils.ts b/src/lib/fileutils.ts index f628f49d1..1d7f77fd6 100644 --- a/src/lib/fileutils.ts +++ b/src/lib/fileutils.ts @@ -289,7 +289,7 @@ export const serviceBuildAndUpdatePipeline = ( ``, `# Commit changes`, `echo "GIT ADD and COMMIT -- Will throw error if there is nothing to commit."`, - `git_commit_if_changes "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}." 1`, + `git_commit_if_changes "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}." 1 unusedVar`, ``, `# Git Push`, `git_push`, diff --git a/src/test/mockFactory.ts b/src/test/mockFactory.ts index 8f1ba5080..68e6f9c34 100644 --- a/src/test/mockFactory.ts +++ b/src/test/mockFactory.ts @@ -175,7 +175,7 @@ export const createTestServiceBuildAndUpdatePipelineYaml = ( ``, `# Commit changes`, `echo "GIT ADD and COMMIT -- Will throw error if there is nothing to commit."`, - `git_commit_if_changes "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}." 1`, + `git_commit_if_changes "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}." 1 unusedVar`, ``, `# Git Push`, `git_push`,