Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
chore: add changelogithub config
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolassutter committed Jun 10, 2023
1 parent 653d65a commit 9cbbe7a
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/beta-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Builds
run: pnpm build

- run: npx changelogithub
- run: pnpm changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Builds
run: pnpm build

- run: npx changelogithub
- run: pnpm changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

Expand Down
37 changes: 37 additions & 0 deletions changelogithub.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { defineConfig } from 'changelogithub'
import { execaCommandSync } from 'execa'
import { readPackageSync } from 'read-pkg'

const { version } = readPackageSync()

const { stdout: tagsResult } = execaCommandSync(
'git tag --sort=version:refname',
)

const betaReleaseRegexp = /^v.*-beta\.?\d?/
const mainReleaseRegexp = /^v.*(?<!-beta\.?\d?)$/

const isBetaRelease = betaReleaseRegexp.test(`v${version}`)
const isMainRelease = mainReleaseRegexp.test(`v${version}`)

// Tags from most recent -> oldest
const tags = tagsResult.split('\n').reverse()

// prettier-ignore
const from = isMainRelease
? tags.find((tag) => mainReleaseRegexp.test(tag))
: isBetaRelease
? tags.find((tag) => mainReleaseRegexp.test(tag) || betaReleaseRegexp.test(tag))
: undefined

if (!from) {
throw new Error('Unable to find previous release.')
}

export default defineConfig({
/**
* When pushing a new main release, the `from` should be the last main release tag (and not a beta version)
* When pushing a new beta release, the `from` should be the last release (beta or main)
*/
from,
})
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@
"@types/node": "^18.16.17",
"@types/prettier": "^2.7.3",
"bumpp": "^9.1.1",
"changelogithub": "^0.12.11",
"eslint": "^8.42.0",
"generator": "link:@types/@babel/generator",
"husky": "^8.0.3",
"prettier": "^2.8.8",
"read-pkg": "^8.0.0",
"traverse": "link:@types/@babel/traverse",
"tsx": "^3.12.7",
"type-fest": "^3.11.1",
Expand All @@ -93,6 +95,7 @@
"inquirer": "^9.2.7",
"local-pkg": "^0.4.3",
"lodash": "^4.17.21",
"ofetch": "^1.1.0",
"tsup": "^6.7.0",
"yaml": "^2.3.1"
}
Expand Down
Loading

0 comments on commit 9cbbe7a

Please sign in to comment.