Hello! Trying to migrate from gitlab ci to github ...
# pactflow
a
Hello! Trying to migrate from gitlab ci to github actions. I used https://github.com/pactflow/example-bi-directional-provider-dredd as a reference (Thank you Pactflow team for that). Sending the provider contract works on local machine but is failing on github with strange error:
Copy code
NoMethodError - undefined method `request_uri' for #<URI::Generic ?>
1
PACT_BROKER_BASE_URL
and
PACT_BROKER_TOKEN
are specified the same way as in the example repo. Don't understand what is failing exactly:
Copy code
PACTICIPANT=ghapi \
""docker run --rm -v /home/runner/work/marketplace-api/marketplace-api:/app -w "/app" -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli"" pactflow publish-provider-contract \
/app/src/test/resources/openapi/swagger.json \
--provider ghapi \
--provider-app-version fefdb4369a5ef60abdfc19ac6edf82aa8d7d6794 \
--branch ci-publish_reports \
--content-type application/json \
--verification-exit-code=0 \
--verification-results /app/target/failsafe-reports/failsafe-summary.xml \
--verification-results-content-type text/xml \
--verifier junit5
m
try adding the
--verbose
flag, that should print out detail about the arguments it received and what requests it’s firing
b
Have you got the “https://” at the start of the base URL?
👍 1
Copy code
$ irb
irb(main):001:0> URI("foo").request_uri
NoMethodError (undefined method `request_uri' for #<URI::Generic foo>)

irb(main):002:0> URI("<https://foo>").request_uri
=> "/"
<URI::Generic ?>
that suggest to me that the PACT_BROKER_BASE_URL env var is empty..
You can see in my example it included the value of the URL in the error
<URI::Generic foo>
m
If it were empty, i’d expect the CLI to tell me I’m missing an important argument - does it not do that?
👍 1
a
Thank you for the suggestions. The output with
--verbose
flag:
Copy code
NoMethodError - undefined method `request_uri' for #<URI::Generic ?>
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/hal/http_client.rb:49:in `create_request'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/hal/http_client.rb:25:in `get'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/hal/link.rb:41:in `get'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/hal/link.rb:45:in `get!'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/hal_client_methods.rb:24:in `index_resource'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/versions/create.rb:48:in `branch_versions_supported?'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/versions/create.rb:11:in `do_call'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/base_command.rb:25:in `call'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/base_command.rb:13:in `call'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pactflow/client/provider_contracts/publish.rb:37:in `create_branch_version_and_tags'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pactflow/client/provider_contracts/publish.rb:24:in `do_call'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/base_command.rb:25:in `call'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/base_command.rb:13:in `call'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pactflow/client/cli/provider_contract_commands.rb:36:in `publish_provider_contract'
/usr/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
/usr/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
/usr/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
/usr/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/lib/pact_broker/client/cli/custom_thor.rb:23:in `start'
/usr/lib/ruby/gems/2.7.0/gems/pact_broker-client-1.64.0/bin/pactflow:4:in `<top (required)>'
/usr/bin/pactflow:25:in `load'
/usr/bin/pactflow:25:in `<main>'
The env vars in github workflow yaml:
Copy code
PACT_BROKER_BASE_URL: <https://mycompany.pactflow.io>
  PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
b
yep, good point Matt. If I give it a blank value, this is what I get.
Copy code
$ PACT_BROKER_BASE_URL="" be bin/pact-broker publish example/scripts/pact.json  --consumer-app-version 1
PactBroker::Client::Error - Please specify the pact_broker_base_url
oh, it’s the provider contract
I can reproduce it
Copy code
export PACT_BROKER_BASE_URL=""
bundle exec bin/pactflow publish-provider-contract  \
  script/oas.yml \
  --provider Foo \
  --provider-app-version 1013b5650d61214e19f10558f97fb5a3bb082d44 \
  --branch main \
  --tag dev \
  --specification oas \
  --content-type application/yml \
  --verification-exit-code 0 \
  --verification-results script/verification-results.txt \
  --verification-results-content-type text/plain \
  --verification-results-format text \
  --verifier my-custom-tool \
  --verifier-version "1.0" \
  --verbose
Copy code
NoMethodError - undefined method `request_uri' for #<URI::Generic ?>
/pact_broker/client/hal/http_client.rb:49:in `create_request'
/pact_broker/client/hal/http_client.rb:25:in `get'
/pact_broker/client/hal/link.rb:41:in `get'
/pact_broker/client/hal/link.rb:45:in `get!'
/pact_broker/client/hal_client_methods.rb:24:in `index_resource'
/pact_broker/client/versions/create.rb:48:in `branch_versions_supported?'
/pact_broker/client/versions/create.rb:11:in `do_call'
/pact_broker/client/base_command.rb:25:in `call'
/pact_broker/client/base_command.rb:13:in `call'
/pactflow/client/provider_contracts/publish.rb:37:in `create_branch_version_and_tags'
/pactflow/client/provider_contracts/publish.rb:24:in `do_call'
/pact_broker/client/base_command.rb:25:in `call'
If I do
unset PACT_BROKER_BASE_URL
then I get an error
No value provided for required options '--broker-base-url'
So, somehow, it looks like it’s going through as an empty string.
m
It’s very easy in YAML to be out by an indentation and for the values to look like they’re there, but actually aren’t present at all. GH should print the environment output (possibly redacted) at the top of the run.
can cast a look over your YAML if you have it
b
I’ve updated the validation for the command.
Copy code
export PACT_BROKER_BASE_URL=""
bundle exec bin/pactflow publish-provider-contract  \
  script/oas.yml \
  --provider Foo \
  --provider-app-version 1013b5650d61214e19f10558f97fb5a3bb082d44 \
  --branch main \
  --tag dev \
  --specification oas \
  --content-type application/yml \
  --verification-exit-code 0 \
  --verification-results script/verification-results.txt \
  --verification-results-content-type text/plain \
  --verification-results-format text \
  --verifier my-custom-tool \
  --verifier-version "1.0" \
  --verbose

No value provided for required option --broker-base-url or environment variable PACT_BROKER_BASE_URL
a
Thank you so much! I found the root cause after adding explicit `echo`s. The problem was in my make file. I have:
Copy code
cp -n .env.example .env || true
So, on github runner it creates an
.env
that looks like:
Copy code
PACT_BROKER_BASE_URL=
PACT_BROKER_TOKEN=
👍 1
😆 1
👍🏼 1
b
thanks for helping me realised I had missed the validation
❤️ 2
a
And this in fact overrides the env variables from workflow file.
m
Glad we got there in the end!
👏 1
a
BTW, all examples on github have
.env
target in the pact related actions: https://github.com/pactflow/example-bi-directional-provider-dredd/blob/master/Makefile#L34 For me it doesn't expose variables from the existing
.env
file on macos. So I ended up adding the snippet on the top of Makefile:
Copy code
# Export all variable to sub-make if .env exists
ifneq (,$(wildcard ./.env))
    include .env
    export
endif
Am I doing it wrong way?