I can’t seem to make CI pipeline work when provide...
# general
c
I can’t seem to make CI pipeline work when provider is deployed first. Getting
Computer says no
on
can-i-deploy
. Steps taken on thread.
Provider: 1.
VERSION=1.0.0 CI=true PACT_BROKER_BASE_URL=<http://localhost:9292> make test
2. Provider test selector:
Copy code
ConsumerVersionSelectors: []provider.Selector{
	&provider.ConsumerVersionSelector{
		MainBranch: true,
	},
	&provider.ConsumerVersionSelector{
		DeployedOrReleased: true,
	},
	&provider.ConsumerVersionSelector{
		MatchingBranch: true,
	},
},
3.
pact-broker create-or-update-version --broker-base-url "<http://localhost:9292>" --pacticipant provider-service --version 1.0.0
4,
pact-broker can-i-deploy --broker-base-url "<http://localhost:9292>" --pacticipant provider-service --to-environment dev --version 1.0.0
5. Computer says yes \o/ 6. There are no missing dependencies 7.
pact-broker record-release --pacticipant provider-service --version "1.0.0" --environment dev --broker-base-url "<http://localhost:9292>"
Recorded release of provider-service version 1.0.0 to dev environment in the Pact Broker.
Consumer: 1.
pact-broker publish "./backend/pacts/" --consumer-app-version 1.0.0 --branch "master" --broker-base-url "<http://localhost:9292>"
2.
pact-broker create-or-update-version --broker-base-url "<http://localhost:9292>" --pacticipant consumer-service --version 1.0.0
3. Created/updated pacticipant version 1.0.0 in the Pact Broker 4.
pact-broker can-i-deploy --broker-base-url "<http://localhost:9292>" --pacticipant consumer-service --to-environment dev --version "1.0.0"
Computer says no ¯\_(ツ)_/¯ CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS? | RESULT# ---------------------|-----------|-------------------------|-----------|----------|-------- consumer-service | 1.0.0 | provider-service | ??? | ??? | There is no verified pact between version 1.0.0 of consumer-service and the version of provider-service currently in dev (1.0.0)
y
you haven’t shown any steps, where you’ve actually verified the consumer pact against the provider, so the output looks correct to me
c
Which steps am I missing? Or could clarify? FYI: they are both golang services using pact-go
y
It looks like you are missing the key part, which is verifying the consumer contract is aligned with your provider. There are two ways to verify pacts https://docs.pact.io/pact_nirvana/step_4#verifying-pacts It looks like you’ve just set up 1 and haven’t setup anything to verify the changed pact. https://docs.pact.io/pact_nirvana/step_6#add-a-new-provider-verification-job
c
The
make test
on the provider would run this go test, wouldn’t this handle that verification:
Copy code
err := verifier.VerifyProvider(t, provider.VerifyRequest{
		BrokerURL:                  os.Getenv("PACT_BROKER_BASE_URL"),
		ProviderBaseURL:            "http://" + serverAddress,
		PublishVerificationResults: os.Getenv("CI") == "true",
		ProviderVersion:            os.Getenv("VERSION"),
		ProviderBranch:             "master",
		Provider:                   "provider-service",
		ConsumerVersionSelectors: []provider.Selector{
			&provider.ConsumerVersionSelector{
				MainBranch: true,
			},
			&provider.ConsumerVersionSelector{
				DeployedOrReleased: true,
			},
			&provider.ConsumerVersionSelector{
				MatchingBranch: true,
			},
		},
	})
Seems like I need to have a better look on the webhook part
y
it should grab it under
MainBranch
consumer version selector, but that would rely on you running that provider verification job again (either manually) or on the next provider change, in order for it to verify it and publish results. that time gap for feedback is usually too long, which is why you have a task utilising webhooks, your verification task should accept a pactUrl and if one exists not pass any consumer version selectors to the broker. This is a verification triggered by a pact change.
c
Thanks @Yousaf Nabi (pactflow.io). I’m trying to run manually before working on the webhook. It’s not working, what am I missing? Consumer:
Copy code
❯ pact-broker publish  "./backend/pacts/" --consumer-app-version 1.0.0 --branch "master" --broker-base-url "<http://127.0.0.1:9292>"
Updated consumer-service version 1.0.0 with branch master
Pact successfully republished for consumer-service version 1.0.0 and provider provider-service with no content changes.
  View the published pact at <http://127.0.0.1:9292/pacts/provider/provider-service/consumer/consumer-service/version/1.0.0>
  Events detected: contract_published, contract_requiring_verification_published
  Next steps:
    * Add Pact verification tests to the provider-service build. See <https://docs.pact.io/go/provider_verification>
    * Configure separate provider-service pact verification build and webhook to trigger it when the pact content changes. See <https://docs.pact.io/go/webhooks>
Provider:
Copy code
❯ VERSION=1.0.0 CI=true PACT_BROKER_BASE_URL=<http://127.0.0.1:9292> make test
go test -v ./...
=== RUN   TestHTTPProvider
⇨ http server started on 127.0.0.1:8080
2024-02-20T10:20:22.394984Z  INFO ThreadId(11) pact_verifier::pact_broker: Fetching path '/' from pact broker
2024-02-20T10:20:22.411647Z  INFO ThreadId(11) pact_verifier::pact_broker: Fetching path '/pacts/provider/provider-service/for-verification' from pact broker
2024-02-20T10:20:22.442008Z ERROR ThreadId(11) pact_verifier: No pacts found for provider 'provider-service' matching the given consumer version selectors in pact broker '<http://127.0.0.1:9292>': Link/Resource was not found - No pacts were found for this provider
2024-02-20T10:20:22.442563Z  WARN ThreadId(11) pact_verifier: Ignoring no pacts error - No pacts found for provider 'provider-service' matching the given consumer version selectors in pact broker '<http://127.0.0.1:9292>'
2024-02-20T10:20:22.442801Z  WARN ThreadId(11) pact_matching::metrics:

=== RUN   TestHTTPProvider/Provider_pact_verification
--- PASS: TestHTTPProvider (0.45s)
    --- PASS: TestHTTPProvider/Provider_pact_verification (0.00s)
PASS
Consumer match version is a few message above.
y
can you try with just the MainBranch selector, or provide a PactUrl which would be the published contract
Copy code
View the published pact at <http://127.0.0.1:9292/pacts/provider/provider-service/consumer/consumer-service/version/1.0.0>
c
wow, you are right
having only this all worked:
Copy code
&provider.ConsumerVersionSelector{
				MainBranch: true,
			}
as soon as I add the other 2, it fails again