Skip to content

Commit

Permalink
Feat/contract test pipeline (#646)
Browse files Browse the repository at this point in the history
* feat: update simple-api ci pipeline to have contract testing steps

* fix: Updated linting errors

* fix: add starting space in comment

* fix: updated openapi relative path

* fix: use correct version numer in can-i-depoy

* fix: use correct version numer in can-i-depoy

* fix: ensure deployments are dependeny on contract tests

* feat: updated ci.yml to include contract tests

* feat: add a run_contract_tests flag

* feat: added contract tests to cqrs and background-worker pipelines

* fix: correct dependencies/conditions on deployment steps

* fix: remove additional dependency

* fix: variable was plural in vars file but not pipelines

* fix: set contract testing to true in ensono pipelines

* qa: test a different condition

* qa: testing new condition

* qa: testing success or skip condition

* qa: testing disabling contract tests

* qa: testing failing contract tests

* fix: use job status conditions

* fix: remove test code

* qa: add dependson

* Fix: add dependson to appinfradev stes

---------
  • Loading branch information
JackMidd-Amido authored Nov 19, 2024
1 parent 9ac4b17 commit f03ffde
Show file tree
Hide file tree
Showing 10 changed files with 527 additions and 0 deletions.
10 changes: 10 additions & 0 deletions build/azDevOps/azure/ci-background-worker-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,13 @@ variables:
value: false
- name: create_resource_group
value: false

# Pact Contract Tests
- name: PACT_BROKER_BASE_URL
value: 'https://ensono-stacks.pactflow.io'
- name: PACTICIPANT_NAME
value: 'stacks-provider'
- name: OAS_FILE
value: ./src/simple-api/contracts/openapi-v1.yaml
- name: run_contract_tests
value: false
10 changes: 10 additions & 0 deletions build/azDevOps/azure/ci-cqrs-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,13 @@ variables:
value: true
- name: create_cosmosdb
value: true

# Pact Contract Tests
- name: PACT_BROKER_BASE_URL
value: 'https://ensono-stacks.pactflow.io'
- name: PACTICIPANT_NAME
value: 'stacks-provider'
- name: OAS_FILE
value: ./src/simple-api/contracts/openapi-v1.yaml
- name: run_contract_tests
value: false
10 changes: 10 additions & 0 deletions build/azDevOps/azure/ci-simple-api-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,13 @@ variables:
value: true
- name: create_cosmosdb
value: false

# Pact Contract Tests
- name: PACT_BROKER_BASE_URL
value: 'https://ensono-stacks.pactflow.io'
- name: PACTICIPANT_NAME
value: 'stacks-provider'
- name: OAS_FILE
value: ./src/simple-api/contracts/openapi-v1.yaml
- name: run_contract_tests
value: false
118 changes: 118 additions & 0 deletions build/azDevOps/azure/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,41 @@ stages:
PROJECT_NAME: $(sonar_project_name)
BUILD_BUILDNUMBER: $(version_number)

- task: Bash@3
displayName: 'Contract Tests: Pull Pact CLI Docker image'
condition: eq(variables.run_contract_tests, true)
inputs:
targetType: inline
script: |
docker pull pactfoundation/pact-cli:latest
- task: Bash@3
displayName: 'Contract Tests: Publish OpenAPI spec to PactFlow'
condition: eq(variables.run_contract_tests, true)
inputs:
targetType: inline
script: |
docker run --rm \
-w ${PWD} \
-v ${PWD}:${PWD} \
-e PACT_BROKER_BASE_URL=$(PACT_BROKER_BASE_URL) \
-e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \
pactfoundation/pact-cli:latest \
pactflow publish-provider-contract \
$(OAS_FILE) \
--provider $(PACTICIPANT_NAME) \
--provider-app-version $(version_number) \
--branch $(Build.SourceBranchName) \
--verification-results $(OAS_FILE) \
--verifier "Verification not necessary when the OpenAPI spec is generated by the API code" \
--tag $(version_number) $(Build.SourceBranchName) \
--content-type "application/yaml" \
--verification-exit-code 0 \
--verification-results-content-type "application/yaml" \
--verification-results-format "yaml"
env:
PACTFLOW_TOKEN: $(PACT_BROKER_TOKEN)

- task: Bash@3
displayName: "TaskCTL: Build Functional Tests"
condition: and(succeeded(), eq(variables.run_functional_tests, true))
Expand Down Expand Up @@ -131,7 +166,33 @@ stages:
- name: core_environment
value: nonprod
jobs:
- job: canideploy_dev
condition: eq(variables.run_contract_tests, true)
steps:
- task: Bash@3
displayName: 'Pull Pact CLI Docker image'
inputs:
targetType: inline
script: |
docker pull pactfoundation/pact-cli:latest
- task: Bash@3
displayName: 'Contract Tests: can-i-deploy to dev'
inputs:
targetType: inline
script: |
docker run --rm \
-e PACT_BROKER_BASE_URL=$(PACT_BROKER_BASE_URL) \
-e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \
pactfoundation/pact-cli:latest \
broker can-i-deploy \
--pacticipant $(PACTICIPANT_NAME) \
--version $(version_number) \
--to-environment $(Environment.ShortName)
- deployment: AppInfraDev
dependsOn: canideploy_dev
condition: or(succeeded('canideploy_dev'), eq(dependencies.canideploy_dev.result, 'skipped'))
pool:
vmImage: $(pool_vm_image)

Expand Down Expand Up @@ -336,6 +397,22 @@ stages:
failTaskOnFailedTests: true # Optional
testRunTitle: Dev Functional Test Report

- task: Bash@3
displayName: 'Contract Tests: Record-deployment to dev'
condition: and(succeeded(), eq(variables.run_contract_tests, true))
inputs:
targetType: inline
script: |
docker run --rm \
-e PACT_BROKER_BASE_URL=$(PACT_BROKER_BASE_URL) \
-e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \
pactfoundation/pact-cli:latest \
broker record-deployment \
--pacticipant $(PACTICIPANT_NAME) \
--version $(version_number) \
--environment $(Environment.ShortName)
- stage: Prod
dependsOn: Build
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/main')))
Expand All @@ -348,7 +425,33 @@ stages:
- name: core_environment
value: prod
jobs:
- job: canideploy_prod
condition: eq(variables.run_contract_tests, true)
steps:
- task: Bash@3
displayName: 'Pull Pact CLI Docker image'
inputs:
targetType: inline
script: |
docker pull pactfoundation/pact-cli:latest
- task: Bash@3S
displayName: 'Contract Tests: can-i-deploy to prod'
inputs:
targetType: inline
script: |
docker run --rm \
-e PACT_BROKER_BASE_URL=$(PACT_BROKER_BASE_URL) \
-e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \
pactfoundation/pact-cli:latest \
broker can-i-deploy \
--pacticipant $(PACTICIPANT_NAME) \
--version $(version_number) \
--to-environment $(Environment.ShortName)
- deployment: AppInfraProd
dependsOn: canideploy_prod
condition: or(succeeded('canideploy_prod'), eq(dependencies.canideploy_prod.result, 'skipped'))
pool:
vmImage: $(pool_vm_image)

Expand Down Expand Up @@ -557,6 +660,21 @@ stages:
failTaskOnFailedTests: true # Optional
testRunTitle: Prod Functional Test Report

- task: Bash@3
displayName: 'Contract Tests: Record-deployment to prod'
condition: and(succeeded(), eq(variables.run_contract_tests, true))
inputs:
targetType: inline
script: |
docker run --rm \
-e PACT_BROKER_BASE_URL=$(PACT_BROKER_BASE_URL) \
-e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \
pactfoundation/pact-cli:latest \
broker record-deployment \
--pacticipant $(PACTICIPANT_NAME) \
--version $(version_number) \
--environment $(Environment.ShortName)
- template: release-notes/publish-release-notes.yml
parameters:
enable: ${{ variables['enable_release_note_generation'] }}
Expand Down
10 changes: 10 additions & 0 deletions build/azDevOps/azure/ensono/ci-background-worker-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,13 @@ variables:
value: false
- name: create_resource_group
value: false

# Pact Contract Tests
- name: PACT_BROKER_BASE_URL
value: 'https://ensono-stacks.pactflow.io'
- name: PACTICIPANT_NAME
value: 'stacks-provider'
- name: OAS_FILE
value: ./src/simple-api/contracts/openapi-v1.yaml
- name: run_contract_tests
value: true
115 changes: 115 additions & 0 deletions build/azDevOps/azure/ensono/ci-background-worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,39 @@ stages:
PROJECT_NAME: $(sonar_project_name)
BUILD_BUILDNUMBER: $(version_number)

- task: Bash@3
displayName: 'Contract Tests: Pull Pact CLI Docker image'
condition: eq(variables.run_contract_tests, true)
inputs:
targetType: inline
script: |
docker pull pactfoundation/pact-cli:latest
- task: Bash@3
displayName: 'Contract Tests: Publish OpenAPI spec to PactFlow'
condition: eq(variables.run_contract_tests, true)
inputs:
targetType: inline
script: |
docker run --rm \
-w ${PWD} \
-v ${PWD}:${PWD} \
-e PACT_BROKER_BASE_URL=$(PACT_BROKER_BASE_URL) \
-e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \
pactfoundation/pact-cli:latest \
pactflow publish-provider-contract \
$(OAS_FILE) \
--provider $(PACTICIPANT_NAME) \
--provider-app-version $(version_number) \
--branch $(Build.SourceBranchName) \
--verification-results $(OAS_FILE) \
--verifier "Verification not necessary when the OpenAPI spec is generated by the API code" \
--tag $(version_number) $(Build.SourceBranchName) \
--content-type "application/yaml" \
--verification-exit-code 0 \
--verification-results-content-type "application/yaml" \
--verification-results-format "yaml"
- task: Bash@3
displayName: "TaskCTL: Build Functional Tests"
condition: and(succeeded(), eq(variables.run_functional_tests, true))
Expand Down Expand Up @@ -138,7 +171,33 @@ stages:
- name: core_environment
value: nonprod
jobs:
- job: canideploy_dev
condition: eq(variables.run_contract_tests, true)
steps:
- task: Bash@3
displayName: 'Pull Pact CLI Docker image'
inputs:
targetType: inline
script: |
docker pull pactfoundation/pact-cli:latest
- task: Bash@3
displayName: 'Contract Tests: can-i-deploy to dev'
inputs:
targetType: inline
script: |
docker run --rm \
-e PACT_BROKER_BASE_URL=$(PACT_BROKER_BASE_URL) \
-e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \
pactfoundation/pact-cli:latest \
broker can-i-deploy \
--pacticipant $(PACTICIPANT_NAME) \
--version $(version_number) \
--to-environment $(Environment.ShortName)
- deployment: AppInfraDev
dependsOn: canideploy_dev
condition: or(succeeded('canideploy_dev'), eq(dependencies.canideploy_dev.result, 'skipped'))
pool:
vmImage: $(pool_vm_image)

Expand Down Expand Up @@ -343,6 +402,21 @@ stages:
failTaskOnFailedTests: true # Optional
testRunTitle: Dev Functional Test Report

- task: Bash@3
displayName: 'Contract Tests: Record-deployment to dev'
condition: and(succeeded(), eq(variables.run_contract_tests, true))
inputs:
targetType: inline
script: |
docker run --rm \
-e PACT_BROKER_BASE_URL=$(PACT_BROKER_BASE_URL) \
-e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \
pactfoundation/pact-cli:latest \
broker record-deployment \
--pacticipant $(PACTICIPANT_NAME) \
--version $(version_number) \
--environment $(Environment.ShortName)
- stage: Prod
dependsOn: Build
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/main')))
Expand All @@ -355,7 +429,33 @@ stages:
- name: core_environment
value: prod
jobs:
- job: canideploy_prod
condition: eq(variables.run_contract_tests, true)
steps:
- task: Bash@3
displayName: 'Pull Pact CLI Docker image'
inputs:
targetType: inline
script: |
docker pull pactfoundation/pact-cli:latest
- task: Bash@3
displayName: 'Contract Tests: can-i-deploy to prod'
inputs:
targetType: inline
script: |
docker run --rm \
-e PACT_BROKER_BASE_URL=$(PACT_BROKER_BASE_URL) \
-e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \
pactfoundation/pact-cli:latest \
broker can-i-deploy \
--pacticipant $(PACTICIPANT_NAME) \
--version $(version_number) \
--to-environment $(Environment.ShortName)
- deployment: AppInfraProd
dependsOn: canideploy_prod
condition: or(succeeded('canideploy_prod'), eq(dependencies.canideploy_prod.result, 'skipped'))
pool:
vmImage: $(pool_vm_image)

Expand Down Expand Up @@ -564,6 +664,21 @@ stages:
failTaskOnFailedTests: true # Optional
testRunTitle: Prod Functional Test Report

- task: Bash@3
displayName: 'Contract Tests: Record-deployment to prod'
condition: and(succeeded(), eq(variables.run_contract_tests, true))
inputs:
targetType: inline
script: |
docker run --rm \
-e PACT_BROKER_BASE_URL=$(PACT_BROKER_BASE_URL) \
-e PACT_BROKER_TOKEN=$(PACT_BROKER_TOKEN) \
pactfoundation/pact-cli:latest \
broker record-deployment \
--pacticipant $(PACTICIPANT_NAME) \
--version $(version_number) \
--environment $(Environment.ShortName)
- template: ../release-notes/publish-release-notes.yml
parameters:
enable: ${{ variables['enable_release_note_generation'] }}
Expand Down
10 changes: 10 additions & 0 deletions build/azDevOps/azure/ensono/ci-cqrs-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,13 @@ variables:
value: true
- name: create_cosmosdb
value: true

# Pact Contract Tests
- name: PACT_BROKER_BASE_URL
value: 'https://ensono-stacks.pactflow.io'
- name: PACTICIPANT_NAME
value: 'stacks-provider'
- name: OAS_FILE
value: ./src/simple-api/contracts/openapi-v1.yaml
- name: run_contract_tests
value: true
Loading

0 comments on commit f03ffde

Please sign in to comment.