Skip to content

Commit

Permalink
feat(changelog): updated changelog command and added call to shipit
Browse files Browse the repository at this point in the history
  • Loading branch information
sladg committed Nov 3, 2022
1 parent 5ad0e7c commit 301c7c3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
5 changes: 3 additions & 2 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ program
.option('-r, --releaseBranchPrefix <prefix>', 'Prefix for release branch fork.', 'release/')
.option('--gitUser <user>', 'User name to be used for commits.', 'Bender')
.option('--gitEmail <email>', '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
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 8 additions & 1 deletion lib/cli/shipit.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
//
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 301c7c3

Please sign in to comment.