diff options
author | Fabio Berger <me@fabioberger.com> | 2018-08-23 20:56:40 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-08-23 20:56:40 +0800 |
commit | 2b38163274de9621160d54a8d809284c0b353cc4 (patch) | |
tree | 947a508ebbb309b90c0fcb67aebf09a411c1b50f | |
parent | 2a635929949c8d8c867b3a2e0297e74e0bd151a3 (diff) | |
download | dexon-sol-tools-2b38163274de9621160d54a8d809284c0b353cc4.tar.gz dexon-sol-tools-2b38163274de9621160d54a8d809284c0b353cc4.tar.zst dexon-sol-tools-2b38163274de9621160d54a8d809284c0b353cc4.zip |
Enable dry run of release publishing and handle git tags existing
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 12 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/publish_release_notes.ts | 13 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/utils/github_release_utils.ts | 40 |
3 files changed, 49 insertions, 16 deletions
diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 3b5070395..d27baf5f8 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -76,8 +76,10 @@ async function confirmAsync(message: string): Promise<void> { utils.log(`Calling 'lerna publish'...`); await lernaPublishAsync(packageToNextVersion); const isStaging = false; - await generateAndUploadDocJsonsAsync(packagesWithDocs, isStaging); - await publishReleaseNotesAsync(updatedPublicPackages); + const shouldUploadDocs = !configs.IS_LOCAL_PUBLISH; + await generateAndUploadDocJsonsAsync(packagesWithDocs, isStaging, shouldUploadDocs); + const isDryRun = configs.IS_LOCAL_PUBLISH; + await publishReleaseNotesAsync(updatedPublicPackages, isDryRun); })().catch(err => { utils.log(err); process.exit(1); @@ -101,10 +103,9 @@ function getPackagesWithDocs(allUpdatedPackages: Package[]): Package[] { return updatedPackagesWithDocPages; } -async function generateAndUploadDocJsonsAsync(packagesWithDocs: Package[], isStaging: boolean): Promise<void> { +async function generateAndUploadDocJsonsAsync(packagesWithDocs: Package[], isStaging: boolean, shouldUploadDocs: boolean): Promise<void> { for (const pkg of packagesWithDocs) { const nameWithoutPrefix = pkg.packageJson.name.replace('@0xproject/', ''); - const shouldUploadDocs = true; const docGenerateAndUploadUtils = new DocGenerateAndUploadUtils(nameWithoutPrefix, isStaging, shouldUploadDocs); await docGenerateAndUploadUtils.generateAndUploadDocsAsync(); } @@ -114,7 +115,8 @@ async function confirmDocPagesRenderAsync(packagesWithDocs: Package[]): Promise< // push docs to staging utils.log("Upload all docJson's to S3 staging..."); const isStaging = true; - await generateAndUploadDocJsonsAsync(packagesWithDocs, isStaging); + const shouldUploadDocs = true; + await generateAndUploadDocJsonsAsync(packagesWithDocs, isStaging, shouldUploadDocs); // deploy website to staging utils.log('Deploy website to staging...'); diff --git a/packages/monorepo-scripts/src/publish_release_notes.ts b/packages/monorepo-scripts/src/publish_release_notes.ts index 5afcc8775..1a0ec59e5 100644 --- a/packages/monorepo-scripts/src/publish_release_notes.ts +++ b/packages/monorepo-scripts/src/publish_release_notes.ts @@ -1,10 +1,21 @@ +import * as yargs from 'yargs'; + import { publishReleaseNotesAsync } from './utils/github_release_utils'; import { utils } from './utils/utils'; +const args = yargs + .option('isDryRun', { + describe: 'Whether we wish to do a dry run, not committing anything to Github', + type: 'boolean', + demandOption: true, + }) + .example('$0 --isDryRun true', 'Full usage example').argv; + // tslint:disable-next-line:no-floating-promises (async () => { + const isDryRun = args.isDryRun; const shouldIncludePrivate = false; const allUpdatedPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); - await publishReleaseNotesAsync(allUpdatedPackages); + await publishReleaseNotesAsync(allUpdatedPackages, isDryRun); })(); diff --git a/packages/monorepo-scripts/src/utils/github_release_utils.ts b/packages/monorepo-scripts/src/utils/github_release_utils.ts index 28dce70ac..43d0d9fc3 100644 --- a/packages/monorepo-scripts/src/utils/github_release_utils.ts +++ b/packages/monorepo-scripts/src/utils/github_release_utils.ts @@ -12,7 +12,7 @@ import { utils } from './utils'; const publishReleaseAsync = promisify(publishRelease); // tslint:disable-next-line:completed-docs -export async function publishReleaseNotesAsync(updatedPublishPackages: Package[]): Promise<void> { +export async function publishReleaseNotesAsync(updatedPublishPackages: Package[], isDryRun: boolean): Promise<void> { // Git push a tag representing this publish (publish-{commit-hash}) (truncate hash) const result = await execAsync('git log -n 1 --pretty=format:"%H"', { cwd: constants.monorepoRootPath }); const latestGitCommit = result.stdout; @@ -20,10 +20,22 @@ export async function publishReleaseNotesAsync(updatedPublishPackages: Package[] const shortenedGitCommit = latestGitCommit.slice(0, prefixLength); const tagName = `monorepo@${shortenedGitCommit}`; - await execAsync(`git rev-parse ${tagName}`); - await execAsync(`git tag ${tagName}`); + if (!isDryRun) { + try { + await execAsync(`git tag ${tagName}`); + } catch (err) { + if (_.includes(err.message, 'already exists')) { + // Noop tag creation since already exists + } else { + throw err; + } + } + const {stdout} = await execAsync(`git ls-remote --tags origin refs/tags/${tagName}`); + if (_.isEmpty(stdout)) { + await execAsync(`git push origin ${tagName}`); + } + } - await execAsync(`git push origin ${tagName}`); const releaseName = `0x monorepo - ${shortenedGitCommit}`; let assets: string[] = []; @@ -42,11 +54,7 @@ export async function publishReleaseNotesAsync(updatedPublishPackages: Package[] }); const finalAssets = adjustAssetPaths(assets); - utils.log('Publishing release notes ', releaseName, '...'); - // TODO: Currently publish-release doesn't let you specify the labels for each asset uploaded - // Ideally we would like to name the assets after the package they are from - // Source: https://github.com/remixz/publish-release/issues/39 - await publishReleaseAsync({ + const publishReleaseConfigs = { token: constants.githubPersonalAccessToken, owner: '0xProject', tag: tagName, @@ -58,7 +66,19 @@ export async function publishReleaseNotesAsync(updatedPublishPackages: Package[] reuseRelease: true, reuseDraftOnly: false, assets: finalAssets, - }); + }; + + if (isDryRun) { + utils.log(`Dry run: stopping short of publishing release notes to github`); + utils.log(`Would publish with configs:\n${JSON.stringify(publishReleaseConfigs, null, '\t')}`); + return; + } + + utils.log('Publishing release notes ', releaseName, '...'); + // TODO: Currently publish-release doesn't let you specify the labels for each asset uploaded + // Ideally we would like to name the assets after the package they are from + // Source: https://github.com/remixz/publish-release/issues/39 + await publishReleaseAsync(publishReleaseConfigs); } // Asset paths should described from the monorepo root. This method prefixes |