Skip to content

Commit

Permalink
Use Changesets for changelog and releases (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens authored Feb 16, 2024
1 parent 1c703bd commit 88fb5da
Show file tree
Hide file tree
Showing 7 changed files with 1,986 additions and 43 deletions.
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "./format.js",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
33 changes: 33 additions & 0 deletions .changeset/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @type {import('@changesets/types').GetReleaseLine}
*/
const getReleaseLine = async (changeset, type, changelogOpts) => {
const [firstLine, ...otherLines] = changeset.summary
.trim()
.split('\n')
.map((l) => l.trimEnd());

let result = `- ${firstLine}`;
if (otherLines.length > 0) {
result += `\n${otherLines.map((l) => ` ${l}`).join('\n')}`;
}

return result;
}

/**
* @type {import('@changesets/types').GetDependencyReleaseLine}
*/
const getDependencyReleaseLine = async (changesets, dependenciesUpdated, changelogOpts) => {
return '';
}

/**
* @type {import('@changesets/types').ChangelogFunctions}
*/
const changelogFunctions = {
getReleaseLine,
getDependencyReleaseLine,
}

module.exports = changelogFunctions;
2 changes: 2 additions & 0 deletions .changeset/funny-mails-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
13 changes: 13 additions & 0 deletions .changeset/post-process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const fs = require('node:fs');
const path = require('node:path');

for (const workspace of require('../package.json').workspaces) {
const changelogPath = path.join(__dirname, '..', workspace, 'CHANGELOG.md');
if (!fs.existsSync(changelogPath)) continue;
let changelog = fs.readFileSync(changelogPath, 'utf8');
changelog = changelog
.replace(/^### Major Changes/gm, '### 💥 Breaking Changes')
.replace(/^### Minor Changes/gm, '### ✨ Features')
.replace(/^### Patch Changes/gm, '### 🐛 Issues');
fs.writeFileSync(changelogPath, changelog);
}
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release
on:
push:
branches:
- main
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm ci --workspaces
- name: Create release PR or publish to npm
id: changesets
uses: changesets/action@v1
with:
commit: "Release"
title: "Release"
version: npm run changeset:version
publish: npx changeset publish
createGithubReleases: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Loading

0 comments on commit 88fb5da

Please sign in to comment.