Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit fc56b19

Browse files
authored
Updating pipelines (build and lifecycle) to have updated failure cases based on if there are any git commits to be made (#426)
* Using constants for helm version in pipelines * updating pipeline commits to use commit function in build.sh to skip commits if there are no changes * Modifying lifecycle pipeline to skip pushing empty branches and opening PRs with no changes if there are no updates * fixing pipeline
1 parent be744de commit fc56b19

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed

src/lib/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export const BEDROCK_FILENAME = "bedrock.yaml";
55
export const BUILD_SCRIPT_URL =
66
"https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh";
77

8+
export const HELM_VERSION = "2.16.3";
9+
810
export const HLD_COMPONENT_FILENAME = "component.yaml";
911

1012
export const PROJECT_INIT_DEPENDENCY_ERROR_MESSAGE =

src/lib/fileutils.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import yaml from "js-yaml";
33
import path from "path";
44
import {
55
ACCESS_FILENAME,
6+
HELM_VERSION,
67
HLD_COMPONENT_FILENAME,
78
PROJECT_PIPELINE_FILENAME,
89
RENDER_HLD_PIPELINE_FILENAME,
@@ -162,7 +163,7 @@ export const serviceBuildAndUpdatePipeline = (
162163
{
163164
task: "HelmInstaller@1",
164165
inputs: {
165-
helmVersionToInstall: "2.16.3"
166+
helmVersionToInstall: HELM_VERSION
166167
}
167168
},
168169
{
@@ -234,7 +235,7 @@ export const serviceBuildAndUpdatePipeline = (
234235
{
235236
task: "HelmInstaller@1",
236237
inputs: {
237-
helmVersionToInstall: "2.16.3"
238+
helmVersionToInstall: HELM_VERSION
238239
}
239240
},
240241
{
@@ -281,18 +282,14 @@ export const serviceBuildAndUpdatePipeline = (
281282
`cd $(Build.Repository.Name)/$FAB_SAFE_SERVICE_NAME/${SAFE_SOURCE_BRANCH}`,
282283
`echo "FAB SET"`,
283284
`fab set --subcomponent chart image.tag=$IMAGE_TAG image.repository=$IMAGE_REPO/$BUILD_REPO_NAME`,
284-
`echo "GIT STATUS"`,
285-
`git status`,
286-
`echo "GIT ADD (git add -A)"`,
287-
`git add -A`,
288285
``,
289286
`# Set git identity`,
290287
`git config user.email "[email protected]"`,
291288
`git config user.name "Automated Account"`,
292289
``,
293290
`# Commit changes`,
294-
`echo "GIT COMMIT"`,
295-
`git commit -m "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}."`,
291+
`echo "GIT ADD and COMMIT -- Will throw error if there is nothing to commit."`,
292+
`git_commit_if_changes "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}." 1 unusedVar`,
296293
``,
297294
`# Git Push`,
298295
`git_push`,
@@ -496,7 +493,7 @@ const manifestGenerationPipelineYaml = (): string => {
496493
{
497494
task: "HelmInstaller@1",
498495
inputs: {
499-
helmVersionToInstall: "2.16.3"
496+
helmVersionToInstall: HELM_VERSION
500497
}
501498
},
502499
{
@@ -696,7 +693,7 @@ const hldLifecyclePipelineYaml = (): string => {
696693
{
697694
task: "HelmInstaller@1",
698695
inputs: {
699-
helmVersionToInstall: "2.16.3"
696+
helmVersionToInstall: HELM_VERSION
700697
}
701698
},
702699
{
@@ -735,18 +732,21 @@ const hldLifecyclePipelineYaml = (): string => {
735732
`git checkout -b "RECONCILE/$(Build.Repository.Name)-$(Build.BuildNumber)"`,
736733
`echo "spk hld reconcile $(Build.Repository.Name) $PWD ./.."`,
737734
`spk hld reconcile $(Build.Repository.Name) $PWD ./..`,
738-
`echo "GIT STATUS"`,
739-
`git status`,
740-
`echo "GIT ADD (git add -A)"`,
741-
`git add -A`,
742735
``,
743736
`# Set git identity`,
744737
`git config user.email "[email protected]"`,
745738
`git config user.name "Automated Account"`,
746739
``,
747740
`# Commit changes`,
748-
`echo "GIT COMMIT"`,
749-
`git commit -m "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)."`,
741+
`echo "GIT ADD and COMMIT -- Will NOT throw error if there is nothing to commit."`,
742+
`didCommit=0`,
743+
`git_commit_if_changes "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)." 0 didCommit`,
744+
``,
745+
`# Skip push and opening PR steps if there were no changes changes to commit.`,
746+
`if [ $didCommit == 0 ]; then`,
747+
`echo "DID NOT FIND CHANGES TO COMMIT. EXITING."`,
748+
`exit 0`,
749+
`fi`,
750750
``,
751751
`# Git Push`,
752752
`git_push`,

src/test/mockFactory.ts

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import yaml from "js-yaml";
2-
import { VM_IMAGE } from "../lib/constants";
2+
import { HELM_VERSION, VM_IMAGE } from "../lib/constants";
33
import {
44
BUILD_REPO_NAME,
55
generateYamlScript,
@@ -49,7 +49,7 @@ export const createTestServiceBuildAndUpdatePipelineYaml = (
4949
{
5050
task: "HelmInstaller@1",
5151
inputs: {
52-
helmVersionToInstall: "2.16.3"
52+
helmVersionToInstall: HELM_VERSION
5353
}
5454
},
5555
{
@@ -121,7 +121,7 @@ export const createTestServiceBuildAndUpdatePipelineYaml = (
121121
{
122122
task: "HelmInstaller@1",
123123
inputs: {
124-
helmVersionToInstall: "2.16.3"
124+
helmVersionToInstall: HELM_VERSION
125125
}
126126
},
127127
{
@@ -168,18 +168,14 @@ export const createTestServiceBuildAndUpdatePipelineYaml = (
168168
`cd $(Build.Repository.Name)/$FAB_SAFE_SERVICE_NAME/${SAFE_SOURCE_BRANCH}`,
169169
`echo "FAB SET"`,
170170
`fab set --subcomponent chart image.tag=$IMAGE_TAG image.repository=$IMAGE_REPO/$BUILD_REPO_NAME`,
171-
`echo "GIT STATUS"`,
172-
`git status`,
173-
`echo "GIT ADD (git add -A)"`,
174-
`git add -A`,
175171
``,
176172
`# Set git identity`,
177173
`git config user.email "[email protected]"`,
178174
`git config user.name "Automated Account"`,
179175
``,
180176
`# Commit changes`,
181-
`echo "GIT COMMIT"`,
182-
`git commit -m "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}."`,
177+
`echo "GIT ADD and COMMIT -- Will throw error if there is nothing to commit."`,
178+
`git_commit_if_changes "Updating $SERVICE_NAME_LOWER image tag to ${IMAGE_TAG}." 1 unusedVar`,
183179
``,
184180
`# Git Push`,
185181
`git_push`,
@@ -325,7 +321,7 @@ export const createTestHldLifecyclePipelineYaml = (
325321
{
326322
task: "HelmInstaller@1",
327323
inputs: {
328-
helmVersionToInstall: "2.16.3"
324+
helmVersionToInstall: HELM_VERSION
329325
}
330326
},
331327
{
@@ -364,18 +360,21 @@ export const createTestHldLifecyclePipelineYaml = (
364360
`git checkout -b "RECONCILE/$(Build.Repository.Name)-$(Build.BuildNumber)"`,
365361
`echo "spk hld reconcile $(Build.Repository.Name) $PWD ./.."`,
366362
`spk hld reconcile $(Build.Repository.Name) $PWD ./..`,
367-
`echo "GIT STATUS"`,
368-
`git status`,
369-
`echo "GIT ADD (git add -A)"`,
370-
`git add -A`,
371363
``,
372364
`# Set git identity`,
373365
`git config user.email "[email protected]"`,
374366
`git config user.name "Automated Account"`,
375367
``,
376368
`# Commit changes`,
377-
`echo "GIT COMMIT"`,
378-
`git commit -m "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)."`,
369+
`echo "GIT ADD and COMMIT -- Will NOT throw error if there is nothing to commit."`,
370+
`didCommit=0`,
371+
`git_commit_if_changes "Reconciling HLD with $(Build.Repository.Name)-$(Build.BuildNumber)." 0 didCommit`,
372+
``,
373+
`# Skip push and opening PR steps if there were no changes changes to commit.`,
374+
`if [ $didCommit == 0 ]; then`,
375+
`echo "DID NOT FIND CHANGES TO COMMIT. EXITING."`,
376+
`exit 0`,
377+
`fi`,
379378
``,
380379
`# Git Push`,
381380
`git_push`,
@@ -426,7 +425,7 @@ export const createTestHldAzurePipelinesYaml = (
426425
{
427426
task: "HelmInstaller@1",
428427
inputs: {
429-
helmVersionToInstall: "2.16.3"
428+
helmVersionToInstall: HELM_VERSION
430429
}
431430
},
432431
{

0 commit comments

Comments
 (0)