-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.ts
33 lines (29 loc) · 1.22 KB
/
publish.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { Publisher } = require('@pact-foundation/pact');
const path = require('path');
const childProcess = require('child_process');
require('dotenv').config();
const exec = (command: any) => childProcess.execSync(command).toString().trim();
// Usually, you would just use the CI env vars, but to allow these examples to run from
// local development machines, we'll fall back to the git command when the env vars aren't set.
// TODO: Update these for your particular CI server
const gitSha = process.env.TRAVIS_COMMIT || exec('git rev-parse HEAD || echo LOCAL_DEV');
// const branch =
// process.env.TRAVIS_BRANCH || exec("git rev-parse --abbrev-ref HEAD || echo LOCAL_DEV");
const branch = 'master';
const opts = {
pactFilesOrDirs: [path.resolve(process.cwd(), 'pact/pacts')],
pactBroker: process.env.PACTFLOW_BROKER_URL,
pactBrokerToken: process.env.PACTFLOW_TOKEN,
consumerVersion: gitSha,
tags: [branch],
};
new Publisher(opts)
.publishPacts()
.then(() => {
console.log('Pact contract publishing complete!');
console.log('');
console.log(`Head over to ${process.env.PACTFLOW_BROKER_URL} to see your published contracts.`);
})
.catch((e: any) => {
console.log('Pact contract publishing failed: ', e);
});