bit of a general question: what’s the best strateg...
# general
u
bit of a general question: what’s the best strategy to select consumer versions? I’m thinking of a two step process: 1) verify all branches (this job doesn’t block roll out CI pipelines since it could very well fail a bunch of contracts) 2) verify deployed/latest-main-branch (this one does block a provider branch since a roll out with a red job here means breakages)
m
WIP and Pending Pacts enables you to do both in the same step. You could separate them out if that’s easier though
or the CI/CD workshop 👇 (howtolearn)
👀 1
s
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops
t
verify all branches
You might want "verify all contracts under a certain age", plus main + deployed
(this one does block a provider branch since a roll out with a red job here means breakages)
You don't actually have to block the build. You just have to block deploy.
u
yes, that’s what I meant, block deployments, not the build
this problem stems mostly from the fact that we can’t do webhooks (networking security stuff); otherwise we’d have a way of verifying with a branch name coming from the env for instance
👍 1
in the guides/workshops I couldn’t find/see where exactly one can configure the pact selector to include all consumer versions (perhaps only check latest of every version), would you mind pointing me to the docs for this? Additionally, I was reading about the pending pacts features, but I’m unsure that’s what I want
Copy code
While the provider build may pass, the verification results are still reported (if results publishing is enabled) to the Pact Broker as "failed", as the consumer should not be able to deploy the code that generated this contract.
wait, maybe it is exactly what I want
I want in my CI/CD to only fail if mainbranch/deployed contracts can’t be verified, everything else I’m happy to just publish the result
ok, it seems I’m not quite understanding how to go about this. I enabled
pending=true
like so
Copy code
enablePendingPacts = "true", providerBranch = "master"
for pact-jvm, and then I ran my provider tests. I know there’s a consumer branch for consumer X with contracts that can’t be successfully verified (for various reasons), however it still didn’t pick up those contracts during the run. Re-reading the docs for
pending
it seems that all this does is for the main branch/deployed allow for failure in cases when the consumer pushed to their main branch/deployed contracts that can’t be verified. And the point is to not block the provider from rolling out. This is good stuff if I got it right, but it doesn’t address my issue of “publish verifications for all contracts out there”.
@Timothy Jones you said “You might want “verify all contracts under a certain age”, plus main + deployed (edited)“, and this sounds about right. How is this achieved? And with pact-jvm, do you know?
I just ran my provider tests with
includeWipPactsSince = "2023-01-01"
, and it seems like this did the trick
👍 2
the result was, in my IDE: 1) contracts for the branch I wasn’t verifying before were included in the run 2) the result of the tests was still
PASS
in the IDE 3) I didn’t publish because IDE but I am hopeful that when this runs in CI/CD a
failed
result will be published
1
t
I believe that’s correct, although I thought the JUnit runner showed skipped for the tests that were failing. It might depend on the runner, I’m not sure.
🤔 1
I think you might need wip pacts too? To be honest I’ve never fully understood how pending works. I believe the answers are in the CI/CD workshop linked off the pending page, but I didn’t want to do a workshop when I last needed to know.
I think pending just means that a contract that has never passed is allowed to fail.
WIP pacts are here
It looks like the documentation is better than when I last looked 🙌
I just re-read your last message. It sounds like you got it to work!
u
I think so. Thanks for your confirmation. The issue might also lie on the consumer’s side of things (they’re not versioning things correctly I suspect which is making this more difficult than it needs to be).
thanks for your patience 🙂
m
What confuses most people is that pending and WIP are relative to the provider version doing the verifying. It’s worth reading the two pages I linked above to fully appreciate the differences (https://pact-foundation.slack.com/archives/C5F4KFKR8/p1687210727448039?thread_ts=1687182566.153459&cid=C5F4KFKR8) But I think with those selectors, you will mostly be able to mitigate the lack of webhooks. You could potentially even run them on a schedule, to help “sweep up” the new consumer contracts that have come through as a sort of poor man’s webhook
u
that’s sort of my intention: we have enough merges to the main branch (daily) to not even need a cron job of sorts; this is why I wanted to run things in 2 stages (just reiterating): 1) verify all consumer contracts (maybe only latest of each); this job fails nothing, it just publishes results, this is the workaround the lack of webhooks and 2) verify main-branch/released/deployed for all consumers; this job if it fails blocks roll outs
👍 1
this problem stems mostly from the fact that we can’t do webhooks (networking security stuff); otherwise we’d have a way of verifying with a branch name coming from the env for instance
An alternative is for us to have a CI job that takes the branch+consumer name from an env var, and we ask consumers to trigger this job after their publish-contracts job. It’s a bit like webhooks except we don’t go via the broker.
👍 1
m
You could possibly even query the PactFlow APIs here to dynamically determine what jobs to trigger (i.e. discover the collaborators), but I can see why you wouldn’t want to get too complicated
t
Yep. I've done it with pipeline rules before, but it didn't feel super maintainable
1
u
nod hmm yes unsure this is easily maintainable; we’d have to keep track of API changes for instance (even if they’re far in between, at some point they might break, and then I moved to another team, etc.)