Skip to content
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
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'
- name: Test
run: GIT_BRANCH=${GITHUB_REF:11} make test

Expand All @@ -31,7 +31,7 @@ jobs:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: docker pull pactfoundation/pact-cli:latest
- name: Can I deploy?
run: GIT_BRANCH=${GITHUB_REF:11} make can_i_deploy
Expand All @@ -41,7 +41,7 @@ jobs:
runs-on: ubuntu-latest
needs: can-i-deploy
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: docker pull pactfoundation/pact-cli:latest
- name: Deploy
run: GIT_BRANCH=${GITHUB_REF:11} make deploy
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/contract_requiring_verification_published.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: contract_requiring_verification_published

# This workflow leverages the https://docs.pact.io/pact_broker/webhooks#the-contract-requiring-verification-published-event webhook

on:
repository_dispatch:
types:
- contract_requiring_verification_published
workflow_dispatch:
# inputs aren't available on push, so we set them explicitly in separate steps
inputs:
PACT_URL:
description: URL of pact to verify
required: true

env:
PACT_BROKER_BASE_URL: https://test.pactflow.io
PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_TOKEN_FOR_CI_CD_WORKSHOP }}
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS: true
PACT_BROKER_HOST: test.pactflow.io # For pact-jvm
PACT_URL: ${{ github.event.client_payload.pact_url }}
GIT_COMMIT: ${{ github.event.client_payload.sha }}
GIT_BRANCH: ${{ github.event.client_payload.branch }}
DESCRIPTION: ${{ github.event.client_payload.message }}

jobs:
verify-contract-requiring-verification:
runs-on: ubuntu-latest
steps:
- name: checkout default branch if user manually provides pact URL
uses: actions/checkout@v4
if: ${{ github.event.inputs.PACT_URL }}
- name: checkout specific SHA if webhook provides pact URL
uses: actions/checkout@v4
if: ${{ github.event.client_payload.pact_url }}
with:
ref: ${{env.GIT_COMMIT}}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- run: docker pull pactfoundation/pact-cli:latest
- name: ${{env.DESCRIPTION}}
run: make ci_webhook
27 changes: 0 additions & 27 deletions .github/workflows/verify_changed_pact.yml

This file was deleted.

1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17.0
34 changes: 14 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PACTICIPANT := "pactflow-example-provider-java-soap"
WEBHOOK_UUID := "962805aa-9f31-4a07-8d54-2355344a6f47"
GITHUB_REPO := "pactflow/example-provider-java-soap"
CONTRACT_REQUIRING_VERIFICATION_PUBLISHED_WEBHOOK_UUID := "962805aa-9f31-4a07-8d54-2355344a6f47"
PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli:latest"

# Only deploy from master
Expand All @@ -24,7 +25,7 @@ fake_ci: .env
CI=true \
GIT_COMMIT=`git rev-parse --short HEAD`+`date +%s` \
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=false \
make ci

ci_webhook: .env
Expand All @@ -34,7 +35,7 @@ fake_ci_webhook:
CI=true \
GIT_COMMIT=`git rev-parse --short HEAD`+`date +%s` \
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=false \
make ci_webhook

## =====================
Expand All @@ -48,7 +49,7 @@ test: .env
## Deploy tasks
## =====================

deploy: deploy_app tag record_deployment
deploy: deploy_app record_deployment

no_deploy:
@echo "Not deploying as not on master branch"
Expand All @@ -65,13 +66,6 @@ can_i_deploy: .env
deploy_app:
@echo "Deploying to prod"

tag: .env
@"${PACT_CLI}" broker create-version-tag \
--pacticipant ${PACTICIPANT} \
--version ${GIT_COMMIT} \
--auto-create-version \
--tag ${GIT_BRANCH}

record_deployment: .env
@"${PACT_CLI}" broker record-deployment --pacticipant ${PACTICIPANT} --version ${GIT_COMMIT} --environment production

Expand All @@ -89,20 +83,20 @@ create_github_token_secret:

# NOTE: the github token secret must be created (either through the UI or using the
# `create_github_token_secret` target) before the webhook is invoked.
create_or_update_pact_changed_webhook:
create_or_update_contract_requiring_verification_published_webhook:
"${PACT_CLI}" \
broker create-or-update-webhook \
"https://api.github.com/repos/${GITHUB_REPO}/dispatches" \
--header 'Content-Type: application/json' 'Accept: application/vnd.github.everest-preview+json' 'Authorization: Bearer $${user.githubToken}' \
--request POST \
--data '{ "event_type": "pact_changed", "client_payload": { "pact_url": "$${pactbroker.pactUrl}" } }' \
--uuid ${PACT_CHANGED_WEBHOOK_UUID} \
--consumer ${PACTICIPANT} \
--contract-content-changed \
--description "Pact content changed for ${PACTICIPANT}"

