From 301c7c398f65a3ceca6e336492a2e385a3374156 Mon Sep 17 00:00:00 2001 From: Bender Date: Thu, 3 Nov 2022 15:50:14 +0100 Subject: [PATCH] feat(changelog): updated changelog command and added call to shipit --- .github/workflows/version.yml | 2 -- README.md | 5 +++++ lib/cli.ts | 5 +++-- lib/cli/changelog.ts | 4 ++-- lib/cli/shipit.ts | 9 ++++++++- package.json | 3 +-- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml index 48c84ea..ad24d97 100644 --- a/.github/workflows/version.yml +++ b/.github/workflows/version.yml @@ -24,8 +24,6 @@ jobs: run: npm ci - name: Build CLI run: npm run build - - name: Update changelog - run: npm run changelog - name: Release run: npm run release env: diff --git a/README.md b/README.md index f6402ae..637deed 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ This library uses Cloudfront, S3, ApiGateway and Lambdas to deploy easily in sec - [Versioning](#versioning) - [Guess](#guess) - [Shipit](#shipit) + - [Changelog](#changelog) ## TL;DR - In your NextJS project, set output to standalone. @@ -186,3 +187,7 @@ Simple CLI command that takes commit message and current version and outputs (st Similar to guess command, however, it automatically tags a commit on current branch and creates release branch for you so hooking up pipelines is as simple as it can be. Version is automatically bumped in common NPM and PHP files (package.json, package-lock.json and composer.json). Simply call `@sladg/next-lambda shipit` on any branch and be done. + +## Changelog + +Simple utility that compares two tags and outputs commits between those two tags. It's intended to be used in CI/CD pipelines to generate changelog for release notes. If you are using using `shipit` command, use `--changelog` flag instead. \ No newline at end of file diff --git a/lib/cli.ts b/lib/cli.ts index 5d98935..5b06573 100644 --- a/lib/cli.ts +++ b/lib/cli.ts @@ -68,10 +68,11 @@ program .option('-r, --releaseBranchPrefix ', 'Prefix for release branch fork.', 'release/') .option('--gitUser ', 'User name to be used for commits.', 'Bender') .option('--gitEmail ', 'User email to be used for commits.', 'bender@bot.eu') + .option('--changelog', 'Generate changelog.', false) .action(async (options) => { console.log('Our config is: ', options) - const { tagPrefix, failOnMissingCommit, releaseBranchPrefix, forceBump, gitUser, gitEmail } = options - wrapProcess(shipitHandler({ tagPrefix, gitEmail, gitUser, failOnMissingCommit, forceBump, releaseBranchPrefix })) + const { tagPrefix, failOnMissingCommit, releaseBranchPrefix, forceBump, gitUser, gitEmail, changelog } = options + wrapProcess(shipitHandler({ tagPrefix, gitEmail, gitUser, failOnMissingCommit, forceBump, releaseBranchPrefix, generateChangelog: changelog })) }) program diff --git a/lib/cli/changelog.ts b/lib/cli/changelog.ts index aeb0bea..6817db8 100644 --- a/lib/cli/changelog.ts +++ b/lib/cli/changelog.ts @@ -15,8 +15,8 @@ export const changelogHandler = async ({ outputFile }: Props) => { const tags = await git.tags() - console.log(log) - console.log(tags) + console.log('Last commits: ', log) + console.log('Last tags: ',tags) const sortedTags = sortTagsDescending(tags.all) diff --git a/lib/cli/shipit.ts b/lib/cli/shipit.ts index d70dc74..1587f65 100644 --- a/lib/cli/shipit.ts +++ b/lib/cli/shipit.ts @@ -1,6 +1,7 @@ import { simpleGit } from 'simple-git' import { skipCiFlag } from '../consts' import { bumpCalculator, bumpMapping, BumpType, findHighestTag, isValidTag, replaceVersionInCommonFiles } from '../utils' +import { changelogHandler } from './changelog' interface Props { gitUser: string @@ -9,9 +10,10 @@ interface Props { failOnMissingCommit: boolean releaseBranchPrefix: string forceBump: boolean + generateChangelog: boolean } -export const shipitHandler = async ({ gitEmail, gitUser, tagPrefix, failOnMissingCommit, forceBump, releaseBranchPrefix }: Props) => { +export const shipitHandler = async ({ gitEmail, gitUser, tagPrefix, failOnMissingCommit, forceBump, releaseBranchPrefix, generateChangelog }: Props) => { const git = simpleGit() // Fetch tags to ensure we have the latest ones. @@ -80,6 +82,11 @@ export const shipitHandler = async ({ gitEmail, gitUser, tagPrefix, failOnMissin const replacementResults = replaceVersionInCommonFiles(currentTag, nextTag) console.log(`Replaced version in files.`, replacementResults) + if (generateChangelog) { + console.log('Generating changelog...') + await changelogHandler({ outputFile: './CHANGELOG.md' }) + } + // Commit changed files (versions) and create a release commit with skip ci flag. await git // diff --git a/package.json b/package.json index ec2da55..d1640c6 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,7 @@ "build": "npm run build:main && npm run build:image", "build:image": "webpack --mode=production", "build:main": "rollup -c", - "release": "node ./dist/cli.js shipit --gitUser @sladg --gitEmail jan@ssoukup.com", - "changelog": "node ./dist/cli.js changelog" + "release": "node ./dist/cli.js shipit --gitUser @sladg --gitEmail jan@ssoukup.com --changelog" }, "dependencies": { "@aws-cdk/aws-apigatewayv2-alpha": "^2.41.0-alpha.0",