Skip to content

Instantly share code, notes, and snippets.

@q-ode
Created July 26, 2019 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save q-ode/76e92e169c0ceff38c6f526ce10e6262 to your computer and use it in GitHub Desktop.
Save q-ode/76e92e169c0ceff38c6f526ce10e6262 to your computer and use it in GitHub Desktop.
Sample Broker Publishing
const fs = require('fs');
const pact = require('@pact-foundation/pact-node');
const path = require('path');
// Modify as required
const pactBroker = process.env.PACT_BROKER;
const pactBrokerToken = process.env.PACT_BROKER_TOKEN;
const gitBranch = process.env.CIRCLE_BRANCH;
const gitCommitHash = process.env.CIRCLE_SHA1;
const pactsDirectory = path.resolve(process.cwd(), '.contracts');
if (
fs.existsSync(pactsDirectory) &&
fs.readdirSync(pactsDirectory).length > 0
) {
pact
.publishPacts({
pactBroker,
pactBrokerToken,
pactFilesOrDirs: [pactsDirectory],
consumerVersion: gitCommitHash,
tags: [gitBranch],
})
.then(res => console.log(res));
} else {
console.info('No Pacts available to be Published');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment