diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml new file mode 100644 index 0000000..ac8e722 --- /dev/null +++ b/.github/workflows/release-plz.yml @@ -0,0 +1,33 @@ +name: release-plz + +permissions: + pull-requests: write + contents: write + +on: + workflow_dispatch: + push: + branches: + - main + - release-plz + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_CONFIG_FUND: false + +concurrency: + group: release-plz + +jobs: + release-plz: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + token: ${{ secrets.GITHUB_TOKEN }} + - uses: jdx/mise-action@v2 + - run: mise run release-plz + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/mise.toml b/mise.toml index 4351116..4424867 100644 --- a/mise.toml +++ b/mise.toml @@ -4,6 +4,9 @@ tasks.test.run = ["npm run all"] tasks.lint = "bun run lint" tasks."lint:fix" = "bun run format:write" tasks.version = "npm version" +tasks.release-plz = "./scripts/release-plz.sh" [tools] node = '24' +git-cliff = 'latest' +gh = 'latest' diff --git a/scripts/release-plz.sh b/scripts/release-plz.sh new file mode 100755 index 0000000..5ffd417 --- /dev/null +++ b/scripts/release-plz.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# shellcheck shell=bash +set -euxo pipefail + +# Get current version from package.json +cur_version="$(jq -r .version package.json)" + +# Check if this version has already been released +released_versions="$(git tag --list | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$')" +if echo "$released_versions" | grep -q "^v$cur_version$"; then + echo "Version $cur_version already released" + exit 0 +fi + +# Get the next version and changelog from git-cliff +version="$(git cliff --bumped-version)" +changelog="$(git cliff --bump --unreleased --strip all)" + +if [ "${MISE_DRY_RUN:-}" == 1 ]; then + echo "version: $version" + echo "changelog: $changelog" + exit 0 +fi + +# Update changelog +git cliff --bump -o CHANGELOG.md + +# Update package.json version +npm version "${version#v}" --no-git-tag + +# Build the project +npm run all + +# Configure git for automated commits +git config user.name mise-en-dev +git config user.email 123107610+mise-en-dev@users.noreply.github.com + +# Add all changes +git add package.json package-lock.json CHANGELOG.md dist/ + +# Create release branch and commit +git checkout -B release +git commit -m "chore: release $version" + +# Push to release branch +git push origin release --force + +# Create or update PR +gh pr create --title "chore: release $version" --body "$changelog" --label "release" || + gh pr edit --title "chore: release $version" --body "$changelog"