-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a command for automated releases (#62)
- Loading branch information
Showing
10 changed files
with
80 additions
and
23 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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
declare module 'semver' { | ||
export function gt(a: string, b: string): boolean; | ||
export function gte(a: string, b: string): boolean; | ||
} |
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
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
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,53 @@ | ||
import {diezVersion, fatalError} from '@diez/cli-core'; | ||
import {readJsonSync, writeJsonSync} from 'fs-extra'; | ||
import {join} from 'path'; | ||
import {gte} from 'semver'; | ||
import {root, run, runQuiet} from '../internal/helpers'; | ||
|
||
export = { | ||
name: 'release [version]', | ||
description: 'Creates a release.', | ||
action: async (_: {}, version: string) => { | ||
if (!version || gte(diezVersion, version)) { | ||
fatalError('Refusing to set a lower version.'); | ||
} | ||
|
||
if (runQuiet('git rev-parse --abbrev-ref HEAD') !== 'master') { | ||
fatalError('You must be on the `master` branch to create a release.'); | ||
} | ||
|
||
if (runQuiet('git diff')) { | ||
fatalError('Working tree has untracked changes; unable to proceed.'); | ||
} | ||
|
||
run('git fetch'); | ||
if (runQuiet('git diff origin/master')) { | ||
fatalError('You must be up to date on the latest `master` branch to create a release.'); | ||
} | ||
|
||
try { | ||
runQuiet('aws s3 ls s3://diez-docs'); | ||
} catch (e) { | ||
fatalError('Unable to run AWS S3 commands. `aws` is either not installed or missing privileges.'); | ||
} | ||
|
||
const docs = runQuiet('yarn docs'); | ||
if (docs.includes('Error:')) { | ||
fatalError('Generating docs produced an error. Please fix the issue and try again.'); | ||
} | ||
|
||
run(`aws s3 cp api s3://diez-docs/${version} --recursive`); | ||
run('aws s3 sync api s3://diez-docs/latest'); | ||
|
||
// Manually bump the monorepo package.json version of `diez-cli`. | ||
const packageJsonPath = join(root, 'package.json'); | ||
const packageJson = readJsonSync(packageJsonPath); | ||
packageJson.devDependencies['diez-cli'] = version; | ||
writeJsonSync(packageJsonPath, packageJson, {spaces: 2}); | ||
run('git add package.json'); | ||
run(`git commit -m 'release: ${version}'`); | ||
|
||
// Create the release with Lerna. | ||
run(`yarn lerna publish ${version} --github-release --conventional-commits --amend --yes`); | ||
}, | ||
}; |
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