Skip to content

Commit

Permalink
Merge pull request #1188 from alphagov/pact-artifacts
Browse files Browse the repository at this point in the history
Fix for CI builds failing on pact tests for Dependabot
  • Loading branch information
brucebolt authored Feb 3, 2023
2 parents c907f29 + 88ceaaf commit b5e4bf6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 35 deletions.
95 changes: 69 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,88 +34,131 @@ jobs:
steps:
- run: echo "All matrix tests have passed 🚀"

generate_and_publish_pacts:
generate_pacts:
needs: test
runs-on: ubuntu-latest
env:
PACT_TARGET_BRANCH: branch-${{ github.ref_name }}
PACT_BROKER_BASE_URL: https://pact-broker.cloudapps.digital
PACT_BROKER_USERNAME: ${{ secrets.GOVUK_PACT_BROKER_USERNAME }}
PACT_BROKER_PASSWORD: ${{ secrets.GOVUK_PACT_BROKER_PASSWORD }}
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bundle exec rake pact_test
- run: bundle exec rake pact:publish:branch
- uses: actions/upload-artifact@v3
with:
name: pacts
path: spec/pacts/*.json

account_api_pact:
needs: generate_and_publish_pacts
needs: generate_pacts
uses: alphagov/account-api/.github/workflows/pact-verify.yml@main
with:
pact_consumer_version: branch-${{ github.ref_name }}
pact_artifact: pacts

asset_manager_pact:
needs: generate_and_publish_pacts
needs: generate_pacts
uses: alphagov/asset-manager/.github/workflows/pact-verify.yml@main
with:
pact_consumer_version: branch-${{ github.ref_name }}
pact_artifact: pacts

collections_pact:
needs: generate_and_publish_pacts
needs: generate_pacts
uses: alphagov/collections/.github/workflows/pact-verify.yml@main
with:
pact_consumer_version: branch-${{ github.ref_name }}
pact_artifact: pacts

email_alert_api_pact:
needs: generate_and_publish_pacts
needs: generate_pacts
uses: alphagov/email-alert-api/.github/workflows/pact-verify.yml@main
with:
pact_consumer_version: branch-${{ github.ref_name }}
pact_artifact: pacts

frontend_pact:
needs: generate_pacts
uses: alphagov/frontend/.github/workflows/pact-verify.yml@main
with:
pact_artifact: pacts

imminence_pact:
needs: generate_and_publish_pacts
needs: generate_pacts
uses: alphagov/imminence/.github/workflows/pact-verify.yml@main
with:
pact_consumer_version: branch-${{ github.ref_name }}
pact_artifact: pacts

link_checker_api_pact:
needs: generate_and_publish_pacts
needs: generate_pacts
uses: alphagov/link-checker-api/.github/workflows/pact-verify.yml@main
with:
pact_consumer_version: branch-${{ github.ref_name }}
pact_artifact: pacts

locations_api_pact:
needs: generate_and_publish_pacts
needs: generate_pacts
uses: alphagov/locations-api/.github/workflows/pact-verify.yml@main
with:
pact_consumer_version: branch-${{ github.ref_name }}
pact_artifact: pacts

publishing_api_pact:
needs: generate_and_publish_pacts
needs: generate_pacts
uses: alphagov/publishing-api/.github/workflows/pact-verify.yml@main
with:
pact_consumer_version: branch-${{ github.ref_name }}
pact_artifact: pacts

whitehall_pact:
needs: generate_and_publish_pacts
needs: generate_pacts
uses: alphagov/whitehall/.github/workflows/pact-verify.yml@main
with:
pact_consumer_version: branch-${{ github.ref_name }}
pact_artifact: pacts

publish_gem:
publish_pacts:
needs:
- account_api_pact
- asset_manager_pact
- collections_pact
- email_alert_api_pact
- frontend_pact
- imminence_pact
- link_checker_api_pact
- locations_api_pact
- publishing_api_pact
- whitehall_pact
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- uses: actions/download-artifact@v3
with:
name: pacts
path: tmp/pacts
- run: bundle exec rake pact:publish
env:
PACT_CONSUMER_VERSION: branch-${{ github.ref_name }}
PACT_BROKER_BASE_URL: https://pact-broker.cloudapps.digital
PACT_BROKER_USERNAME: ${{ secrets.GOVUK_PACT_BROKER_USERNAME }}
PACT_BROKER_PASSWORD: ${{ secrets.GOVUK_PACT_BROKER_PASSWORD }}
PACT_PATTERN: tmp/pacts/*.json

# We don't use the artifact outside of sharing it for jobs so delete it
# at the end of the flow.
delete_pact_artifact:
needs:
- generate_pacts
- publish_pacts
# Run whenever generate_pacts is a success but wait until publish_pacts
# is either ran or skipped to ensure all work with the artifact is complete
if: ${{ always() && needs.generate_pacts.result == 'success' }}
runs-on: ubuntu-latest
steps:
# As of Jan 2023, GitHub doesn't provide a delete artifact equivalent to
# their upload / download ones
- uses: geekyeggo/delete-artifact@v2
with:
name: pacts

publish_gem:
needs: publish_pacts
if: ${{ github.ref == 'refs/heads/main' }}
permissions:
contents: write
uses: alphagov/govuk-infrastructure/.github/workflows/publish-rubygem.yml@main
Expand Down
16 changes: 7 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ task default: %i[lint test]

require "pact_broker/client/tasks"

def configure_pact_broker_location(task)
PactBroker::Client::PublicationTask.new do |task|
task.consumer_version = ENV.fetch("PACT_CONSUMER_VERSION")
task.pact_broker_base_url = ENV.fetch("PACT_BROKER_BASE_URL")
if ENV["PACT_BROKER_USERNAME"]
task.pact_broker_basic_auth = { username: ENV["PACT_BROKER_USERNAME"], password: ENV["PACT_BROKER_PASSWORD"] }
end
end

PactBroker::Client::PublicationTask.new("branch") do |task|
task.consumer_version = ENV.fetch("PACT_TARGET_BRANCH")
configure_pact_broker_location(task)
task.pact_broker_basic_auth = {
username: ENV.fetch("PACT_BROKER_USERNAME"),
password: ENV.fetch("PACT_BROKER_PASSWORD"),
}
task.pattern = ENV["PACT_PATTERN"] if ENV["PACT_PATTERN"]
end

desc "Run the linter against changed files"
Expand Down

0 comments on commit b5e4bf6

Please sign in to comment.