Is there a way to specify to use a specific consum...
# general
k
Is there a way to specify to use a specific consumerVersionNumber with consumer-version-selectors? The docs do not mention it. If not, shouldn't there be? + What would the recommended workaround be (use tags/branch names instead)?
y
there isn’t and you should use the recommendations on the page. why do you want to specify a specific version
deployedOrReleased and mainBranch true, along with enable pending and include wip pacts if prob the best config alongside a triggered provider job when runs when a consumer contract changes
k
Because I assume consumerVersionNumber to be the most specific identification of a contract version, instead of relying on branch with latest and/or tags.
What is the recommended approach here though? The use-case this is for is for MR/branch verification. I.e. a consumer creates a new contract in a branch/MR, uploads the contract and providers are supposed to pull exactly this version for verificaton and then upload the results so consumers know with can-i-deploy if this is cool or not
y
there are two verifications when consumer changes contract - the provider is provided the version when a consumer pact changes and runs a verification via webhooks https://docs.pact.io/pact_nirvana/step_6 or the provider commits - the provider uses consumer version selectors. they use named selectors, so they don’t have to be aware of the underlying version, which may change (the provider doesn’t need to aware of the exact contract version on main branch, or deployed or released versions, as the broker would provide those pacts via the consumer version selectors)
k
So when the consumer changes contract, the provider is provided the version how? We currently use webhook to trigger provider verification, but without telling the provider what version exactly to pull for verification, it pulls something wrong/different, hence we were thinking to tell the provider which version exactly to pull for verification via the consumerVersionNumber, but if this is not possible I am unsure how to tell the provider exactly what version/contract needs to be verified and hence asking for the recommended alternative approach
y
recommend webhook approach is this event, showing the versions on the contract it will trigger when a consumer contract is published https://docs.pact.io/pact_broker/webhooks#using-webhooks-with-the-contract_requiring_verification_published-event which webhook are you using? You can see the recommended ci/cd workflow in action via this demo set https://docs.pactflow.io/docs/workshops/ci-cd/
We currently use webhook to trigger provider verification, but without telling the provider what version exactly to pull for verification, it pulls something wrong/different,
It’s probably worth providing detail on this issue, rather than looking into workarounds at the moment
k
which webhook are you using?
Not sure how to answer this. Is there different flavors/ways of webhooks on pactflow.io? Let me know what details I can provide to answer it
It’s probably worth providing detail on this issue, rather than looking into workarounds at the moment
What details would you like me to provide?
y
1. which webhook are you using https://docs.pact.io/pact_broker/webhooks#the-contract-content-changed-event or https://docs.pact.io/pact_broker/webhooks#the-contract-requiring-verification-published-event 2. Why do you think the below is the case. What is your expectation, and how is your system setup. Are you publishing with branches/tags? Are you recording deployments/releases to environments > We currently use webhook to trigger provider verification, but without telling the provider what version exactly to pull for verification, it pulls something wrong/different, The fact you’ve mentioned that is key to your original question, which I believe to be an XY problem, you are asking you solve Y, but your problem is X (probably a misconfiguration or misunderstanding of webhooks)
k
For 1 I assume we are using the "contract published"-webhook event? (see screenshot)? On 2: Because we can see from the provider verification logs that it pull a different version than expected. See 2nd screenshot XY may be the case, I unfortunately did not set this up and am trying to make sense of it 😄
😅 1
y
c3ff556
looks correct, it is the short sha for the published version. the verification task, should be provided the URL of the pact that has changed, it looks like from your logs that its retrieving two pacts. You shouldn’t provide consumer version selectors, when you provide a pact url driven by a webhook
XY may be the case, I unfortunately did not set this up and am trying to make sense of it
No worries, I can appreciate that! We can definitely try and help
btw it doesn’t show that you are using the webhook pact url value, in your provider verification task, which is why you aren’t triggering a verification against the correct pact per sai
in the CI job, we read the PACT_URL from the webhook https://github.com/pactflow/example-provider/blob/594529a11b188f55d6dc86d95355f8a9[…].github/workflows/contract_requiring_verification_published.yml and use this in our verification task. optionally if you use the newer webhook, you get a provider sha, for deployed/released and main versions of the provider, retrieved in line 21 and checks out the provider code in line 36
k
c3ff556
looks correct
It just does out of coincidence, but usually does not
btw it doesn’t show that you are using the webhook pact url value, in your provider verification task, which is why you aren’t triggering a verification against the correct pact per sai
Maybe that is the problem then? I do not see any reference/usage of the PACT_URL, so should we update our webhooks to include the pactUrl in the body and then during verification set the env var PACT_URL to its value in order to assure that the correct version is pulled and verified? I just noticed that pact_urls are marked as deprecated? Is that so or am I misunderstanding something (See screenshot)?
No worries, I can appreciate that! We can definitely try and help
Thank you very much. I appreciate it 😊
y
ahhh okay, thanks for the screenshot that is helpful is tracing down which tool you are using It looks like that is from the python wrapper around the pact ruby cli https://github.com/pact-foundation/pact-python/blob/f02ea24321f41ea752512a2aec83350f96ebc7a1/pact/cli/verify.py#L134 I believe it is wrapping this ruby based verifier and I am not sure why it is stating those opts are deprecated elmo shrug https://github.com/pact-foundation/pact-provider-verifier as part of this standalone bundle https://github.com/pact-foundation/pact-ruby-standalone it actually forms part of our legacy pact core, written in ruby and only supports up to v2 of the pact specification. https://docs.pact.io/diagrams/ecosystem#ruby-goldberg-machine You may find that using the verifier directly rather than using via the python wrapper should provide a more up to date experience. The libraries have mainly moved over to the pact rust core https://docs.pact.io/diagrams/ecosystem#rust-goldberg-machine of which there is a standalone verifier cli which supports up to v4 of the pact specification. https://github.com/pact-foundation/pact-reference/tree/master/rust/pact_verifier_cli
oh btw the python wrapper states for the depration notice
specify pacts as arguments instead
which makes sense, as the ruby verifier takes the pacts as args, rather than a separate option
so just pop them at the start of the command, the full url from the webhook
btw sorry that is probably loads of information 🙂
😅 1
k
Using it from the env (PACT_URL) should still work though, is that what your saying?
y
I can’t see anything that will read the PACT_URL from an env var, you will need to pass the value from webhook, and pass that into the command to the verifier so something like, assume PACT_URL is populated with the value from the webhook
Copy code
pact-verifier
${PACT_URL}
--hostname=app
...other opts
or
Copy code
pact-verifier
--hostname=app
--pact-url=${PACT_URL}
...other opts
Even though it is marked as deprecated the code is still in place to read from the pact-url arg.
k
I just double checked to be safe and it seems this is what we are using on CI: Does that make sense?
thank you 1
It mentioned something about the standalone version here:
y
so that is a newer rust based verifier, the newest being here https://github.com/pact-foundation/pact-reference/releases/tag/pact_verifier_cli-v1.0.3 Your version appears to be this https://github.com/pact-foundation/pact-reference/releases/tag/pact_verifier_cli-v0.10.6 it looks to have renamed provider-verifier, has it comes as pact_verifier_cli in the tar.gz
k
So does that mean we can set the env var PACT_URL accordingly?
y
it takes the option
--url
which you can repeat it there are multiple. map that value to the url from the webhook
👍 1
k
Cool, let me try that
Thank you so far