Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement git tag checking for autoupdate. #43

Open
wants to merge 5 commits into
base: sensotrend-uploader
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 57 additions & 17 deletions electron-builder-publish.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const child_process = require('child_process');

const config = {
publish: [
'github'
Expand Down Expand Up @@ -93,33 +95,71 @@ const config = {
},
'dir'
]
},
linux: {
target: ['AppImage'],
category: 'Utility',
}
};

console.log('CIRCLE_TAG:', process.env.CIRCLE_TAG);
console.log('APPVEYOR_REPO_TAG:', process.env.APPVEYOR_REPO_TAG);
function resolveReleaseType() {
const gitResult = child_process.spawnSync('git', ['describe', '--tags'], {
shell: true,
stdio: [
'ignore',
'pipe',
'inherit',
],
timeout: 2000,
});
if (gitResult.status !== 0 || gitResult.error) {
throw new Error('git describe failed: ' +
(gitResult.error || gitResult.status));
}

if ( (process.env.CIRCLE_TAG && process.env.CIRCLE_TAG.length > 0) ||
(process.env.APPVEYOR_REPO_TAG_NAME && process.env.APPVEYOR_REPO_TAG_NAME.length > 0) ) {
let releaseType = null;
const tagStdout = gitResult.stdout.toString().trim();
const tagPattern = /^(.+?)(-\w+?)?(-\d+-g\w+)?$/;
const tagDetails = tagPattern.exec(tagStdout);
if (tagDetails === null) {
throw new Error('Couldn\'t parse tag: ' + tagStdout);
}

if ( (process.env.CIRCLE_TAG && process.env.CIRCLE_TAG.indexOf('-') !== -1) ||
(process.env.APPVEYOR_REPO_TAG_NAME && process.env.APPVEYOR_REPO_TAG_NAME.indexOf('-') !== -1) ) {
// non-production releases have hyphens in their tags
releaseType = 'pre-release';
let channel;
let logSuffix = '';
if (tagDetails[3]) {
channel = 'snapshot';
logSuffix = ', detail=' + tagDetails[3].substring(1);
} else if (tagDetails[2]) {
channel = tagDetails[2].substring(1);
} else {
releaseType = 'release';
channel = 'unknown';
}

const tagVersion = tagDetails[1].trim();
console.info(' * Release: tag version=' + tagVersion +
', channel=' + channel + logSuffix);

const pkg = require('./package.json');
if (channel !== 'snapshot') {
if (pkg.version !== tagVersion) {
throw new Error(' ** Package.json and tag version differ: '
+ pkg.version + ' != ' + tagVersion);
}
} else if (pkg.version.indexOf('snapshot') === -1) {
throw new Error(' ** Package.json version must contain' +
' text "snapshot" for snapshot packaging.');
}
return channel;
}

const channel = resolveReleaseType();

if (channel !== 'unknown') {
config.publish = [
{
provider: 'github',
owner: 'tidepool-org', // required to overwrite existing binaries
releaseType: releaseType,
},
{
provider: 's3',
bucket: 'downloads.tidepool.org',
provider: 'generic',
url: 'https://www.sensotrend.fi/download/uploader/update/${os}/',
mrinnetmaki marked this conversation as resolved.
Show resolved Hide resolved
channel: channel,
},
];
}
Expand Down