Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 34 additions & 22 deletions src/lib/fileutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ export const serviceBuildAndUpdatePipeline = (
]),
displayName: "Azure Login"
},
{
script: generateYamlScript([
`# Download build.sh`,
`curl $BEDROCK_BUILD_SCRIPT > build.sh`,
`chmod +x ./build.sh`
]),
displayName: "Download bedrock bash scripts",
env: {
BEDROCK_BUILD_SCRIPT: "$(BUILD_SCRIPT_URL)"
}
},
{
script: generateYamlScript([
`export BUILD_REPO_NAME=${BUILD_REPO_NAME(serviceName)}`,
Expand All @@ -232,9 +243,6 @@ export const serviceBuildAndUpdatePipeline = (
`service=\${service##*/}`,
`url=$(git remote --verbose | grep origin | grep fetch | cut -f2 | cut -d' ' -f1)`,
`repourl=\${url##*@}`,
`echo "Downloading SPK"`,
`curl https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh > build.sh`,
`chmod +x build.sh`,
`. ./build.sh --source-only`,
`get_spk_version`,
`download_spk`,
Expand Down Expand Up @@ -347,7 +355,6 @@ export const serviceBuildAndUpdatePipeline = (
`response=$(az repos pr create --description "Updating $SERVICE_NAME_LOWER to ${IMAGE_TAG}." "PR created by: $(Build.DefinitionName) with buildId: $(Build.BuildId) and buildNumber: $(Build.BuildNumber)")`,
`pr_id=$(echo $response | jq -r '.pullRequestId')`,
``,
``,
`# Update introspection storage with this information, if applicable`,
`if [ -z "$(INTROSPECTION_ACCOUNT_NAME)" -o -z "$(INTROSPECTION_ACCOUNT_KEY)" -o -z "$(INTROSPECTION_TABLE_NAME)" -o -z "$(INTROSPECTION_PARTITION_KEY)" ]; then`,
`echo "Introspection variables are not defined. Skipping..."`,
Expand All @@ -356,10 +363,6 @@ export const serviceBuildAndUpdatePipeline = (
`tag_name="$BUILD_REPO_NAME:$(Build.SourceBranchName)-$(Build.BuildNumber)"`,
`url=$(git remote --verbose | grep origin | grep fetch | cut -f2 | cut -d' ' -f1)`,
`repourl=\${url##*@}`,
`echo "Downloading SPK"`,
`curl https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh > build.sh`,
`chmod +x build.sh`,
`. ./build.sh --source-only`,
`get_spk_version`,
`download_spk`,
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p2 $(Build.BuildId) --hld-commit-id $latest_commit --env $BRANCH_NAME --image-tag $tag_name --pr $pr_id --repository $repourl`,
Expand Down Expand Up @@ -580,6 +583,26 @@ const manifestGenerationPipelineYaml = (): string => {
BEDROCK_BUILD_SCRIPT: "$(BUILD_SCRIPT_URL)"
}
},
{
script: generateYamlScript([
`commitId=$(Build.SourceVersion)`,
`commitId=$(echo "\${commitId:0:7}")`,
`. ./build.sh --source-only`,
`get_spk_version`,
`download_spk`,
`message="$(Build.SourceVersionMessage)"`,
`if [[ $message == *"Merged PR"* ]]; then`,
`pr_id=$(echo $message | grep -oE '[0-9]+' | head -1 | sed -e 's/^0\\+//')`,
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId --pr $pr_id`,
`else`,
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId`,
`fi`
]),
displayName:
"If configured, update manifest pipeline details in Spektate db before manifest generation",
condition:
"and(ne(variables['INTROSPECTION_ACCOUNT_NAME'], ''), ne(variables['INTROSPECTION_ACCOUNT_KEY'], ''),ne(variables['INTROSPECTION_TABLE_NAME'], ''),ne(variables['INTROSPECTION_PARTITION_KEY'], ''))"
},
{
task: "ShellScript@2",
displayName: "Validate fabrikate definitions",
Expand Down Expand Up @@ -608,28 +631,17 @@ const manifestGenerationPipelineYaml = (): string => {
},
{
script: generateYamlScript([
`. ./build.sh --source-only`,
`cd "$HOME"/\${MANIFEST_REPO##*/}`,
`commitId=$(Build.SourceVersion)`,
`commitId=$(echo "\${commitId:0:7}")`,
`latest_commit=$(git rev-parse --short HEAD)`,
`url=$(git remote --verbose | grep origin | grep fetch | cut -f2 | cut -d' ' -f1)`,
`repourl=\${url##*@}`,
`echo "Downloading SPK"`,
`curl https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh > build.sh`,
`chmod +x build.sh`,
`. ./build.sh --source-only`,
`get_spk_version`,
`download_spk`,
`message="$(Build.SourceVersionMessage)"`,
`if [[ $message == *"Merged PR"* ]]; then`,
`pr_id=$(echo $message | grep -oE '[0-9]+' | head -1 | sed -e 's/^0\\+//')`,
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId --manifest-commit-id $latest_commit --pr $pr_id --repository $repourl`,
`else`,
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId --manifest-commit-id $latest_commit --repository $repourl`,
`fi`
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --manifest-commit-id $latest_commit --repository $repourl`
]),
displayName:
"If configured, update manifest pipeline details in Spektate db",
"If configured, update manifest pipeline details in Spektate db after manifest generation",
condition:
"and(ne(variables['INTROSPECTION_ACCOUNT_NAME'], ''), ne(variables['INTROSPECTION_ACCOUNT_KEY'], ''),ne(variables['INTROSPECTION_TABLE_NAME'], ''),ne(variables['INTROSPECTION_PARTITION_KEY'], ''))"
}
Expand Down
56 changes: 34 additions & 22 deletions src/test/mockFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ export const createTestServiceBuildAndUpdatePipelineYaml = (
]),
displayName: "Azure Login"
},
{
script: generateYamlScript([
`# Download build.sh`,
`curl $BEDROCK_BUILD_SCRIPT > build.sh`,
`chmod +x ./build.sh`
]),
displayName: "Download bedrock bash scripts",
env: {
BEDROCK_BUILD_SCRIPT: "$(BUILD_SCRIPT_URL)"
}
},
{
script: generateYamlScript([
`export BUILD_REPO_NAME=${BUILD_REPO_NAME(serviceName)}`,
Expand All @@ -63,9 +74,6 @@ export const createTestServiceBuildAndUpdatePipelineYaml = (
`service=\${service##*/}`,
`url=$(git remote --verbose | grep origin | grep fetch | cut -f2 | cut -d' ' -f1)`,
`repourl=\${url##*@}`,
`echo "Downloading SPK"`,
`curl https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh > build.sh`,
`chmod +x build.sh`,
`. ./build.sh --source-only`,
`get_spk_version`,
`download_spk`,
Expand Down Expand Up @@ -178,7 +186,6 @@ export const createTestServiceBuildAndUpdatePipelineYaml = (
`response=$(az repos pr create --description "Updating $SERVICE_NAME_LOWER to ${IMAGE_TAG}." "PR created by: $(Build.DefinitionName) with buildId: $(Build.BuildId) and buildNumber: $(Build.BuildNumber)")`,
`pr_id=$(echo $response | jq -r '.pullRequestId')`,
``,
``,
`# Update introspection storage with this information, if applicable`,
`if [ -z "$(INTROSPECTION_ACCOUNT_NAME)" -o -z "$(INTROSPECTION_ACCOUNT_KEY)" -o -z "$(INTROSPECTION_TABLE_NAME)" -o -z "$(INTROSPECTION_PARTITION_KEY)" ]; then`,
`echo "Introspection variables are not defined. Skipping..."`,
Expand All @@ -187,10 +194,6 @@ export const createTestServiceBuildAndUpdatePipelineYaml = (
`tag_name="$BUILD_REPO_NAME:$(Build.SourceBranchName)-$(Build.BuildNumber)"`,
`url=$(git remote --verbose | grep origin | grep fetch | cut -f2 | cut -d' ' -f1)`,
`repourl=\${url##*@}`,
`echo "Downloading SPK"`,
`curl https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh > build.sh`,
`chmod +x build.sh`,
`. ./build.sh --source-only`,
`get_spk_version`,
`download_spk`,
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p2 $(Build.BuildId) --hld-commit-id $latest_commit --env $BRANCH_NAME --image-tag $tag_name --pr $pr_id --repository $repourl`,
Expand Down Expand Up @@ -430,6 +433,26 @@ export const createTestHldAzurePipelinesYaml = (
BEDROCK_BUILD_SCRIPT: "$(BUILD_SCRIPT_URL)"
}
},
{
script: generateYamlScript([
`commitId=$(Build.SourceVersion)`,
`commitId=$(echo "\${commitId:0:7}")`,
`. ./build.sh --source-only`,
`get_spk_version`,
`download_spk`,
`message="$(Build.SourceVersionMessage)"`,
`if [[ $message == *"Merged PR"* ]]; then`,
`pr_id=$(echo $message | grep -oE '[0-9]+' | head -1 | sed -e 's/^0\\+//')`,
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId --pr $pr_id`,
`else`,
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId`,
`fi`
]),
displayName:
"If configured, update manifest pipeline details in Spektate db before manifest generation",
condition:
"and(ne(variables['INTROSPECTION_ACCOUNT_NAME'], ''), ne(variables['INTROSPECTION_ACCOUNT_KEY'], ''),ne(variables['INTROSPECTION_TABLE_NAME'], ''),ne(variables['INTROSPECTION_PARTITION_KEY'], ''))"
},
{
task: "ShellScript@2",
displayName: "Validate fabrikate definitions",
Expand Down Expand Up @@ -458,28 +481,17 @@ export const createTestHldAzurePipelinesYaml = (
},
{
script: generateYamlScript([
`. ./build.sh --source-only`,
`cd "$HOME"/\${MANIFEST_REPO##*/}`,
`commitId=$(Build.SourceVersion)`,
`commitId=$(echo "\${commitId:0:7}")`,
`latest_commit=$(git rev-parse --short HEAD)`,
`url=$(git remote --verbose | grep origin | grep fetch | cut -f2 | cut -d' ' -f1)`,
`repourl=\${url##*@}`,
`echo "Downloading SPK"`,
`curl https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh > build.sh`,
`chmod +x build.sh`,
`. ./build.sh --source-only`,
`get_spk_version`,
`download_spk`,
`message="$(Build.SourceVersionMessage)"`,
`if [[ $message == *"Merged PR"* ]]; then`,
`pr_id=$(echo $message | grep -oE '[0-9]+' | head -1 | sed -e 's/^0\\+//')`,
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId --manifest-commit-id $latest_commit --pr $pr_id --repository $repourl`,
`else`,
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId --manifest-commit-id $latest_commit --repository $repourl`,
`fi`
`./spk/spk deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --manifest-commit-id $latest_commit --repository $repourl`
]),
displayName:
"If configured, update manifest pipeline details in Spektate db",
"If configured, update manifest pipeline details in Spektate db after manifest generation",
condition:
"and(ne(variables['INTROSPECTION_ACCOUNT_NAME'], ''), ne(variables['INTROSPECTION_ACCOUNT_KEY'], ''),ne(variables['INTROSPECTION_TABLE_NAME'], ''),ne(variables['INTROSPECTION_PARTITION_KEY'], ''))"
}
Expand Down