-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshould_generate.js
33 lines (29 loc) · 1.07 KB
/
should_generate.js
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 util = require('util')
const fs = require('fs')
const fetch = require("node-fetch");
const base64 = require('base-64');
const AsyncReadFile = util.promisify(fs.readFile);
async function getLastReleases() {
const url = 'https://api.github.com/repos/pact-foundation/pact-ruby-standalone/releases/latest';
try {
const response = await fetch(url, {
headers: { 'Authorization': 'Basic ' + base64.encode(process.env.GH_CLIENT_ID + ":" + process.env.GH_CLIENT_SECRET) },
});
const json = await response.json();
return json;
} catch (error) {
console.log("Error fetching releases");
}
}
async function run() {
const lastReleases = await getLastReleases();
const packagePath = './dist/package.json';
var file_content = await AsyncReadFile(packagePath);
var content = JSON.parse(file_content);
const releaseVersion = lastReleases.tag_name.replace('v', '');
if (content.version === releaseVersion) {
console.log('New binaries not found, skipping publish.');
process.exit(1);
}
}
run();