mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-21 05:47:18 +00:00

`etcher-latest-version` was kept in a separate repository in order to re-use it with the Etcher website, however the Etcher website is not using it at all, and we're moving towards having the website in the main repository. Therefore, this commit brings back the logic from `etcher-latest-version`, but introduces it as `lib/shared/s3-packages.js`, in order to not tie ourselves to the AngularJS framework, and as a step towards the Etcher SDK. As a nice little bonus, this commit adds support for an `ETCHER_FAKE_S3_LATEST_VERSION` environment variable that can be used to trick Etcher that there is an available update, and therefore show the update notifier modal. Also, this commit adds support for snapshot builds update-checks, by checking the `resin-nightly-downloads` S3 bucket if the current version contains a git commit hash build number. If the version is not a production release, then the update notifier modal doesn't present the checkbox to disable update notifications for X days. We also add a property called `updates.semverRange` to `package.json`, which can be used to fine control which versions are considered as candidates for an update notification. This commit adds a setting called `includeUnstableChannel`, which can be used to tweak whether unstable (beta) releases are considered or not when checking for the latest available version. See: https://github.com/resin-io-modules/etcher-latest-version Fixes: https://github.com/resin-io/etcher/issues/953 Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
104 lines
2.4 KiB
JavaScript
104 lines
2.4 KiB
JavaScript
/*
|
|
* Copyright 2017 resin.io
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
const semver = require('semver');
|
|
|
|
/**
|
|
* @summary Application release types
|
|
* @namespace RELEASE_TYPE
|
|
* @public
|
|
*/
|
|
exports.RELEASE_TYPE = {
|
|
|
|
/**
|
|
* @property {String} PRODUCTION
|
|
* @memberof RELEASE_TYPE
|
|
* @description
|
|
* Production release type
|
|
*/
|
|
PRODUCTION: 'PRODUCTION',
|
|
|
|
/**
|
|
* @property {String} SNAPSHOT
|
|
* @memberof RELEASE_TYPE
|
|
* @description
|
|
* Snapshot release type
|
|
*/
|
|
SNAPSHOT: 'SNAPSHOT',
|
|
|
|
/**
|
|
* @property {String} UNKNOWN
|
|
* @memberof RELEASE_TYPE
|
|
* @description
|
|
* Unknown release type
|
|
*/
|
|
UNKNOWN: 'UNKNOWN'
|
|
|
|
};
|
|
|
|
/**
|
|
* @summary Get the release type from a version string
|
|
* @function
|
|
* @public
|
|
*
|
|
* @param {String} version - application version
|
|
* @returns {RELEASE_TYPE} release type
|
|
*
|
|
* @example
|
|
* const version = require('../../package.json').version;
|
|
* const releaseType = release.getReleaseType(version);
|
|
*
|
|
* if (releaseType === release.RELEASE_TYPE.PRODUCTION) {
|
|
* console.log('This is a production release!');
|
|
* }
|
|
*/
|
|
exports.getReleaseType = (version) => {
|
|
const GIT_HASH_REGEX = /^[0-9a-f]{7,40}$/;
|
|
const buildNumber = _.get(semver.parse(version), [ 'build' ]);
|
|
|
|
if (!_.isNil(buildNumber)) {
|
|
if (_.isEmpty(buildNumber)) {
|
|
return exports.RELEASE_TYPE.PRODUCTION;
|
|
}
|
|
|
|
if (GIT_HASH_REGEX.test(_.first(buildNumber))) {
|
|
return exports.RELEASE_TYPE.SNAPSHOT;
|
|
}
|
|
}
|
|
|
|
return exports.RELEASE_TYPE.UNKNOWN;
|
|
};
|
|
|
|
/**
|
|
* @summary Check if a version is a stable release
|
|
* @function
|
|
* @public
|
|
*
|
|
* @param {String} version - version
|
|
* @returns {Boolean} whether the version is a stable release
|
|
*
|
|
* @example
|
|
* if (release.isStableRelease('1.0.0')) {
|
|
* console.log('This is a stable release');
|
|
* }
|
|
*/
|
|
exports.isStableRelease = (version) => {
|
|
return _.isEmpty(_.get(semver.parse(version), [ 'prerelease' ]));
|
|
};
|