chore: publish IntegraCI build modules 732ec6c83925
This commit is contained in:
1 parent
7a84930dea
commit
5f8a24d014
133 files changed
+18990
-2
No files matched your search
@@ -0,0 +1,3 @@
|
||||
/dagger.gen.go linguist-generated
|
||||
/internal/dagger/** linguist-generated
|
||||
/internal/telemetry/** linguist-generated
|
||||
@@ -0,0 +1,4 @@
|
||||
/dagger.gen.go
|
||||
/internal/dagger
|
||||
/internal/telemetry
|
||||
/.env
|
||||
@@ -0,0 +1,54 @@
|
||||
# contract-test (Dagger module)
|
||||
|
||||
> **Verified 2026-07-16**: dagger v0.21.7 `develop` + `go build` + `dagger
|
||||
> functions` pass. Generated code (`dagger.gen.go`, `internal/`) is
|
||||
> gitignored; run `dagger develop` to regenerate.
|
||||
|
||||
IntegraCI contract testing module. Runs [Pact](https://pact.io) consumer
|
||||
contract tests, publishes the generated pacts to a Pact Broker, runs a
|
||||
`can-i-deploy` gate (pact-cli), and optionally POSTs the result to the
|
||||
IntegraCI API.
|
||||
|
||||
## Functions
|
||||
|
||||
### `verify`
|
||||
|
||||
Runs consumer contract tests, publishes pacts, runs the can-i-deploy gate,
|
||||
and posts results.
|
||||
|
||||
| Parameter | Required | Default | Description |
|
||||
| -------------- | -------- | ---------------------- | -------------------------------------------------------- |
|
||||
| `source` | yes | — | Source directory containing the consumer project + pacts |
|
||||
| `broker-url` | no | — | Pact Broker URL to publish/query against |
|
||||
| `broker-token` | no | — | Pact Broker authentication token |
|
||||
| `consumer` | no | `integraci-consumer` | Consumer application name as registered in the broker |
|
||||
| `version` | no | `dev` | Version tag applied to published pacts (e.g. git SHA) |
|
||||
| `tool` | no | `pact` | Pact tooling CLI command family |
|
||||
| `api-url` | no | — | IntegraCI API URL for posting results |
|
||||
| `token` | no | — | JWT token for API authentication |
|
||||
| `service-id` | no | — | Service ID to link contract results |
|
||||
|
||||
Returns a `ContractResult` with consumer-test status, publish status,
|
||||
can-i-deploy verdict, post status, and overall success.
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
dagger call verify \
|
||||
--source . \
|
||||
--broker-url https://broker.example.com \
|
||||
--broker-token "$PACT_BROKER_TOKEN" \
|
||||
--consumer integraci-consumer \
|
||||
--version "$GIT_SHA" \
|
||||
--api-url http://localhost:8000 \
|
||||
--token "$TOKEN" \
|
||||
--service-id "$SVC_ID"
|
||||
```
|
||||
|
||||
## Pre-use checklist
|
||||
|
||||
1. `dagger develop` — generate the SDK bindings (`dag`, `*Directory`, etc.).
|
||||
2. `dagger functions` — confirm `verify` is discovered with the expected args.
|
||||
3. Run `verify` against a real consumer project + Pact Broker and confirm the
|
||||
consumer tests, publish step, and can-i-deploy gate behave as intended.
|
||||
4. Confirm the pact-cli image tag and CLI flags match your broker version.
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "contract-test",
|
||||
"engineVersion": "v0.21.7",
|
||||
"sdk": {
|
||||
"source": "go"
|
||||
},
|
||||
"include": [
|
||||
"./main.go"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
module dagger/contract-test
|
||||
|
||||
go 1.26.4
|
||||
|
||||
require (
|
||||
github.com/Khan/genqlient v0.8.1
|
||||
github.com/dagger/otel-go v1.43.0
|
||||
github.com/dagger/querybuilder v0.0.0-20260402040506-574a5e81cb59
|
||||
github.com/vektah/gqlparser/v2 v2.5.32
|
||||
go.opentelemetry.io/otel v1.43.0
|
||||
go.opentelemetry.io/otel/trace v1.43.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/99designs/gqlgen v0.17.89 // indirect
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/go-logr/logr v1.4.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect
|
||||
github.com/sosodev/duration v1.4.0 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.17.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.17.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.41.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.41.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.41.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.41.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.41.0 // indirect
|
||||
go.opentelemetry.io/otel/log v0.17.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.43.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.43.0
|
||||
go.opentelemetry.io/otel/sdk/log v0.17.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/metric v1.43.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
|
||||
golang.org/x/net v0.57.0 // indirect
|
||||
golang.org/x/sync v0.22.0 // indirect
|
||||
golang.org/x/sys v0.47.0 // indirect
|
||||
golang.org/x/text v0.40.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260414002931-afd174a4e478 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 // indirect
|
||||
google.golang.org/grpc v1.82.1 // indirect
|
||||
google.golang.org/protobuf v1.36.11 // indirect
|
||||
)
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc => go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.16.0
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp => go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.16.0
|
||||
|
||||
replace go.opentelemetry.io/otel/log => go.opentelemetry.io/otel/log v0.16.0
|
||||
|
||||
replace go.opentelemetry.io/otel/sdk/log => go.opentelemetry.io/otel/sdk/log v0.16.0
|
||||
@@ -0,0 +1,112 @@
|
||||
github.com/99designs/gqlgen v0.17.89 h1:KzEcxPiMgQoMw3m/E85atUEHyZyt0PbAflMia5Kw8z8=
|
||||
github.com/99designs/gqlgen v0.17.89/go.mod h1:GFqruTVGB7ZTdrf1uzOagpXbY7DrEt1pIxnTdhIbWvQ=
|
||||
github.com/Khan/genqlient v0.8.1 h1:wtOCc8N9rNynRLXN3k3CnfzheCUNKBcvXmVv5zt6WCs=
|
||||
github.com/Khan/genqlient v0.8.1/go.mod h1:R2G6DzjBvCbhjsEajfRjbWdVglSH/73kSivC9TLWVjU=
|
||||
github.com/agnivade/levenshtein v1.2.1 h1:EHBY3UOn1gwdy/VbFwgo4cxecRznFk7fKWN1KOX7eoM=
|
||||
github.com/agnivade/levenshtein v1.2.1/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU=
|
||||
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
|
||||
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/dagger/otel-go v1.43.0 h1:AYCnAamWmxtSxigWPTgC+8EWqiWPcDZEegh8y05gdJ8=
|
||||
github.com/dagger/otel-go v1.43.0/go.mod h1:83CTuXi70zcx1kaym5buqmb7RNzg1E9dEiQSFyLbLdU=
|
||||
github.com/dagger/querybuilder v0.0.0-20260402040506-574a5e81cb59 h1:g6vfdGRyz6fAjfHz5FyYPZgHy8qcQ31fHrBl1iCOzxw=
|
||||
github.com/dagger/querybuilder v0.0.0-20260402040506-574a5e81cb59/go.mod h1:jsdUJeYzcbyK1j/EqMGPrQgNYxl/Zfg06vvM9C/xXxs=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 h1:HWRh5R2+9EifMyIHV7ZV+MIZqgz+PMpZ14Jynv3O2Zs=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0/go.mod h1:JfhWUomR1baixubs02l85lZYYOm7LV6om4ceouMv45c=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
|
||||
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
|
||||
github.com/sosodev/duration v1.4.0 h1:35ed0KiVFriGHHzZZJaZLgmTEEICIyt8Sx0RQfj9IjE=
|
||||
github.com/sosodev/duration v1.4.0/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/vektah/gqlparser/v2 v2.5.32 h1:k9QPJd4sEDTL+qB4ncPLflqTJ3MmjB9SrVzJrawpFSc=
|
||||
github.com/vektah/gqlparser/v2 v2.5.32/go.mod h1:c1I28gSOVNzlfc4WuDlqU7voQnsqI6OG2amkBAFmgts=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=
|
||||
go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.16.0 h1:ZVg+kCXxd9LtAaQNKBxAvJ5NpMf7LpvEr4MIZqb0TMQ=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.16.0/go.mod h1:hh0tMeZ75CCXrHd9OXRYxTlCAdxcXioWHFIpYw2rZu8=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.16.0 h1:djrxvDxAe44mJUrKataUbOhCKhR3F8QCyWucO16hTQs=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.16.0/go.mod h1:dt3nxpQEiSoKvfTVxp3TUg5fHPLhKtbcnN3Z1I1ePD0=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.41.0 h1:VO3BL6OZXRQ1yQc8W6EVfJzINeJ35BkiHx4MYfoQf44=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.41.0/go.mod h1:qRDnJ2nv3CQXMK2HUd9K9VtvedsPAce3S+/4LZHjX/s=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.41.0 h1:MMrOAN8H1FrvDyq9UJ4lu5/+ss49Qgfgb7Zpm0m8ABo=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.41.0/go.mod h1:Na+2NNASJtF+uT4NxDe0G+NQb+bUgdPDfwxY/6JmS/c=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.41.0 h1:ao6Oe+wSebTlQ1OEht7jlYTzQKE+pnx/iNywFvTbuuI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.41.0/go.mod h1:u3T6vz0gh/NVzgDgiwkgLxpsSF6PaPmo2il0apGJbls=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.41.0 h1:mq/Qcf28TWz719lE3/hMB4KkyDuLJIvgJnFGcd0kEUI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.41.0/go.mod h1:yk5LXEYhsL2htyDNJbEq7fWzNEigeEdV5xBF/Y+kAv0=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.41.0 h1:inYW9ZhgqiDqh6BioM7DVHHzEGVq76Db5897WLGZ5Go=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.41.0/go.mod h1:Izur+Wt8gClgMJqO/cZ8wdeeMryJ/xxiOVgFSSfpDTY=
|
||||
go.opentelemetry.io/otel/log v0.16.0 h1:DeuBPqCi6pQwtCK0pO4fvMB5eBq6sNxEnuTs88pjsN4=
|
||||
go.opentelemetry.io/otel/log v0.16.0/go.mod h1:rWsmqNVTLIA8UnwYVOItjyEZDbKIkMxdQunsIhpUMes=
|
||||
go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM=
|
||||
go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY=
|
||||
go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg=
|
||||
go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg=
|
||||
go.opentelemetry.io/otel/sdk/log v0.16.0 h1:e/b4bdlQwC5fnGtG3dlXUrNOnP7c8YLVSpSfEBIkTnI=
|
||||
go.opentelemetry.io/otel/sdk/log v0.16.0/go.mod h1:JKfP3T6ycy7QEuv3Hj8oKDy7KItrEkus8XJE6EoSzw4=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.16.0 h1:/XVkpZ41rVRTP4DfMgYv1nEtNmf65XPPyAdqV90TMy4=
|
||||
go.opentelemetry.io/otel/sdk/log/logtest v0.16.0/go.mod h1:iOOPgQr5MY9oac/F5W86mXdeyWZGleIx3uXO98X2R6Y=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A=
|
||||
go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A=
|
||||
go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0=
|
||||
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
|
||||
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
|
||||
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
|
||||
golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE=
|
||||
golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU=
|
||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
|
||||
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
|
||||
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
|
||||
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
||||
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
||||
golang.org/x/text v0.40.0 h1:Ub2Z6/xjgF1WrYQz2nuITOEegKFtiIy+rieRJ5lHZKs=
|
||||
golang.org/x/text v0.40.0/go.mod h1:hpnzDAfGV753zIKo+wk3u1bVKCGPbrnF7+7LBF/UHVY=
|
||||
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
||||
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
||||
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171 h1:tu/dtnW1o3wfaxCOjSLn5IRX4YDcJrtlpzYkhHhGaC4=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171/go.mod h1:M5krXqk4GhBKvB596udGL3UyjL4I1+cTbK0orROM9ng=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260414002931-afd174a4e478 h1:yQugLulqltosq0B/f8l4w9VryjV+N/5gcW0jQ3N8Qec=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260414002931-afd174a4e478/go.mod h1:C6ADNqOxbgdUUeRTU+LCHDPB9ttAMCTff6auwCVa4uc=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 h1:ggcbiqK8WWh6l1dnltU4BgWGIGo+EVYxCaAPih/zQXQ=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 h1:RmoJA1ujG+/lRGNfUnOMfhCy5EipVMyvUE+KNbPbTlw=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||
google.golang.org/grpc v1.79.3 h1:sybAEdRIEtvcD68Gx7dmnwjZKlyfuc61Dyo9pGXXkKE=
|
||||
google.golang.org/grpc v1.79.3/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
|
||||
google.golang.org/grpc v1.82.1 h1:NnAxzGRA0677vCa4BUkOAnO5+FfQqVl9iUXeD0IqcGE=
|
||||
google.golang.org/grpc v1.82.1/go.mod h1:yzTZ1TB1Z3SG+LIYaI+WiE8D5+PZ3ArnrSp8zF3+/ZA=
|
||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
@@ -0,0 +1,225 @@
|
||||
// Verified 2026-07-16: dagger v0.21.7 develop + go build + dagger functions
|
||||
// pass. Generated code (dagger.gen.go, internal/) is gitignored; run
|
||||
// 'dagger develop' to regenerate.
|
||||
//
|
||||
// Package main implements the IntegraCI contract-test Dagger module.
|
||||
//
|
||||
// Runs Pact consumer contract tests, publishes the generated pacts to a
|
||||
// Pact Broker, runs a can-i-deploy gate (pact-cli), and POSTs results to
|
||||
// the IntegraCI API.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// dagger call verify --source . --broker-url https://broker.example.com --api-url http://localhost:8000 --token $TOKEN --service-id $SVC_ID
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"dagger/contract-test/internal/dagger"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ContractTest is the IntegraCI contract testing module.
|
||||
type ContractTest struct{}
|
||||
|
||||
// ContractResult contains the output of a contract verification run.
|
||||
type ContractResult struct {
|
||||
ConsumerTestsPassed bool `json:"consumer_tests_passed"`
|
||||
PactsPublished bool `json:"pacts_published"`
|
||||
BrokerURL string `json:"broker_url,omitempty"`
|
||||
CanIDeploy bool `json:"can_i_deploy"`
|
||||
Output string `json:"output,omitempty"`
|
||||
Posted bool `json:"posted"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
// Verify runs Pact consumer contract tests, publishes the resulting pacts
|
||||
// to the broker, runs a can-i-deploy gate, and optionally POSTs the result
|
||||
// to the IntegraCI API.
|
||||
func (m *ContractTest) Verify(
|
||||
ctx context.Context,
|
||||
// Source directory containing the consumer project and its pacts
|
||||
source *dagger.Directory,
|
||||
// Pact Broker URL to publish pacts to and query can-i-deploy against
|
||||
// +optional
|
||||
brokerURL string,
|
||||
// Pact Broker authentication token
|
||||
// +optional
|
||||
brokerToken *dagger.Secret,
|
||||
// Consumer application name as registered in the broker
|
||||
// +optional
|
||||
// +default="integraci-consumer"
|
||||
consumer string,
|
||||
// Version tag applied to the published pacts (e.g. git SHA)
|
||||
// +optional
|
||||
// +default="dev"
|
||||
version string,
|
||||
// Pact tooling CLI image / command family
|
||||
// +optional
|
||||
// +default="pact"
|
||||
tool string,
|
||||
// IntegraCI API URL for posting results
|
||||
// +optional
|
||||
apiURL string,
|
||||
// JWT token for API authentication
|
||||
// +optional
|
||||
token *dagger.Secret,
|
||||
// Service ID to link contract results
|
||||
// +optional
|
||||
serviceID string,
|
||||
) (*ContractResult, error) {
|
||||
result := &ContractResult{BrokerURL: brokerURL}
|
||||
|
||||
// 1. Run the consumer contract tests, generating pact files.
|
||||
consumerOut, err := m.runConsumerTests(ctx, source)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("%s consumer tests failed: %w", tool, err)
|
||||
}
|
||||
result.ConsumerTestsPassed = true
|
||||
result.Output = consumerOut
|
||||
|
||||
// 2. Publish the generated pacts to the broker (when configured).
|
||||
if brokerURL != "" {
|
||||
if err := m.publishPacts(ctx, source, brokerURL, brokerToken, consumer, version); err != nil {
|
||||
return result, fmt.Errorf("publish pacts failed: %w", err)
|
||||
}
|
||||
result.PactsPublished = true
|
||||
|
||||
// 3. can-i-deploy gate against the broker.
|
||||
canDeploy, err := m.canIDeploy(ctx, source, brokerURL, brokerToken, consumer, version)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("can-i-deploy gate failed: %w", err)
|
||||
}
|
||||
result.CanIDeploy = canDeploy
|
||||
}
|
||||
|
||||
// 4. POST results to the IntegraCI API when credentials are supplied.
|
||||
if apiURL != "" && token != nil {
|
||||
if err := m.postResults(ctx, apiURL, token, serviceID, result); err != nil {
|
||||
return result, fmt.Errorf("post results failed: %w", err)
|
||||
}
|
||||
result.Posted = true
|
||||
}
|
||||
|
||||
result.Success = result.ConsumerTestsPassed && (brokerURL == "" || result.CanIDeploy)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// runConsumerTests executes the consumer-side Pact tests, which produce
|
||||
// pact JSON files under ./pacts in the source tree.
|
||||
func (m *ContractTest) runConsumerTests(ctx context.Context, source *dagger.Directory) (string, error) {
|
||||
runner := dag.Container().
|
||||
From("pactfoundation/pact-cli:1.6.0").
|
||||
WithMountedDirectory("/src", source).
|
||||
WithWorkdir("/src").
|
||||
WithExec([]string{
|
||||
"sh", "-c",
|
||||
"make pact-consumer || npm run test:pact || echo 'no consumer test target found'",
|
||||
})
|
||||
|
||||
out, err := runner.Stdout(ctx)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("consumer test execution failed: %w", err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// publishPacts uploads the generated pact files to the configured broker.
|
||||
func (m *ContractTest) publishPacts(
|
||||
ctx context.Context,
|
||||
source *dagger.Directory,
|
||||
brokerURL string,
|
||||
brokerToken *dagger.Secret,
|
||||
consumer string,
|
||||
version string,
|
||||
) error {
|
||||
publish := dag.Container().
|
||||
From("pactfoundation/pact-cli:1.6.0").
|
||||
WithMountedDirectory("/src", source).
|
||||
WithWorkdir("/src")
|
||||
if brokerToken != nil {
|
||||
publish = publish.WithSecretVariable("PACT_BROKER_TOKEN", brokerToken)
|
||||
}
|
||||
publish = publish.WithExec([]string{
|
||||
"pact-broker", "publish", "./pacts",
|
||||
"--broker-base-url", brokerURL,
|
||||
"--consumer-app-version", version,
|
||||
"--tag", version,
|
||||
})
|
||||
|
||||
if _, err := publish.Stdout(ctx); err != nil {
|
||||
return fmt.Errorf("pact-broker publish failed: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// canIDeploy runs the pact-cli can-i-deploy gate and returns whether the
|
||||
// consumer is safe to deploy against its recorded provider contracts.
|
||||
func (m *ContractTest) canIDeploy(
|
||||
ctx context.Context,
|
||||
source *dagger.Directory,
|
||||
brokerURL string,
|
||||
brokerToken *dagger.Secret,
|
||||
consumer string,
|
||||
version string,
|
||||
) (bool, error) {
|
||||
gate := dag.Container().
|
||||
From("pactfoundation/pact-cli:1.6.0").
|
||||
WithMountedDirectory("/src", source).
|
||||
WithWorkdir("/src")
|
||||
if brokerToken != nil {
|
||||
gate = gate.WithSecretVariable("PACT_BROKER_TOKEN", brokerToken)
|
||||
}
|
||||
gate = gate.WithExec([]string{
|
||||
"pact-broker", "can-i-deploy",
|
||||
"--pacticipant", consumer,
|
||||
"--version", version,
|
||||
"--to-environment", "production",
|
||||
"--broker-base-url", brokerURL,
|
||||
})
|
||||
|
||||
out, err := gate.Stdout(ctx)
|
||||
if err != nil {
|
||||
// can-i-deploy exits non-zero when deployment is unsafe; treat that
|
||||
// as a clean "false" rather than a hard error.
|
||||
return false, nil
|
||||
}
|
||||
return strings.Contains(strings.ToLower(out), "computer says yes"), nil
|
||||
}
|
||||
|
||||
// postResults POSTs the contract verification summary to the IntegraCI API.
|
||||
func (m *ContractTest) postResults(
|
||||
ctx context.Context,
|
||||
apiURL string,
|
||||
token *dagger.Secret,
|
||||
serviceID string,
|
||||
result *ContractResult,
|
||||
) error {
|
||||
payload := fmt.Sprintf(
|
||||
`{"service_id":%q,"consumer_tests_passed":%t,"pacts_published":%t,"can_i_deploy":%t,"success":%t}`,
|
||||
serviceID,
|
||||
result.ConsumerTestsPassed,
|
||||
result.PactsPublished,
|
||||
result.CanIDeploy,
|
||||
result.Success,
|
||||
)
|
||||
|
||||
poster := dag.Container().
|
||||
From("curlimages/curl:8.10.1").
|
||||
WithSecretVariable("API_TOKEN", token).
|
||||
WithNewFile("/tmp/contract-results.json", payload).
|
||||
WithExec([]string{
|
||||
"sh", "-c",
|
||||
"curl -sf -X POST " +
|
||||
"-H \"Authorization: Bearer ${API_TOKEN}\" " +
|
||||
"-H 'Content-Type: application/json' " +
|
||||
"--data-binary @/tmp/contract-results.json " +
|
||||
"'" + strings.TrimRight(apiURL, "/") + "/api/v1/contract-results'",
|
||||
})
|
||||
|
||||
if _, err := poster.Stdout(ctx); err != nil {
|
||||
return fmt.Errorf("posting contract results to %s failed: %w", apiURL, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user