Skip to content

Commit

Permalink
fix: Update release action (#59)
Browse files Browse the repository at this point in the history
Changes made:
- Updated PR template to describe categories and add `Release Note` section
- Split changelog generation into smaller steps
- Update GH release step to use a correct output

[category:Infrastructure]
  • Loading branch information
RayRedGoose authored Oct 24, 2023
1 parent b277648 commit b7d779f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
## Release Category

<!-- Documentation, Infrastructure, Tokens -->
<!-- For packiage specific changes, add package name before category: Web Tokens, Web Documentation, etc -->

### Release Note
Optional release note message. Add `⚠️ BREAKING CHANGES:` before message if it's a breaking change.
Changelog and release summaries will contain a pull request title. This section will add additional notes under that title. This section is not a summary, but something extra to point out in release notes. An example might be calling out breaking changes in a labs component or minor visual changes that need visual regression updates. Remove this section if no additional release notes are required.

---

Expand Down
19 changes: 13 additions & 6 deletions .github/workflows/release-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,20 @@ jobs:
fromRef: '@workday/canvas-tokens-web@${{steps.previous-tag.outputs.tag}}'
toRef: 'main'
tagName: 'new-release'

- name: Filter changes
id: filter-changes
run: echo "changelog=$(node scripts/utils/filter-changes.js)" >> $GITHUB_OUTPUT
env:
PACKAGE: web
CHANGESET_BODY: ${{steps.changeset.outputs.body}}

- name: Update Changelog
run: npx ts-node scripts/utils/update-changelog.ts
- name: Create pre-changelog for versioning
run: npx ts-node scripts/utils/create-prechangelog.ts
env:
PACKAGE: canvas-tokens-web
PACKAGE: web
VERSION: ${{inputs.version}}
CHANGESET_BODY: ${{steps.changeset.outputs.body}}
CHANGESET_BODY: ${{steps.filter-changes.outputs.changelog}}

- name: Bump package
run: npx changeset version
Expand Down Expand Up @@ -85,14 +92,14 @@ jobs:
tags: true

## Create a release on Github.
- name: Create Release
- name: Create GH Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "@workday/canvas-tokens-web@${{steps.new-tag.outputs.tag}}"
name: "@workday/canvas-tokens-web@${{steps.new-tag.outputs.tag}}"
body: ${{steps.changeset.outputs.body}}
body: ${{steps.filter-changes.outputs.changelog}}
draft: false
prerelease: false

Expand Down
16 changes: 16 additions & 0 deletions scripts/utils/create-prechangelog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import path from 'path';
import fs from 'fs';

const {CHANGESET_BODY = ``, PACKAGE = '', VERSION} = process.env;

const header = `---
'@workday/canvas-tokens-${PACKAGE}': ${VERSION || 'patch'}
---`;

const changeset = CHANGESET_BODY.replace(/<br>/g, '\n');

fs.writeFileSync(
path.join(path.resolve('./'), './.changeset/pre-changelog.md'),
`${header}\n\n${changeset}`,
'utf8'
);
25 changes: 25 additions & 0 deletions scripts/utils/filter-changes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const {CHANGESET_BODY = '', PACKAGE = ''} = process.env;

const allowedTitles = [PACKAGE, 'all', 'other', 'infrastructure', 'documentation'];

// Regex to find blocks that starts from package name or non-specified categories
const titleRegex = new RegExp(`^# (${allowedTitles.join('|')})`, 'i');

// Canvas Kit's changelog generator creates changelog based on all commits
// For a given package changelog should only contain related chages
// The default section name headings to "Components",
// so we're updating that default with use "Other" instead.
// Changelog sections are sorted alphabetically
const changelogBody = CHANGESET_BODY.replace('# Components', '# Other')
.split('##')
.filter(block => titleRegex.test(block))
.sort((a, b) => (a > b ? 1 : -1))
.map(b =>
// Removes extra line breaks and changes a section heading to a bold text
b.replace(/\n+$/g, '').replace(/# [a-zA-Z0-9_ ]*\n/g, a => `**${a.replace(/# |\n/g, '')}**\n`)
)
.join('\n\n');

const oneLineChangelog = changelogBody.replace(/\n/g, '<br>');

console.log(oneLineChangelog);
33 changes: 0 additions & 33 deletions scripts/utils/update-changelog.ts

This file was deleted.

0 comments on commit b7d779f

Please sign in to comment.