chore(scripts): Implement new release helpers
This commit is contained in:
parent
0920fe3b7f
commit
09cfec2b3b
22
package.json
22
package.json
@ -9,15 +9,12 @@
|
||||
"e2e": "./scripts/e2e.sh",
|
||||
"format": "prettier \"{packages,e2e}/**/*.ts\" --write",
|
||||
"linknpm": "./scripts/link.sh",
|
||||
"package": "./scripts/package.sh",
|
||||
"release": "./scripts/release.sh",
|
||||
"nx-release": "./scripts/nx-release.js",
|
||||
"copy": "./scripts/copy.sh",
|
||||
"test:schematics": "yarn linknpm fast && ./scripts/test_schematics.sh",
|
||||
"test:nx": "yarn linknpm fast && ./scripts/test_nx.sh",
|
||||
"test":
|
||||
"yarn linknpm fast && ./scripts/test_nx.sh && ./scripts/test_schematics.sh",
|
||||
"checkformat": "prettier \"{packages,e2e}/**/*.ts\" --list-different",
|
||||
"publish_npm": "./scripts/publish.sh"
|
||||
"test": "yarn linknpm fast && ./scripts/test_nx.sh && ./scripts/test_schematics.sh",
|
||||
"checkformat": "prettier \"{packages,e2e}/**/*.ts\" --list-different"
|
||||
},
|
||||
"dependencies": {
|
||||
"jasmine-marbles": "0.2.0"
|
||||
@ -44,7 +41,9 @@
|
||||
"@types/yargs": "^11.0.0",
|
||||
"angular": "1.6.6",
|
||||
"app-root-path": "^2.0.1",
|
||||
"conventional-changelog-cli": "^1.3.21",
|
||||
"cosmiconfig": "^4.0.0",
|
||||
"fs-extra": "5.0.0",
|
||||
"graphviz": "^0.0.8",
|
||||
"husky": "^0.14.3",
|
||||
"jasmine-core": "~2.8.0",
|
||||
@ -59,6 +58,7 @@
|
||||
"opn": "^5.3.0",
|
||||
"precise-commits": "1.0.0",
|
||||
"prettier": "1.10.2",
|
||||
"release-it": "^7.4.0",
|
||||
"rxjs": "^5.5.6",
|
||||
"semver": "5.4.1",
|
||||
"strip-json-comments": "2.0.1",
|
||||
@ -66,14 +66,16 @@
|
||||
"tslint": "5.9.1",
|
||||
"typescript": "2.6.2",
|
||||
"viz.js": "^1.8.1",
|
||||
"yargs-parser": "10.0.0",
|
||||
"yargs": "^11.0.0",
|
||||
"zone.js": "^0.8.19",
|
||||
"fs-extra": "5.0.0"
|
||||
"yargs-parser": "10.0.0",
|
||||
"zone.js": "^0.8.19"
|
||||
},
|
||||
"author": "Victor Savkin",
|
||||
"license": "MIT",
|
||||
"jest": {
|
||||
"modulePathIgnorePatterns": ["tmp", "files"]
|
||||
"modulePathIgnorePatterns": [
|
||||
"tmp",
|
||||
"files"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
177
scripts/nx-release.js
Executable file
177
scripts/nx-release.js
Executable file
@ -0,0 +1,177 @@
|
||||
#!/usr/bin/env node
|
||||
const yargsParser = require('yargs-parser');
|
||||
const releaseIt = require('release-it');
|
||||
const childProcess = require('child_process');
|
||||
|
||||
const parsedArgs = yargsParser(process.argv, {
|
||||
boolean: ['dry-run'],
|
||||
alias: {
|
||||
d: 'dry-run',
|
||||
h: 'help'
|
||||
}
|
||||
});
|
||||
|
||||
if (parsedArgs.help) {
|
||||
console.log(`
|
||||
Usage: yarn nx-release <version> [options]
|
||||
|
||||
Example: "yarn nx-release 1.0.0-beta.1"
|
||||
|
||||
The acceptable format for the version number is:
|
||||
{number}.{number}.{number}[-{alpha|beta|rc}.{number}]
|
||||
|
||||
The subsection of the version number in []s is optional, and, if used, will be used to
|
||||
mark the release as "prerelease" on GitHub, and tag it with "next" on npm.
|
||||
|
||||
Options:
|
||||
--dry-run Do not touch or write anything, but show the commands
|
||||
--help Show this message
|
||||
|
||||
`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function parseVersion(version) {
|
||||
if (!version || !version.length) {
|
||||
return {
|
||||
version,
|
||||
isValid: false,
|
||||
isPrerelease: false
|
||||
};
|
||||
}
|
||||
const sections = version.split('-');
|
||||
if (sections.length === 1) {
|
||||
/**
|
||||
* Not a prerelease version, validate matches exactly the
|
||||
* standard {number}.{number}.{number} format
|
||||
*/
|
||||
return {
|
||||
version,
|
||||
isValid: !!sections[0].match(/\d+\.\d+\.\d+$/),
|
||||
isPrerelease: false
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Is a prerelease version, validate each section
|
||||
* 1. {number}.{number}.{number} format
|
||||
* 2. {alpha|beta|rc}.{number}
|
||||
*/
|
||||
return {
|
||||
version,
|
||||
isValid: !!(
|
||||
sections[0].match(/\d+\.\d+\.\d+$/) &&
|
||||
sections[1].match(/(alpha|beta|rc)\.\d+$/)
|
||||
),
|
||||
isPrerelease: true
|
||||
};
|
||||
}
|
||||
|
||||
const parsedVersion = parseVersion(parsedArgs._[2]);
|
||||
if (!parsedVersion.isValid) {
|
||||
console.error(
|
||||
`\nError:\nThe specified version is not valid. You specified: "${parsedVersion.version}"`
|
||||
);
|
||||
console.error(
|
||||
`Please run "yarn nx-release --help" for details on the acceptable version format.\n`
|
||||
);
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
console.log('Executing build script:');
|
||||
const buildCommand = './scripts/package.sh';
|
||||
console.log(`> ${buildCommand}`);
|
||||
childProcess.execSync(buildCommand, {
|
||||
stdio: [0, 1, 2]
|
||||
});
|
||||
|
||||
/**
|
||||
* Create working directory and copy over built packages
|
||||
*/
|
||||
childProcess.execSync('rm -rf build/npm && mkdir -p build/npm', {
|
||||
stdio: [0, 1, 2]
|
||||
});
|
||||
childProcess.execSync('cp -R build/packages/* build/npm', {
|
||||
stdio: [0, 1, 2]
|
||||
});
|
||||
/**
|
||||
* Get rid of tarballs at top of copied directory (made with npm pack)
|
||||
*/
|
||||
childProcess.execSync(`find build/npm -name *.tgz -maxdepth 1 -delete`, {
|
||||
stdio: [0, 1, 2]
|
||||
});
|
||||
|
||||
/**
|
||||
* Setting this to true can be useful for development/testing purposes.
|
||||
* No git commands, nor npm publish commands will be run when this is
|
||||
* true.
|
||||
*/
|
||||
const DRY_RUN = !!parsedArgs['dry-run'];
|
||||
|
||||
/**
|
||||
* Set the static options for release-it
|
||||
*/
|
||||
const options = {
|
||||
'dry-run': DRY_RUN,
|
||||
changelogCommand: 'conventional-changelog -p angular | tail -n +3',
|
||||
/**
|
||||
* Needed so that we can leverage conventional-changelog to generate
|
||||
* the changelog
|
||||
*/
|
||||
safeBump: false,
|
||||
/**
|
||||
* All the package.json files that will have their version updated
|
||||
* by release-it
|
||||
*/
|
||||
pkgFiles: [
|
||||
'package.json',
|
||||
'build/npm/bazel/package.json',
|
||||
'build/npm/nx/package.json',
|
||||
'build/npm/schematics/package.json'
|
||||
],
|
||||
increment: parsedVersion.version,
|
||||
github: {
|
||||
preRelease: parsedVersion.isPrerelease,
|
||||
release: true,
|
||||
/**
|
||||
* The environment variable containing a valid GitHub
|
||||
* auth token with "repo" access (no other permissions required)
|
||||
*/
|
||||
token: process.env.GITHUB_TOKEN_RELEASE_IT_NX
|
||||
},
|
||||
npm: {
|
||||
/**
|
||||
* We don't use release-it to do the npm publish, because it is not
|
||||
* able to understand our multi-package setup.
|
||||
*/
|
||||
release: false
|
||||
}
|
||||
};
|
||||
|
||||
releaseIt(options)
|
||||
.then(output => {
|
||||
if (DRY_RUN) {
|
||||
console.warn('WARNING: In DRY_RUN mode - not running publishing script');
|
||||
process.exit(0);
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* We always use either "latest" or "next" (i.e. no separate tags for alpha, beta etc)
|
||||
*/
|
||||
const npmTag = parsedVersion.isPrerelease ? 'next' : 'latest';
|
||||
const npmPublishCommand = `./scripts/publish.sh ${
|
||||
output.version
|
||||
} ${npmTag}`;
|
||||
console.log('Executing publishing script for all packages:');
|
||||
console.log(`> ${npmPublishCommand}`);
|
||||
console.log(
|
||||
`Note: You will need to authenticate with your NPM credentials`
|
||||
);
|
||||
childProcess.execSync(npmPublishCommand, {
|
||||
stdio: [0, 1, 2]
|
||||
});
|
||||
process.exit(0);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err.message);
|
||||
process.exit(1);
|
||||
});
|
||||
@ -1,4 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
##################################################
|
||||
# This shell script is executed by nx-release.js #
|
||||
##################################################
|
||||
|
||||
SCHEMATICS_VERSION=$1
|
||||
NX_VERSION=$2
|
||||
|
||||
@ -1,70 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
##################################################
|
||||
# This shell script is executed by nx-release.js #
|
||||
##################################################
|
||||
|
||||
# This script will:
|
||||
# - Run the package script
|
||||
# - copy built packages into new directory, so as to not mutate in place
|
||||
# - NOT change the version of the root package.json
|
||||
# - set all built package versions to value provided in the command line OR the version in the root package.json
|
||||
# - validate that the supplied version is a valid npm version according to the semver spec
|
||||
# - check that npm does not already have this version published for ANY package
|
||||
# - publish all packages in the build/packages directory to npm
|
||||
# - publish to the provided tag OR `latest` by default
|
||||
|
||||
# i.e. ./scripts/publish.sh 1.0.0-beta.1 beta
|
||||
VERSION=$1
|
||||
TAG=$2
|
||||
PACKAGE_SOURCE=build/packages
|
||||
NPM_DEST=build/npm
|
||||
ORIG_DIRECTORY=`pwd`
|
||||
|
||||
# Grab version from package.json if not provided as 1st arg
|
||||
if [ -z "$VERSION" ]; then
|
||||
VERSION=`node -e "console.log(require('./package.json').version)"`
|
||||
fi
|
||||
|
||||
# Validate that the version is valid according to semver
|
||||
VERSION=`node -e "console.log(require('semver').valid('${VERSION}'))"`
|
||||
|
||||
if [ "$VERSION" = "null" ]; then
|
||||
echo "Version $VERSION is not valid semver"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$TAG" ]; then
|
||||
TAG="latest"
|
||||
fi
|
||||
|
||||
./scripts/package.sh $VERSION $VERSION
|
||||
|
||||
# Create working directory and copy over built packages
|
||||
rm -rf $NPM_DEST
|
||||
mkdir -p $NPM_DEST
|
||||
cp -R $PACKAGE_SOURCE/* $NPM_DEST/
|
||||
|
||||
# Get rid of tarballs at top of copied directory (made with npm pack)
|
||||
find $NPM_DEST -name *.tgz -maxdepth 1 -delete
|
||||
|
||||
# We are running inside of a child_process, so we need to reauth
|
||||
npm adduser
|
||||
|
||||
for package in $NPM_DEST/*/
|
||||
do
|
||||
|
||||
PACKAGE_DIR="$(basename ${package})"
|
||||
cd $NPM_DEST/$PACKAGE_DIR
|
||||
# Check that the new version for the package is not taken
|
||||
PACKAGE_NAME=`node -e "console.log(require('./package.json').name)"`
|
||||
echo "Preparing to publish ${PACKAGE_NAME}"
|
||||
# Package might not exist yet, so suppress errors if so
|
||||
PACKAGE_INFO=`npm view ${PACKAGE_NAME}@${VERSION} 2> /dev/null`
|
||||
if [ -z "$PACKAGE_INFO"]; then
|
||||
echo "Package ${PACKAGE_NAME} not yet published. Okay to proceed."
|
||||
elif [ "$PACKAGE_INFO" = "undefined" ]; then
|
||||
echo "Package ${PACKAGE_NAME} not yet published at ${VERSION}. Okay to proceed."
|
||||
else
|
||||
echo "package ${PACKAGE_NAME} has already been published at ${VERSION}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set the package.json version for the package
|
||||
npm version $VERSION
|
||||
PACKAGE_NAME=`node -e "console.log(require('./package.json').name)"`
|
||||
|
||||
echo "Publishing ${PACKAGE_NAME}@${VERSION} --tag ${TAG}"
|
||||
npm publish --tag $TAG
|
||||
|
||||
@ -1,62 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
./scripts/package.sh "nrwl/schematics-build" "nrwl/nx-build"
|
||||
|
||||
function restore() {
|
||||
echo "FINISHED"
|
||||
cd $STARTING_DIRECTORY
|
||||
}
|
||||
|
||||
function getPackageVersion() {
|
||||
echo `node -e "console.log(require('./package.json').version)"`
|
||||
}
|
||||
|
||||
#Rewrite the version in the package.json to be root package version+short sha (0.0.1+abcdef0)
|
||||
function updatePackageVersion() {
|
||||
PACKAGE_NAME=$1
|
||||
VERSION=$2
|
||||
node -e "const pkgPath='./${PACKAGE_NAME}/package.json';const pkg=require(pkgPath);pkg.version='${VERSION}'; fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)+'\n')"
|
||||
}
|
||||
|
||||
STARTING_DIRECTORY=${PWD}
|
||||
SHORT_SHA=`git rev-parse --short HEAD`
|
||||
BRANCH_NAME=pub-${SHORT_SHA}
|
||||
PACKAGE_VERSION=`getPackageVersion`
|
||||
BUILT=../packages
|
||||
BUILD_VER="${PACKAGE_VERSION}+${SHORT_SHA}"
|
||||
trap restore SIGINT SIGTERM EXIT
|
||||
|
||||
mkdir -p build/git-clones
|
||||
cd build/git-clones
|
||||
|
||||
for dir in $BUILT/*/
|
||||
do
|
||||
PACKAGE_DIR="$(basename ${dir})"
|
||||
BUILD_ARTIFACTS="${dir}"
|
||||
REPO_DIR="${PACKAGE_DIR}-build"
|
||||
|
||||
rm -rf $REPO_DIR
|
||||
mkdir -p $REPO_DIR
|
||||
# Create directory and populate with shallow git content from origin
|
||||
(cd $REPO_DIR &&
|
||||
git init && \
|
||||
git remote add origin git@github.com:nrwl/$REPO_DIR.git && \
|
||||
git fetch origin master --depth=1 && \
|
||||
git checkout origin/master && \
|
||||
git checkout -b $BRANCH_NAME
|
||||
)
|
||||
|
||||
# Clean up the contents of the git directory so creating the commit will
|
||||
# be simpler (not having to selectively delete files)
|
||||
rm -rf $REPO_DIR/*
|
||||
cp -R ${BUILD_ARTIFACTS}/* $REPO_DIR/
|
||||
updatePackageVersion $REPO_DIR $BUILD_VER
|
||||
|
||||
(
|
||||
cd $REPO_DIR && \
|
||||
git add --all && \
|
||||
git commit -m "publishing ${BUILD_VER}" --quiet && \
|
||||
git tag "${BUILD_VER}" && \
|
||||
git push origin $BRANCH_NAME:master --tags --force
|
||||
)
|
||||
done
|
||||
Loading…
x
Reference in New Issue
Block a user