This action for Changesets runs the Snapshot workflow for your repository, based on changes done in Pull Requests.
This action is helpful if you wish to create an automated release flow in trunk branch, release branches, and PRs.
The following flow is being executed:
- Check for available
changeset
files in the PR. - Runs
version
flow insnapshot
mode (--snapshot
flag,x.y.z-{commit-hash}-(develop|branch-name)
schema) and stable mode (x.y.z
schema). - Calculate changes which packages were changed and should be released.
- Runs user script for build/preparation for the release.
- Create commit (and annotated tags) with changed versions, removed changesets and updated changelogs. By default, works only in
stable
mode, could be overridden manually. - Publishes a GitHub release with the list of releases done. By default, works only in
stable
mode, could be overridden manually. - Publishes a GitHub comment on the Pull Request, with the list of releases done.
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"snapshot": {
"useCalculatedVersion": true,
// this part is important. It will generate a version like 1.2.3-d3d32d-branch-name
"prereleaseTemplate": "{commit}-{tag}"
},
"updateInternalDependencies": "patch",
"ignore": []
}
mode
: - "snapshot | stable. Default is snapshot. Snapshot releases are meant to be used for canary releases (could be used in trunk branch and feature branches), and stable releases are meant to be used for stable releases. required: trueprepare-script
- A custom, user-provided script, that is being executed afterversion
script. Usually, this is where yourbuild
script goes.cwd
- Changes node'sprocess.cwd()
if the project is not located on the root. Default toprocess.cwd()
setup-git-user
- Sets up the git user for commits as"github-actions[bot]"
. Default totrue
commit
- Release commit. Works only instable
mode. Default totrue
instable
mode.tag
- Release tag. Works only instable
mode. Default totrue
instable
mode.github-release
- A boolean value to indicate whether to create Github releases. Default totrue
instable
mode.comment
- By default, this action will add comment in PR with information about packages and theirs versions to be released.release-codenames
- An array of dictionaries that containing the words to use for generating the release codename (e.g. adjectives, animals, colors, countries, languages, names, starWars).snapshot-tag
- A custom tag for snapshot releases. Default to current branch name.
upgraded
- A boolean value to indicate whether a publishing is happened or notupgraded-packages
- A JSON array to present the upgraded packages. The format is[{"name": "@xx/xx", "version": "1.2.0" "path": "apps/web", "config": { ...config field from package.json }}, {"name": "@xx/xy", "version": "0.8.9", "path": "apps/api", "config": { ... config field from package.json }}]
Create a file at .github/workflows/ci.yml
with the following content.
name: CI
on:
push:
branches: ["main"]
pull_request:
types: [opened, synchronize]
env:
NPM_AUTH_TOKEN: ${{ secrets.GH_PAT }}
jobs:
build:
name: Build and Test
outputs:
upgraded: ${{ steps.release.outputs.upgraded }}
upgraded-packages: ${{ steps.release.outputs.upgradedPackages }}
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16
cache: "pnpm"
# this is where you do your regular setup, dependencies installation and so on
- name: Release
uses: "edenlabllc/changesets-action@v1"
with:
mode: ${{ startsWith(github.ref_name, 'release/') != true && 'snapshot' || 'stable' }}
release-codenames: |
colors
animals
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub Token