Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved the publish.ps1 to be able to publish RC packages #5110

Merged
merged 5 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/angular.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
paths:
- 'npm/ng-packs/**'
- '!npm/ng-packs/scripts/**'
jobs:
build-test-lint:
runs-on: ubuntu-18.04
Expand Down
10 changes: 0 additions & 10 deletions npm/get-version.js

This file was deleted.

17 changes: 9 additions & 8 deletions npm/ng-packs/scripts/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ program
'-v, --nextVersion <version>',
'next semantic version. Available versions: ["major", "minor", "patch", "premajor", "preminor", "prepatch", "prerelease", "or type a custom version"]',
)
.option('-p, --preview', 'publish with preview tag');
.option('-p, --preview', 'publishes with preview tag')
.option('-r, --rc', 'publishes with next tag')
.option('-g, --skipGit', 'skips git push');

program.parse(process.argv);

Expand Down Expand Up @@ -55,14 +57,13 @@ const publish = async () => {

await fse.rename('../lerna.publish.json', '../lerna.json');

let tag: string;
if (program.preview) tag = 'preview';
if (program.rc) tag = 'next';

await execa(
'yarn',
[
'lerna',
'exec',
'--',
`"npm publish --registry ${registry}${program.preview ? ' --tag preview' : ''}"`,
],
['lerna', 'exec', '--', `"npm publish --registry ${registry}${tag ? ` --tag ${tag}` : ''}"`],
{
stdout: 'inherit',
cwd: '../',
Expand All @@ -71,7 +72,7 @@ const publish = async () => {

await fse.rename('../lerna.json', '../lerna.publish.json');

if (!program.preview) {
if (!program.preview && !program.skipGit) {
await execa('git', ['add', '../packages/*', '../package.json', '../lerna.version.json'], {
stdout: 'inherit',
});
Expand Down
15 changes: 10 additions & 5 deletions npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"npm-check-updates": "^3.1.25"
},
"dependencies": {
"commander": "^6.0.0",
"execa": "^3.4.0",
"fs-extra": "^8.1.0"
}
Expand Down
6 changes: 3 additions & 3 deletions npm/preview-publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ param(

npm install

$NextVersion = $(node get-version.js)
$rootFolder = (Get-Item -Path "./" -Verbose).FullName
$NextVersion = $(node publish-utils.js --nextVersion)
$RootFolder = (Get-Item -Path "./" -Verbose).FullName

if(-Not $Version) {
$Version = $NextVersion;
Expand All @@ -34,7 +34,7 @@ foreach ($command in $commands) {
Invoke-Expression $command
if($LASTEXITCODE -ne '0' -And $command -notlike '*cd *'){
Write-Host ("Process failed! " + $command)
Set-Location $rootFolder
Set-Location $RootFolder
exit $LASTEXITCODE
}
}
21 changes: 21 additions & 0 deletions npm/publish-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { program } = require('commander');
const fse = require('fs-extra');

program.version('0.0.1');
program.option('-n, --nextVersion', 'version in common.props');
program.option('-r, --rc', 'whether version is rc');

program.parse(process.argv);

if (program.nextVersion) console.log(getVersion());

if (program.rc) console.log(getVersion().includes('rc'));

function getVersion() {
const commonProps = fse.readFileSync('../common.props').toString();
const versionTag = '<Version>';
const versionEndTag = '</Version>';
const first = commonProps.indexOf(versionTag) + versionTag.length;
const last = commonProps.indexOf(versionEndTag);
return commonProps.substring(first, last);
}
20 changes: 15 additions & 5 deletions npm/publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@ param(

npm install

$NextVersion = $(node get-version.js)
$rootFolder = (Get-Item -Path "./" -Verbose).FullName
$NextVersion = $(node publish-utils.js --nextVersion)
$RootFolder = (Get-Item -Path "./" -Verbose).FullName

if(-Not $Version) {
$Version = $NextVersion;
}

$NgPacksPublishCommand = "npm run publish-packages -- --nextVersion $Version --skipGit"
$PacksPublishCommand = "npm run lerna -- exec 'npm publish --registry https://registry.npmjs.org'"

$IsRc = $(node publish-utils.js --rc) -eq "true";

if($IsRc) {
$NgPacksPublishCommand += " --rc"
$PacksPublishCommand = $PacksPublishCommand.Substring(0,$PacksPublishCommand.Length-1) + " --tag next'"
}

$commands = (
"cd ng-packs\scripts",
"npm install",
"npm run publish-packages -- --nextVersion $Version",
$NgPacksPublishCommand,
"cd ../../",
"npm run lerna -- version $Version --yes --no-commit-hooks --skip-git --force-publish",
"npm run replace-with-tilde",
"npm run lerna -- exec 'npm publish --registry https://registry.npmjs.org'",
$PacksPublishCommand,
"npm run update-gulp"
)

Expand All @@ -27,7 +37,7 @@ foreach ($command in $commands) {
Invoke-Expression $command
if($LASTEXITCODE -ne '0' -And $command -notlike '*cd *'){
Write-Host ("Process failed! " + $command)
Set-Location $rootFolder
Set-Location $RootFolder
exit $LASTEXITCODE
}
}