|
| 1 | +name: Version Bump |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + |
| 7 | +jobs: |
| 8 | + version-bump: |
| 9 | + name: Version Bump |
| 10 | + runs-on: ubuntu-latest |
| 11 | + if: "!contains(github.event.head_commit.message, 'skip ci') && !contains(github.event.head_commit.message, 'chore(release)')" |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} |
| 19 | + |
| 20 | + - name: Setup Node.js |
| 21 | + uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: 20 |
| 24 | + |
| 25 | + - name: Setup pnpm |
| 26 | + uses: pnpm/action-setup@v3 |
| 27 | + with: |
| 28 | + version: 10.8.0 |
| 29 | + |
| 30 | + - name: Get pnpm store directory |
| 31 | + id: pnpm-cache |
| 32 | + shell: bash |
| 33 | + run: | |
| 34 | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT |
| 35 | + |
| 36 | + - name: Setup pnpm cache |
| 37 | + uses: actions/cache@v4 |
| 38 | + with: |
| 39 | + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} |
| 40 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 41 | + restore-keys: | |
| 42 | + ${{ runner.os }}-pnpm-store- |
| 43 | + |
| 44 | + - name: Install dependencies |
| 45 | + run: pnpm install |
| 46 | + |
| 47 | + - name: Lint |
| 48 | + run: pnpm lint |
| 49 | + |
| 50 | + - name: Build |
| 51 | + run: pnpm build |
| 52 | + |
| 53 | + - name: Test |
| 54 | + run: pnpm test:ci |
| 55 | + |
| 56 | + - name: Test Release (Dry Run) |
| 57 | + env: |
| 58 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} |
| 59 | + run: pnpm release:dry-run |
| 60 | + |
| 61 | + - name: Update or Create GitHub Release Draft |
| 62 | + env: |
| 63 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} |
| 64 | + run: | |
| 65 | + # Get the next version from semantic-release |
| 66 | + VERSION=$(npx semantic-release --dry-run | grep -oP 'The next release version is \K[0-9]+\.[0-9]+\.[0-9]+' || echo "") |
| 67 | + |
| 68 | + if [ -z "$VERSION" ]; then |
| 69 | + echo "No version change detected, skipping release creation" |
| 70 | + exit 0 |
| 71 | + fi |
| 72 | + |
| 73 | + echo "Next version will be: $VERSION" |
| 74 | + |
| 75 | + # Update package.json version |
| 76 | + npm version $VERSION --no-git-tag-version |
| 77 | + |
| 78 | + # Generate changelog for this version |
| 79 | + npx semantic-release --dry-run --no-ci > release-notes.md |
| 80 | + |
| 81 | + # Extract just the release notes section |
| 82 | + sed -n '/# \[/,/^$/p' release-notes.md > changelog-extract.md |
| 83 | + |
| 84 | + # Get PR information |
| 85 | + PR_NUMBER=$(echo "${{ github.event.head_commit.message }}" | grep -oP '#\K[0-9]+' || echo "") |
| 86 | + PR_TITLE="" |
| 87 | + PR_BODY="" |
| 88 | + |
| 89 | + if [ ! -z "$PR_NUMBER" ]; then |
| 90 | + PR_INFO=$(gh pr view $PR_NUMBER --json title,body || echo "{}") |
| 91 | + PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // ""') |
| 92 | + PR_BODY=$(echo "$PR_INFO" | jq -r '.body // ""') |
| 93 | + fi |
| 94 | + |
| 95 | + # Check if draft release already exists |
| 96 | + RELEASE_EXISTS=$(gh release view v$VERSION --json isDraft 2>/dev/null || echo "{}") |
| 97 | + IS_DRAFT=$(echo "$RELEASE_EXISTS" | jq -r '.isDraft // false') |
| 98 | + |
| 99 | + if [ "$IS_DRAFT" = "true" ]; then |
| 100 | + echo "Updating existing draft release v$VERSION" |
| 101 | + |
| 102 | + # Get existing release notes |
| 103 | + gh release view v$VERSION --json body | jq -r '.body' > existing-notes.md |
| 104 | + |
| 105 | + # Add new PR information if available |
| 106 | + if [ ! -z "$PR_NUMBER" ] && [ ! -z "$PR_TITLE" ]; then |
| 107 | + echo -e "\n### PR #$PR_NUMBER: $PR_TITLE\n" >> existing-notes.md |
| 108 | + if [ ! -z "$PR_BODY" ]; then |
| 109 | + echo -e "$PR_BODY\n" >> existing-notes.md |
| 110 | + fi |
| 111 | + fi |
| 112 | + |
| 113 | + # Update the release |
| 114 | + gh release edit v$VERSION --notes-file existing-notes.md |
| 115 | + else |
| 116 | + echo "Creating new draft release v$VERSION" |
| 117 | + |
| 118 | + # Create initial release notes |
| 119 | + echo -e "# Release v$VERSION\n" > release-notes.md |
| 120 | + cat changelog-extract.md >> release-notes.md |
| 121 | + |
| 122 | + # Add PR information if available |
| 123 | + if [ ! -z "$PR_NUMBER" ] && [ ! -z "$PR_TITLE" ]; then |
| 124 | + echo -e "\n## Pull Requests\n" >> release-notes.md |
| 125 | + echo -e "### PR #$PR_NUMBER: $PR_TITLE\n" >> release-notes.md |
| 126 | + if [ ! -z "$PR_BODY" ]; then |
| 127 | + echo -e "$PR_BODY\n" >> release-notes.md |
| 128 | + fi |
| 129 | + fi |
| 130 | + |
| 131 | + # Create a draft release |
| 132 | + gh release create v$VERSION \ |
| 133 | + --draft \ |
| 134 | + --title "v$VERSION" \ |
| 135 | + --notes-file release-notes.md |
| 136 | + fi |
| 137 | + |
| 138 | + # Commit the version change |
| 139 | + git config --global user.name "GitHub Actions" |
| 140 | + git config --global user.email "[email protected]" |
| 141 | + git add package.json |
| 142 | + git commit -m "chore(release): bump version to $VERSION [skip ci]" |
| 143 | + git push |
0 commit comments