diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml new file mode 100644 index 00000000..675d845c --- /dev/null +++ b/.github/workflows/release-pr.yml @@ -0,0 +1,52 @@ +name: Release PR ⬆️ + +on: + workflow_dispatch: + inputs: + bump: + description: "Version bump type (patch/minor/major)" + required: true + type: choice + default: patch + options: + - patch + - minor + - major + +jobs: + release-pr: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - uses: fregante/setup-git-user@v2 + + - name: Bump version + run: npm version ${{ inputs.bump }} --no-git-tag-version # --no-git-tag-version: skip auto commit and tag, only modify package.json + + - name: Create Pull Request + id: create-pr + env: + GH_TOKEN: ${{ github.token }} + run: | + VERSION=$(jq -r '.version' package.json) + BRANCH="release/v${VERSION}" + echo "branch=$BRANCH" >> "$GITHUB_OUTPUT" + + LAST_TAG=$(git describe --tags --abbrev=0) + BODY=$(git log ${LAST_TAG}..HEAD --oneline | grep -oE "#[0-9]+" | sort -u | sed 's/^/- /') + + git switch -c "$BRANCH" origin/main + git commit -am "release: v${VERSION}" + git push origin "$BRANCH" + + gh pr create --title "release: v${VERSION}" --body "$BODY" + + - name: Cleanup on failure + if: failure() + run: git push origin --delete "${{ steps.create-pr.outputs.branch }}" || true diff --git a/.github/workflows/tagging.yml b/.github/workflows/tagging.yml index c4505b33..9c2f72d0 100644 --- a/.github/workflows/tagging.yml +++ b/.github/workflows/tagging.yml @@ -1,37 +1,26 @@ name: Tagging 🏷️ on: - workflow_dispatch: - inputs: - bump: - description: "Version bump type (patch/minor/major)" - required: true - type: choice - default: patch - options: - - patch - - minor - - major + pull_request: + types: [closed] + branches: [main] jobs: create-tag: + if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/') runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v6 - - uses: fregante/setup-git-user@v2 - - - name: Bump version - run: npm version ${{ inputs.bump }} - - - name: Push changes - run: git push --follow-tags - - - name: Draft release + - name: Create tag and release env: GH_TOKEN: ${{ github.token }} run: | - NEW_VERSION="v$(jq -r '.version' package.json)" - gh release create $NEW_VERSION --draft --generate-notes + VERSION="v$(jq -r '.version' package.json)" + + git tag "$VERSION" + git push origin "$VERSION" + + gh release create "$VERSION" --draft --generate-notes