feat: add github stars, issues and created at to comparison page (#2479) #343
This file contains hidden or 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-pr | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| release-pr: | |
| name: π Create or update release PR | |
| runs-on: ubuntu-slim | |
| if: github.repository == 'npmx-dev/npmx.dev' | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - uses: voidzero-dev/setup-vp@8ecb39174989ce55af90f45cf55b02738599831d # v1 | |
| with: | |
| node-version: lts/* | |
| run-install: false | |
| - name: π Check for unreleased commits | |
| id: check | |
| run: | | |
| git fetch origin release | |
| COMMITS=$(git log origin/release..origin/main --oneline) | |
| if [ -z "$COMMITS" ]; then | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| echo "No new commits to release" | |
| else | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| echo "Found unreleased commits:" | |
| echo "$COMMITS" | |
| fi | |
| - name: π’ Determine next version | |
| if: steps.check.outputs.skip == 'false' | |
| id: version | |
| run: | | |
| VERSION_JSON=$(node scripts/next-version.ts) | |
| CURRENT_VERSION=$(echo "$VERSION_JSON" | jq -r .current) | |
| NEXT_VERSION=$(echo "$VERSION_JSON" | jq -r .next) | |
| FROM_REF=$(echo "$VERSION_JSON" | jq -r .from) | |
| echo "current=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "next=v${NEXT_VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "from=$FROM_REF" >> "$GITHUB_OUTPUT" | |
| - name: π Generate changelog body | |
| if: steps.check.outputs.skip == 'false' | |
| id: changelog | |
| env: | |
| CURRENT_VERSION: ${{ steps.version.outputs.current }} | |
| NEXT_VERSION: ${{ steps.version.outputs.next }} | |
| FROM_REF: ${{ steps.version.outputs.from }} | |
| run: | | |
| # Categorize commits | |
| FEATURES="" | |
| FIXES="" | |
| CHORES="" | |
| OTHER="" | |
| while IFS= read -r line; do | |
| [ -z "$line" ] && continue | |
| SHA=$(echo "$line" | cut -d' ' -f1) | |
| MSG=$(echo "$line" | cut -d' ' -f2-) | |
| ENTRY="- $MSG (\`$SHA\`)" | |
| if echo "$MSG" | grep -qE '^feat(\(|:)'; then | |
| FEATURES="${FEATURES}${ENTRY}\n" | |
| elif echo "$MSG" | grep -qE '^fix(\(|:)'; then | |
| FIXES="${FIXES}${ENTRY}\n" | |
| elif echo "$MSG" | grep -qE '^(chore|ci|build|perf|refactor|style|test|docs)(\(|:)'; then | |
| CHORES="${CHORES}${ENTRY}\n" | |
| else | |
| OTHER="${OTHER}${ENTRY}\n" | |
| fi | |
| done <<< "$(git log "$FROM_REF"..origin/main --oneline --no-merges)" | |
| # Strip the leading 'v' for display | |
| DISPLAY_NEXT="${NEXT_VERSION#v}" | |
| # Build the PR body | |
| BODY="This PR will deploy the following changes to production (\`npmx.dev\`).\n\n" | |
| BODY="${BODY}**Next version: \`${NEXT_VERSION}\`** (current: \`v${CURRENT_VERSION}\`)\n\n" | |
| if [ -n "$FEATURES" ]; then | |
| BODY="${BODY}### Features\n\n${FEATURES}\n" | |
| fi | |
| if [ -n "$FIXES" ]; then | |
| BODY="${BODY}### Fixes\n\n${FIXES}\n" | |
| fi | |
| if [ -n "$CHORES" ]; then | |
| BODY="${BODY}### Other Changes\n\n${CHORES}\n" | |
| fi | |
| if [ -n "$OTHER" ]; then | |
| BODY="${BODY}### Uncategorized\n\n${OTHER}\n" | |
| fi | |
| BODY="${BODY}---\n\n" | |
| BODY="${BODY}> Merging this PR will:\n" | |
| BODY="${BODY}> - Deploy to \`npmx.dev\` via Vercel\n" | |
| BODY="${BODY}> - Create a \`${NEXT_VERSION}\` tag and GitHub Release\n" | |
| BODY="${BODY}> - Publish \`npmx-connector@${DISPLAY_NEXT}\` to npm" | |
| # Write body to file, truncating if needed (GitHub limits PR body to 65536 chars) | |
| echo -e "$BODY" > /tmp/pr-body.md | |
| if [ "$(wc -c < /tmp/pr-body.md)" -gt 60000 ]; then | |
| COMMIT_COUNT=$(git log "$FROM_REF"..origin/main --oneline --no-merges | wc -l) | |
| COMPARE_URL="https://github.com/npmx-dev/npmx.dev/compare/${FROM_REF}...main" | |
| TRUNCATED="This PR will deploy the following changes to production (\`npmx.dev\`).\n\n" | |
| TRUNCATED="${TRUNCATED}**Next version: \`${NEXT_VERSION}\`** (current: \`v${CURRENT_VERSION}\`)\n\n" | |
| TRUNCATED="${TRUNCATED}> **${COMMIT_COUNT} commits** are included in this release. The full changelog is too large to display here.\n>\n" | |
| TRUNCATED="${TRUNCATED}> [View full diff on GitHub](${COMPARE_URL})\n\n" | |
| TRUNCATED="${TRUNCATED}---\n\n" | |
| TRUNCATED="${TRUNCATED}> Merging this PR will:\n" | |
| TRUNCATED="${TRUNCATED}> - Deploy to \`npmx.dev\` via Vercel\n" | |
| TRUNCATED="${TRUNCATED}> - Create a \`${NEXT_VERSION}\` tag and GitHub Release\n" | |
| TRUNCATED="${TRUNCATED}> - Publish \`npmx-connector@${DISPLAY_NEXT}\` to npm" | |
| echo -e "$TRUNCATED" > /tmp/pr-body.md | |
| fi | |
| - name: π Create or update release PR | |
| if: steps.check.outputs.skip == 'false' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NEXT_VERSION: ${{ steps.version.outputs.next }} | |
| run: | | |
| EXISTING_PR=$(gh pr list --base release --head main --state open --json number --jq '.[0].number') | |
| if [ -n "$EXISTING_PR" ]; then | |
| gh pr edit "$EXISTING_PR" \ | |
| --title "chore: release ${NEXT_VERSION}" \ | |
| --body-file /tmp/pr-body.md | |
| echo "Updated existing PR #${EXISTING_PR}" | |
| else | |
| gh pr create \ | |
| --base release \ | |
| --head main \ | |
| --title "chore: release ${NEXT_VERSION}" \ | |
| --body-file /tmp/pr-body.md \ | |
| --label "release" | |
| echo "Created new release PR" | |
| fi |