Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add do-release to support changeset #27

Merged
merged 10 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Creating an Issue

To create an issue, please follow one of [these issue templates](https://github.com/Workday/canvas-kit-actions/issues/new/choose).
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: 🐛 Bug report
labels: 'bug'
about: Submit a bug report
---

## 🐛 Bug Report

### Expected Behavior

<!-- What's the behavior you're expecting to see? -->

### Actual Behavior

<!-- What's actually happening instead? -->

### Steps to Reproduce

<!-- Please provide clear steps to reproduce the issue. -->
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: 🚀 Feature Proposal
labels: 'feature'
about: Submit a proposal for a new feature
---

## 🚀 Feature Proposal

<!-- Please write a clear and concise description of what the feature is. -->

### Motivation

<!-- Please outline the motivation for the proposal. -->

### Acceptance Criteria

<!-- External contributors can skip this. This can be added by maintainers. -->

<!-- - [ ] Add checklist items here-->
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: 🤔 Question
label: 'question'
about: Submit a question about CK Analytics
---

## 🤔 Question

<!-- Please provide a clear question with sufficient context. -->
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/spike.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: 🔍 Spike
label: 'spike'
about: Submit a proposal for technical exploration
---

## 🔍 Spike

<!-- Please provide a short summary of the spike. -->

### Questions

<!-- What questions would be answered once this spike was completed? -->

### Documentation

<!-- How should we document what is learned from this exploration? -->

## Existing Issues

<!-- Please list any existing issues related to this spike. -->
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/suggestion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: 💡 Suggestion
labels: 'suggestion'
about: Submit a suggestion
---

## 💡 Suggestion

<!-- Please provide a clear and concise description of your suggestion. -->

### Motivation

<!-- Please outline the motivation for this suggestion. -->

### Example

<!-- Please provide an example of this suggestion in practice. -->
26 changes: 26 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Issue

<!-- Add an issue number and link the PR with a keyword: "Fixes", "Resolves", or "Closes" -->
<!-- Resolves #123 -->

## Summary

<!-- Give a brief description of what this PR does. -->

---

<!-- For the reviewer -->

## Where Should the Reviewer Start?

<!-- `packages/canvas-assets-docs/index.ts` -->

## Testing Manually

<!-- List steps to test this locally. -->

## Thank You GIF

<!-- _Share a fun [gif](https://giphy.com) to say thanks to your reviewer:_ -->

<!-- ![](https://media.giphy.com/media/mCRJDo24UvJMA/giphy.gif) -->
97 changes: 96 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
Makes release based on given version or patch as default.

#### Example

```yml
jobs:
main:
Expand All @@ -98,4 +99,98 @@ jobs:
publish_token: ${{ secrets.NPM_CI_PUBLISH_TOKEN }}
chromatic_project_token: ${{ secrets.CHROMATIC_APP_CODE }}
version: 'minor'
```
```

### `do-release`

#### Purpose

This GitHub Action automates the release or prerelease process, supporting version bumping, changelog attachment, and publishing. It integrates with **changeset** by default but can be customized for other workflows.

#### Inputs

| Input Name | Required | Default | Description |
| --------------------- | -------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `buildScript` | ❌ No | `yarn build` | Command to build the package before release. Defaults to `yarn build`. |
| `changelog` | ❌ No | `""` | Text for the changelog to include in the release. |
| `commitScript` | ❌ No | N/A | Command to commit changes (e.g., version bumps, changelogs). If not provided, the commit message defaults to: `"chore: Release <package> v<version> [skip release]"`. |
| `ghToken` | ✅ Yes | N/A | GitHub token with read/write permissions for release operations. |
| `package` | ✅ Yes | N/A | The package name for correct versioning. |
| `packagePath` | ✅ Yes | N/A | Path to the folder of the package to be released. |
| `preid` | ❌ No | N/A | Preid to specify a prerelease version tag (e.g., `beta`, `rc`). |
| `prerelease` | ❌ No | `false` | Flag to indicate whether this is a prerelease. If `true`, both `preid` and `version` must be provided. |
| `releaseScript` | ❌ No | `npx changeset publish` | Command to perform the release action (e.g., deploy or publish). Defaults to `npx changeset publish`. |
| `skipCreateChangelog` | ❌ No | N/A | If set to `true`, changelog creation is skipped. |
| `skipCreateTag` | ❌ No | `true` | If set to `true`, git tag creation (`package@version`) is skipped. Defaults to `true`, as Changeset auto-creates tags. |
| `skipGithubRelease` | ❌ No | N/A | If set to `true`, skips creating a GitHub release. |
| `skipPush` | ❌ No | N/A | If set to `true`, skips pushing the created commit and tag to the origin branch. |
| `skipTagsPush` | ❌ No | N/A | If set to `true`, skips pushing the created tags to the origin branch. |
| `version` | ✅ Yes | N/A | The version type for the release: `patch`, `minor`, or `major`. |
| `versionScript` | ❌ No | `npx changeset version` | Command to bump the package version. Defaults to `npx changeset version`. |

#### Outputs

| Output Name | Description |
| ----------------- | ---------------------------- |
| `releasedVersion` | The released version number. |

#### Usage

**Standard Release**

```yaml
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Release package
uses: Workday/canvas-kit-actions/do-release@v1
with:
ghToken: ${{ secrets.GITHUB_TOKEN }}
version: 'minor'
package: 'my-package'
packagePath: 'packages/my-package'
buildScript: 'yarn build'
commitScript: 'git commit -am "chore: Release minor version"'
releaseScript: 'yarn release'
versionScript: 'npx changeset version'
skipCreateTag: true
skipGithubRelease: true
```

**Prerelease (Beta)**

```yaml
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Beta Release
uses: Workday/canvas-kit-actions/do-release@v1
with:
ghToken: ${{ secrets.GITHUB_TOKEN }}
version: 'minor'
package: 'my-package'
packagePath: 'packages/my-package'
prerelease: true
preid: 'beta'
buildScript: 'yarn build'
commitScript: 'git commit -am "chore: Release beta version"'
releaseScript: 'yarn release'
versionScript: 'npx changeset version'
skipGithubRelease: true
```

#### Notes

- `ghToken` must have **read/write** permissions to perform release operations.
- When `prerelease` is `true`, ensure `preid` and `version` are set (e.g., `beta`, `minor`).
- The action supports overriding default scripts to adapt to various publishing strategies.
- For npm users, replace `yarn` commands with appropriate `npm` equivalents.
- By default, git tags are skipped (`skipCreateTag: true`), since Changeset auto-generates tags. Set to `false` if you prefer manual tag creation.
149 changes: 149 additions & 0 deletions do-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: 'Release'
description: 'Action to do release or prerelease. By default this release action rely on changeset, but all scripts can be modified to use any other tool.'
author: 'Workday'
inputs:
buildScript:
required: false
description: 'Command to build the package before release. Defaults to `yarn build`.'
default: 'yarn build'
changelog:
required: false
description: 'Text for the changelog to include in the release.'
default: ''
commitScript:
required: false
description: 'Command to commit changes, typically used for committing version bumps or changelogs. If no provided commit will be released with the next message: `"chore: Release <package> v<version> [skip release]"`'
ghToken:
required: true
description: 'GitHub token with read/write permissions for release operations.'
package:
required: true
description: 'The package name for correct versioning.'
packagePath:
required: true
description: 'Path to the folder of the package to be released.'
preid:
required: false
description: 'Preid to specify a prerelease version tag.'
prerelease:
required: false
description: 'Flag to indicate whether this is a prerelease. If `true`, `preid` and `version` must be specified for prerelease.'
releaseScript:
required: false
default: 'npx changeset publish'
description: 'Command to perform the release action, such as deploying or publishing the package. Default to `npx changeset publish`.'
skipCreateChangelog:
required: false
description: 'If set to`true`, changelog creation is skipped.'
skipCreateTag:
required: false
default: true
description: 'Create git tag in the `package@version` format if set to `true`. Skipped if set to false. Defaults to `true`. Changeset is auto create tag.'
skipGithubRelease:
required: false
description: 'Skip Github release if set to `true`.'
skipPush:
required: false
description: 'Skip git push of the created commit and tag to the origin branch if set to `true`.'
skipTagsPush:
required: false
description: 'Skip git push of the created tags to the origin branch if set to `true`.'
version:
required: true
description: 'The version to specify for the prerelease: patch, minor or major.'
versionScript:
required: false
description: 'Command to bump the version of the package. Defaults to `npx changeset version`.'
default: 'npx changeset version'

outputs:
releasedVersion:
description: 'The released version number.'
value: ${{ steps.get_version.outputs.version }}

runs:
using: 'composite'
steps:
- name: Get version from package.json
id: get_old_version
shell: bash
run: echo "version=$(jq -r '.version' ${{ steps.get_path.outputs.path }})" >> "$GITHUB_OUTPUT"

- name: Generate Changeset
uses: Workday/canvas-kit-actions/generate-changeset@v1
id: changeset
with:
token: ${{ inputs.ghToken }}
fromRef: '@workday/canvas-tokens-web@${{ steps.get_old_version.outputs.version }}'
toRef: ${{ github.ref_name }}
tagName: release

- name: Enter pre mode
if: ${{ inputs.prerelease == 'true' }}
shell: bash
run: npx changeset pre enter ${{ inputs.preid }}

- name: Generate pre-changelog
if: ${{ contains(inputs.versionScript, 'changeset') && inputs.skipCreateChangelog != 'true' }}
shell: bash
run: "echo \"---\n'${{ inputs.package }}': ${{ inputs.version }}\n---\n${{ inputs.changelog || steps.changeset.outputs.body }}\" > .changeset/pre-changelog.md"

- name: Bump version
shell: bash
run: ${{ inputs.versionScript }}

- name: Get package.json path
id: get_path
shell: bash
run: echo "path=${{ inputs.packagePath }}/package.json" >> "$GITHUB_OUTPUT"

- name: Get version from package.json
id: get_version
shell: bash
run: echo "version=$(jq -r '.version' ${{ steps.get_path.outputs.path }})" >> "$GITHUB_OUTPUT"

- name: Build new package
if: ${{ inputs.buildScript }}
shell: bash
run: ${{ inputs.buildScript }}

- name: Release
shell: bash
run: ${{ inputs.releaseScript }}

- name: Create tag
id: create_tag
shell: bash
run: echo "tag=${{ inputs.package }}@${{ steps.get_version.outputs.version }}" >> "$GITHUB_OUTPUT"

- name: Commit changes
if: ${{ !inputs.commitScript }}
shell: bash
run: |
git add ${{ inputs.packagePath }}
git commit -m "chore: Release ${{ inputs.package }} v${{ steps.get_version.outputs.version }} [ci skip]"

- name: Create git release tag
if: ${{ inputs.skipCreateTag != 'true' }}
shell: bash
run: git tag -a ${{ steps.create_tag.outputs.tag }} -m "${{ steps.create_tag.outputs.tag }}"

- name: Push changes
if: ${{ inputs.skipPush != 'true' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ inputs.ghToken }}
branch: ${{ github.ref }}
tags: ${{ inputs.skipTagsPush != 'true' }}

- name: Create Github Release
if: ${{ inputs.skipGithubRelease != 'true' }}
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ inputs.ghToken }}
with:
tag_name: ${{steps.create_tag.outputs.tag}}
name: ${{steps.create_tag.outputs.tag}}
body: ${{ inputs.changelog }}
draft: false
prerelease: ${{ inputs.prerelease }}