From 2ff79d3ca0ac2c8812c86edf74c7bafa25a8783f Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Mon, 22 Nov 2021 18:04:17 +0100 Subject: [PATCH] fix(hadron-build): Check if evergreen channels are matching the expectation before uploading the release Both evergreen stable and testing are currently picking up the changes in the x.x-releases branches and basically racing to release Compass disregarding if they should. This checks the project against the release channel to make sure that stable doesn't publish beta releases and vice versa --- packages/hadron-build/commands/upload.js | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/hadron-build/commands/upload.js b/packages/hadron-build/commands/upload.js index 65d59a120fa..9a0ba1d9691 100644 --- a/packages/hadron-build/commands/upload.js +++ b/packages/hadron-build/commands/upload.js @@ -83,6 +83,31 @@ exports.handler = function(argv) { return; } + if (process.env.CI && !process.env.EVERGREEN_PROJECT) { + cli.warn('Trying to publish a release from non-Evergreen CI environment'); + return; + } + + if (process.env.EVERGREEN_PROJECT) { + const projectChannel = process.env.EVERGREEN_PROJECT.split('-').pop(); + if (!['stable', 'testing'].includes(projectChannel)) { + cli.warn( + `Trying to publish a release from unsupported Evergreen project. Expected stable or testing, got ${projectChannel}` + ); + return; + } + const channelToProjectMap = { + testing: 'beta' + }; + const mappedChannel = channelToProjectMap[projectChannel] || projectChannel; + if (target.channel !== mappedChannel) { + cli.warn( + `Trying to publish a release from mismatched channel. Expected ${target.channel}, got ${mappedChannel}` + ); + return; + } + } + target.assets = target.assets.filter(function(asset) { // eslint-disable-next-line no-sync var exists = fs.existsSync(asset.path);