test_pact_changed_webhook:
@curl -v -X POST ${PACT_BROKER_BASE_URL}/webhooks/${PACT_CHANGED_WEBHOOK_UUID}/execute -H "Authorization: Bearer ${PACT_BROKER_TOKEN}"
--data '{ "event_type": "contract_requiring_verification_published","client_payload": { "pact_url": "$${pactbroker.pactUrl}", "sha": "$${pactbroker.providerVersionNumber}", "branch":"$${pactbroker.providerVersionBranch}" , "message": "Verify changed pact for $${pactbroker.consumerName} version $${pactbroker.consumerVersionNumber} branch $${pactbroker.consumerVersionBranch} by $${pactbroker.providerVersionNumber} ($${pactbroker.providerVersionDescriptions})" } }' \
--uuid ${CONTRACT_REQUIRING_VERIFICATION_PUBLISHED_WEBHOOK_UUID} \
--provider ${PACTICIPANT} \
--contract-requiring-verification-published \
--description "contract_requiring_verification_published for ${PACTICIPANT}"

test_contract_requiring_verification_published_webhook:
@curl -v -X POST ${PACT_BROKER_BASE_URL}/webhooks/${CONTRACT_REQUIRING_VERIFICATION_PUBLISHED_WEBHOOK_UUID}/execute -H "Authorization: Bearer ${PACT_BROKER_TOKEN}"

## ======================
## Misc
Expand Down
45 changes: 37 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.6'
id 'java'
}

group = 'io.pactflow.example.xml.provider'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
java {
sourceCompatibility = '17'
}

repositories {
mavenLocal()
Expand All @@ -22,13 +24,13 @@ configurations {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.2'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.18.0'
runtimeOnly 'com.h2database:h2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'au.com.dius.pact.provider:junit5:4.1.7'
testImplementation 'au.com.dius.pact.provider:spring:4.1.7'
testImplementation 'au.com.dius.pact.provider:junit5:4.5.13'
testImplementation 'au.com.dius.pact.provider:spring6:4.5.13'
testImplementation 'org.apache.commons:commons-lang3:3.11'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
Expand All @@ -39,7 +41,34 @@ test {
useJUnitPlatform()

// These properties need to be set on the test JVM process
//https://docs.pact.io/implementation_guides/jvm/provider/junit#using-java-system-properties


// required variables for fetching dynamic pacts, & publishing verification results
// used for fetching dynamic pacts
systemProperty("pactbroker.providerBranch", System.getenv("GIT_BRANCH") == null ? "" : System.getenv("GIT_BRANCH"))
// used for publishing verification results
systemProperty("pact.provider.branch", System.getenv("GIT_BRANCH") == null ? "" : System.getenv("GIT_BRANCH"))
systemProperty("pact.provider.version", System.getenv("GIT_COMMIT") == null ? "" : System.getenv("GIT_COMMIT"))
systemProperty("pact.provider.tag", System.getenv("GIT_BRANCH") == null ? "" : System.getenv("GIT_BRANCH"))

// only publish verification results from CI allowing developers to run tests locally and debug, without affecting broker results
// only verification results from a known source (such at a commit in a VCS and a reproducible environment such as CI) should be published
systemProperty("pact.verifier.publishResults", System.getenv("PACT_BROKER_PUBLISH_VERIFICATION_RESULTS") == null ? "false" : "true")
}

// Consumer version selectors for dynamically fetching pacts
// https://docs.pact.io/implementation_guides/jvm/provider/junit#selecting-the-pacts-to-verify-with-consumer-version-selectors-4314
// Runs when the provider code changes
systemProperty("pactbroker.consumerversionselectors.rawjson", "[{\"mainBranch\":true},{\"deployedOrReleased\":true},{\"matchingBranch\":true}]")
// Allow just the changed pact triggered by webhook, to be verified, ignoring the consumer version selectors above
// https://docs.pact.io/implementation_guides/jvm/provider/junit#allowing-just-the-changed-pact-specified-in-a-webhook-to-be-verified-406
// Runs when the consumer contract changes
systemProperty("pact.filter.pacturl", System.getenv("PACT_URL") == null ? null : System.getenv("PACT_URL"))
systemProperty("pact.filter.consumers", System.getenv("PACT_URL") == null ? null : System.getenv("PACT_URL").split("/consumer/")[1])

// pending pacts
systemProperty("pactbroker.enablePending", true)

// work in progress pacts
systemProperty("pactbroker.includeWipPactsSince", java.time.LocalDate.now().minusMonths(6).format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd")))

}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading