-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(github): connect npm release with more checks
- Loading branch information
Showing
6 changed files
with
244 additions
and
150 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
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,26 @@ | ||
import semver from 'semver'; | ||
|
||
import { getLocalVersion } from './helpers'; | ||
|
||
const checkVersions = (packages: string[], deploymentType: string): void => { | ||
const versions = packages.map(packageName => getLocalVersion(packageName)); | ||
|
||
const isCorrectType = versions.every(version => { | ||
const isBeta = semver.prerelease(version); | ||
return (deploymentType === 'canary' && isBeta) || (deploymentType === 'stable' && !isBeta); | ||
}); | ||
|
||
if (!isCorrectType) { | ||
console.error( | ||
`Mixed deployment types detected. All versions should be either "stable" or "canary".`, | ||
); | ||
process.exit(1); | ||
} else { | ||
console.log(`All versions are of the ${deploymentType} deployment type.`); | ||
} | ||
}; | ||
|
||
const packages = JSON.parse(process.argv[2]); | ||
const deploymentType = process.argv[3]; | ||
|
||
checkVersions(packages, deploymentType); |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
const semver = require('semver'); | ||
|
||
const version = process.argv[2]; | ||
|
||
let deploymentType; | ||
if (semver.prerelease(version)) { | ||
deploymentType = 'canary'; | ||
} else if (semver.minor(version) || semver.major(version)) { | ||
deploymentType = 'stable'; | ||
} else { | ||
throw new Error(`Invalid version: ${version}`); | ||
} | ||
|
||
process.stdout.write(deploymentType); |
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,77 @@ | ||
// This script should check what packages from the repository have a higher version than in NPM | ||
// and stdout out those to be used by GitHub workflow. | ||
|
||
import fs from 'fs'; | ||
import util from 'util'; | ||
import path from 'path'; | ||
import semver from 'semver'; | ||
|
||
import { getNpmRemoteGreatestVersion } from './helpers'; | ||
|
||
const readFile = util.promisify(fs.readFile); | ||
|
||
const ROOT = path.join(__dirname, '..', '..'); | ||
|
||
const nonReleaseDependencies: string[] = []; | ||
|
||
const checkNonReleasedDependencies = async (packageName: string) => { | ||
const rawPackageJSON = await readFile( | ||
path.join(ROOT, 'packages', packageName, 'package.json'), | ||
'utf-8', | ||
); | ||
|
||
const packageJSON = JSON.parse(rawPackageJSON); | ||
const { | ||
version: localVersion, | ||
dependencies, | ||
// devDependencies // We should ignore devDependencies. | ||
} = packageJSON; | ||
|
||
const remoteGreatestVersion = await getNpmRemoteGreatestVersion(`@trezor/${packageName}`); | ||
|
||
// If local version is greatest than the greatest one in NPM we add it to the release. | ||
if (semver.gt(localVersion, remoteGreatestVersion as string)) { | ||
const index = nonReleaseDependencies.indexOf(packageName); | ||
if (index > -1) { | ||
nonReleaseDependencies.splice(index, 1); | ||
} | ||
nonReleaseDependencies.push(packageName); | ||
} | ||
|
||
if (!dependencies || !Object.keys(dependencies)) { | ||
return; | ||
} | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
for await (const [dependency] of Object.entries(dependencies)) { | ||
// is not a dependency released from monorepo. we don't care | ||
if (!dependency.startsWith('@trezor')) { | ||
// eslint-disable-next-line no-continue | ||
continue; | ||
} | ||
const [_prefix, name] = dependency.split('/'); | ||
|
||
await checkNonReleasedDependencies(name); | ||
} | ||
}; | ||
|
||
const getConnectDependenciesToRelease = async () => { | ||
// We check what dependencies need to be released because they have version bumped locally | ||
// and remote greatest version is lower than the local one. | ||
await checkNonReleasedDependencies('connect'); | ||
await checkNonReleasedDependencies('connect-web'); | ||
await checkNonReleasedDependencies('connect-webextension'); | ||
|
||
// We do not want to include `connect`, `connect-web` and `connect-webextension` since we want | ||
// to release those separately and we always want to release them. | ||
const onlyDependenciesToRelease = nonReleaseDependencies.filter(item => { | ||
return !['connect', 'connect-web', 'connect-webextension'].includes(item); | ||
}); | ||
|
||
// We use `onlyDependenciesToRelease` to trigger NPM releases | ||
const dependenciesToRelease = JSON.stringify(onlyDependenciesToRelease); | ||
|
||
process.stdout.write(dependenciesToRelease); | ||
}; | ||
|
||
getConnectDependenciesToRelease(); |
Oops, something went wrong.