Release with Changeset #16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release with Changeset | |
on: | |
workflow_dispatch: | |
branches: | |
- main | |
jobs: | |
release: | |
name: Create Release | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ github.token }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- name: Install dependencies | |
run: npm ci | |
- name: Commit Changeset Version Bump | |
id: changesets | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
npx changeset version | |
if [ -n "$(git status --porcelain)" ]; then | |
git add . | |
git commit -m "Version packages" | |
else | |
echo "No changes to commit" | |
fi | |
- name: Create Version Bump Branch and Push | |
if: steps.changesets.outputs.commit | |
run: | | |
BRANCH_NAME="release-version-bump-$(date +'%Y%m%d%H%M%S')" | |
git checkout -b "$BRANCH_NAME" | |
git push origin "$BRANCH_NAME" | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
- name: Open Pull Request for Version Bump | |
if: steps.changesets.outputs.commit | |
uses: peter-evans/create-pull-request@v4 | |
with: | |
token: ${{ github.token }} | |
base: main | |
head: ${{ steps.create_version_bump_branch.outputs.BRANCH_NAME }} | |
title: "Version packages" | |
body: "This pull request contains version bumps for packages." | |
- name: Check Version Change | |
id: version_check | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: | | |
CURRENT_VERSION=$(node -p "require('./package.json').version") | |
LATEST_RELEASE=$(gh release list --limit 1 | cut -f1) | |
LATEST_VERSION=${LATEST_RELEASE#v} | |
echo "Current version: ${CURRENT_VERSION}" | |
echo "Latest release: ${LATEST_VERSION}" | |
if [ "$(printf '%s\n' "$LATEST_VERSION" "$CURRENT_VERSION" | sort -V | tail -n1)" = "$CURRENT_VERSION" ] && [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then | |
echo "Version increment detected" | |
echo "should_release=true" >> $GITHUB_OUTPUT | |
else | |
echo "No version increment detected or versions are equal" | |
echo "should_release=false" >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
- name: Create GitHub Release | |
if: steps.version_check.outputs.should_release == 'true' | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: | | |
CURRENT_VERSION=$(node -p "require('./package.json').version") | |
gh release create "v${CURRENT_VERSION}" \ | |
--title "v${CURRENT_VERSION}" \ | |
--generate-notes |