diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index cffaa5b..c679439 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -2,18 +2,26 @@ name: "Release New Version" on: workflow_dispatch: + inputs: + release_title: + description: "Title for the release" + required: true + release_body: + description: "Additional notes (optional)" + required: false + default: "" permissions: contents: write jobs: publish: - name: "Publish to NPM" runs-on: ubuntu-latest - steps: - name: "Checkout source code" uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: "Set up Node.js" uses: actions/setup-node@v3 @@ -29,7 +37,63 @@ jobs: - name: "Get version from package.json" id: get_version - run: echo "version=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + run: | + VERSION="v$(node -p 'require("./package.json").version')" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Get previous Git tag + id: get_previous_tag + run: | + VERSION="${{ steps.get_version.outputs.version }}" + PREV_TAG=$(git tag --sort=-creatordate | grep '^v' | grep -v "$VERSION" | head -n 1) + echo "previous_tag=$PREV_TAG" >> $GITHUB_OUTPUT + + - name: Fetch and categorize merged PRs + id: fetch_prs + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -e + PREVIOUS_TAG=${{ steps.get_previous_tag.outputs.previous_tag }} + if [ -z "$PREVIOUS_TAG" ]; then + echo "pr_list=No previous tag found to compare PRs." >> $GITHUB_OUTPUT + exit 0 + fi + PREVIOUS_SHA=$(git rev-list -n 1 $PREVIOUS_TAG) + PREVIOUS_DATE=$(git show -s --format=%cI $PREVIOUS_SHA) + CURRENT_DATE=$(git show -s --format=%cI HEAD) + echo "Fetching PRs merged between $PREVIOUS_DATE and $CURRENT_DATE" + + RAW_PRS=$(gh pr list --state merged --search "merged:${PREVIOUS_DATE}..${CURRENT_DATE}" \ + --json number,title,url \ + --jq '.[] | "- [#\(.number)](\(.url)) \(.title)"') + + if [ -z "$RAW_PRS" ]; then + echo "pr_list=No pull requests were merged during this release." >> $GITHUB_OUTPUT + exit 0 + fi + + ADDED="" + FIXED="" + while IFS= read -r pr; do + if echo "$pr" | grep -iq "fix"; then + FIXED+="$pr"$'\n' + else + ADDED+="$pr"$'\n' + fi + done <<< "$RAW_PRS" + + BODY="" + if [ -n "$ADDED" ]; then + BODY="$BODY### Added"$'\n'"$ADDED" + fi + if [ -n "$FIXED" ]; then + BODY="$BODY"$'\n'"### Fixed"$'\n'"$FIXED" + fi + + echo "pr_list<> $GITHUB_OUTPUT + echo "$BODY" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT - name: "Set Git user name and email" run: | @@ -51,11 +115,12 @@ jobs: uses: actions/create-release@v1 with: tag_name: ${{ steps.get_version.outputs.version }} - release_name: Release ${{ steps.get_version.outputs.version }} + release_name: ${{ github.event.inputs.release_title }} body: | - ``` - • See CHANGELOG.md for details - • Published by ${{ github.actor }} - ``` + ${{ github.event.inputs.release_body }} + + ${{ steps.fetch_prs.outputs.pr_list }} + + Published by ${{ github.actor }} env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file