This repository has been archived by the owner on Dec 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: elect build leader by highest node version
BREAKING CHANGE: The first job in the build matrix is no longer automatically elected to be the build leader. Instead the build job with the highest node version is selected. If you want to control which job is the build leader set the environment variable `BUILD_LEADER_ID`.
- Loading branch information
1 parent
2bcdee6
commit bd850b1
Showing
2 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const semver = require('semver') | ||
|
||
module.exports = versions => { | ||
// if there is only one candidate, then it's the winner | ||
if (!Array.isArray(versions) || versions.length === 1) return 1 | ||
|
||
// if there is latest stable it's the winner | ||
const stable = versions.indexOf('node') + 1 | ||
if (stable) return stable | ||
|
||
// otherwise we use the lower bound of all valid semver ranges | ||
const validRanges = versions.filter(semver.validRange) | ||
const lowVersionBoundaries = validRanges | ||
.map(semver.Range) | ||
.map(r => r.set[0][0].semver.version) | ||
|
||
// then we find the highest of those | ||
const highestVersion = semver.sort(Array.from(lowVersionBoundaries)).pop() | ||
const highestRange = validRanges[lowVersionBoundaries.indexOf(highestVersion)] | ||
|
||
// and make its build job the winner | ||
return versions.indexOf(highestRange) + 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters