|
| 1 | +name: Manual Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_type: |
| 7 | + description: "Type of release" |
| 8 | + required: true |
| 9 | + default: "patch" |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - patch |
| 13 | + - minor |
| 14 | + - major |
| 15 | + description: |
| 16 | + description: "Release description (optional)" |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + dry_run: |
| 20 | + description: "Dry run (test without making changes)" |
| 21 | + required: false |
| 22 | + default: false |
| 23 | + type: boolean |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: ${{ github.workflow }}-main |
| 27 | + cancel-in-progress: false |
| 28 | + |
| 29 | +jobs: |
| 30 | + complete-release: |
| 31 | + name: Complete Manual Release |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + contents: write |
| 35 | + actions: write |
| 36 | + id-token: write |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Checkout code |
| 40 | + uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + fetch-depth: 0 |
| 43 | + fetch-tags: true |
| 44 | + |
| 45 | + - name: Setup Node.js |
| 46 | + uses: actions/setup-node@v4 |
| 47 | + with: |
| 48 | + node-version: 22.x |
| 49 | + |
| 50 | + - name: Install dependencies |
| 51 | + run: npm ci |
| 52 | + |
| 53 | + - name: Configure Git |
| 54 | + run: | |
| 55 | + git config --local user.email "action@github.com" |
| 56 | + git config --local user.name "GitHub Action" |
| 57 | +
|
| 58 | + - name: Get current version |
| 59 | + id: current_version |
| 60 | + run: | |
| 61 | + CURRENT_VERSION=$(node -p "require('./package.json').version") |
| 62 | + echo "current=${CURRENT_VERSION}" >> $GITHUB_OUTPUT |
| 63 | + echo "Current version: ${CURRENT_VERSION}" |
| 64 | +
|
| 65 | + - name: Set version bump type |
| 66 | + id: version_bump |
| 67 | + run: | |
| 68 | + BUMP_TYPE="${{ github.event.inputs.release_type }}" |
| 69 | + echo "bump_type=${BUMP_TYPE}" >> $GITHUB_OUTPUT |
| 70 | + echo "Selected release type: ${BUMP_TYPE}" |
| 71 | +
|
| 72 | + - name: Bump version |
| 73 | + id: bump_version |
| 74 | + run: | |
| 75 | + CURRENT_VERSION="${{ steps.current_version.outputs.current }}" |
| 76 | + BUMP_TYPE="${{ steps.version_bump.outputs.bump_type }}" |
| 77 | +
|
| 78 | + IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION" |
| 79 | + MAJOR=${VERSION_PARTS[0]} |
| 80 | + MINOR=${VERSION_PARTS[1]} |
| 81 | + PATCH=${VERSION_PARTS[2]} |
| 82 | +
|
| 83 | + case $BUMP_TYPE in |
| 84 | + "major") |
| 85 | + MAJOR=$((MAJOR + 1)) |
| 86 | + MINOR=0 |
| 87 | + PATCH=0 |
| 88 | + ;; |
| 89 | + "minor") |
| 90 | + MINOR=$((MINOR + 1)) |
| 91 | + PATCH=0 |
| 92 | + ;; |
| 93 | + "patch") |
| 94 | + PATCH=$((PATCH + 1)) |
| 95 | + ;; |
| 96 | + esac |
| 97 | +
|
| 98 | + NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" |
| 99 | + echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT |
| 100 | + echo "tag=v${NEW_VERSION}" >> $GITHUB_OUTPUT |
| 101 | +
|
| 102 | + node -e " |
| 103 | + const fs = require('fs'); |
| 104 | + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); |
| 105 | + pkg.version = '${NEW_VERSION}'; |
| 106 | + fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); |
| 107 | + " |
| 108 | +
|
| 109 | + - name: Collect commit messages for release |
| 110 | + id: commit_messages |
| 111 | + run: | |
| 112 | + # Ensure we have all tags |
| 113 | + git fetch --tags origin |
| 114 | +
|
| 115 | + # Debug: Show available tags |
| 116 | + echo "Available tags:" |
| 117 | + git tag --sort=-version:refname | head -5 |
| 118 | +
|
| 119 | + LAST_TAG=$(git tag --sort=-version:refname | head -1 2>/dev/null || echo "") |
| 120 | +
|
| 121 | + # Debug: Show what we detected |
| 122 | + echo "Detected last tag: '$LAST_TAG'" |
| 123 | +
|
| 124 | + if [[ -n "$LAST_TAG" && "$LAST_TAG" != "" ]]; then |
| 125 | + # Use normal tag-based logic |
| 126 | + git log ${LAST_TAG}..HEAD --pretty=format:"- %s" --no-merges > /tmp/commits.txt |
| 127 | + echo "Using tag-based range: ${LAST_TAG}..HEAD" |
| 128 | + else |
| 129 | + # No tags exist, get last 10 commits |
| 130 | + git log -10 --pretty=format:"- %s" --no-merges > /tmp/commits.txt |
| 131 | + echo "No tags found, using last 10 commits" |
| 132 | + fi |
| 133 | +
|
| 134 | + echo "Raw commits:" |
| 135 | + cat /tmp/commits.txt |
| 136 | +
|
| 137 | + # Use base64 encoding to safely pass commit messages through JSON |
| 138 | + COMMITS_B64=$(base64 -w 0 /tmp/commits.txt) |
| 139 | +
|
| 140 | + # Only use base64 encoded commits to avoid multiline output issues |
| 141 | + echo "commits_b64=$COMMITS_B64" >> $GITHUB_OUTPUT |
| 142 | +
|
| 143 | + - name: Amend commit with version |
| 144 | + run: | |
| 145 | + NEW_VERSION="${{ steps.bump_version.outputs.new_version }}" |
| 146 | + CURRENT_MESSAGE=$(git log -1 --pretty=%B) |
| 147 | + NEW_MESSAGE="${CURRENT_MESSAGE} [v${NEW_VERSION}]" |
| 148 | +
|
| 149 | + git add package.json |
| 150 | + git commit --amend -m "${NEW_MESSAGE}" |
| 151 | +
|
| 152 | + if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then |
| 153 | + echo "🔍 DRY RUN: Would push amended commit to main" |
| 154 | + else |
| 155 | + git push --force-with-lease origin main |
| 156 | + fi |
| 157 | +
|
| 158 | + - name: Create tag |
| 159 | + run: | |
| 160 | + TAG="${{ steps.bump_version.outputs.tag }}" |
| 161 | + NEW_VERSION="${{ steps.bump_version.outputs.new_version }}" |
| 162 | +
|
| 163 | + # Create tag with commit messages (decode from base64) |
| 164 | + COMMIT_MESSAGES=$(echo "${{ steps.commit_messages.outputs.commits_b64 }}" | base64 -d) |
| 165 | +
|
| 166 | + TAG_MESSAGE=$(printf "Release %s\n\nChanges in this release:\n%s" "${TAG}" "${COMMIT_MESSAGES}") |
| 167 | +
|
| 168 | + git tag -a "${TAG}" -m "${TAG_MESSAGE}" |
| 169 | +
|
| 170 | + if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then |
| 171 | + echo "🔍 DRY RUN: Would push tag ${TAG}" |
| 172 | + echo "Tag message would be:" |
| 173 | + echo "${TAG_MESSAGE}" |
| 174 | + else |
| 175 | + git push origin "${TAG}" |
| 176 | + fi |
| 177 | +
|
| 178 | + - name: Verify version validation passed |
| 179 | + env: |
| 180 | + TYPEGRAPHQL_PRISMA_VERSION: ${{ steps.bump_version.outputs.tag }} |
| 181 | + run: | |
| 182 | + echo "Verifying release for version: $TYPEGRAPHQL_PRISMA_VERSION" |
| 183 | +
|
| 184 | + if ! printf "%s\n" "$TYPEGRAPHQL_PRISMA_VERSION" | grep -q -P '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(alpha|beta|rc)\.(0|[1-9][0-9]*))?$'; then |
| 185 | + printf '[ERROR]: Invalid version tag format (%s)\n' "$TYPEGRAPHQL_PRISMA_VERSION" |
| 186 | + exit 1 |
| 187 | + fi |
| 188 | +
|
| 189 | + echo "✅ Version tag format is valid" |
| 190 | +
|
| 191 | + - name: Determine if version is prerelease |
| 192 | + id: prerelease |
| 193 | + env: |
| 194 | + TYPEGRAPHQL_PRISMA_VERSION: ${{ steps.bump_version.outputs.tag }} |
| 195 | + run: | |
| 196 | + _prerelease= |
| 197 | + if printf "%s\n" "$TYPEGRAPHQL_PRISMA_VERSION" | grep -q -P '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'; then |
| 198 | + _prerelease=false |
| 199 | + else |
| 200 | + _prerelease=true |
| 201 | + fi |
| 202 | +
|
| 203 | + printf 'value=%s\n' "$_prerelease" >> "$GITHUB_OUTPUT" |
| 204 | +
|
| 205 | + - name: Setup Node.js for publishing |
| 206 | + uses: actions/setup-node@v4 |
| 207 | + with: |
| 208 | + node-version: 22.x |
| 209 | + registry-url: "https://registry.npmjs.org" |
| 210 | + |
| 211 | + - name: Install latest npm |
| 212 | + run: | |
| 213 | + npm install -g npm@latest |
| 214 | +
|
| 215 | + - name: Configure npm authentication |
| 216 | + run: | |
| 217 | + echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc |
| 218 | +
|
| 219 | + - name: Prepare package |
| 220 | + run: | |
| 221 | + npm run prepublishOnly |
| 222 | + env: |
| 223 | + TYPEGRAPHQL_PRISMA_REF: ${{ steps.bump_version.outputs.tag }} |
| 224 | + |
| 225 | + - name: Format commit messages for release |
| 226 | + id: changelog |
| 227 | + run: | |
| 228 | + COMMITS_B64="${{ steps.commit_messages.outputs.commits_b64 }}" |
| 229 | +
|
| 230 | + if [ -z "$COMMITS_B64" ]; then |
| 231 | + echo "No commits provided" |
| 232 | + FORMATTED_COMMITS="No changes listed" |
| 233 | + else |
| 234 | + FORMATTED_COMMITS=$(echo "$COMMITS_B64" | base64 -d) |
| 235 | + fi |
| 236 | +
|
| 237 | + RELEASE_BODY=$(printf "## Changes in this release:\n\n%s\n\nReleased as %s" "$FORMATTED_COMMITS" "${{ steps.bump_version.outputs.tag }}") |
| 238 | +
|
| 239 | + # Use base64 encoding to avoid EOF delimiter issues |
| 240 | + CHANGELOG_B64=$(echo "$RELEASE_BODY" | base64 -w 0) |
| 241 | + echo "changelog_b64=$CHANGELOG_B64" >> $GITHUB_OUTPUT |
| 242 | +
|
| 243 | + - name: Create GitHub Release |
| 244 | + if: github.event.inputs.dry_run != 'true' |
| 245 | + env: |
| 246 | + CHANGELOG_B64: ${{ steps.changelog.outputs.changelog_b64 }} |
| 247 | + GH_TOKEN: ${{ github.token }} |
| 248 | + run: | |
| 249 | + RELEASE_BODY=$(echo "$CHANGELOG_B64" | base64 -d) |
| 250 | + gh release create "${{ steps.bump_version.outputs.tag }}" \ |
| 251 | + --title "${{ steps.bump_version.outputs.tag }}" \ |
| 252 | + --notes "$RELEASE_BODY" \ |
| 253 | + ${{ steps.prerelease.outputs.value == 'true' && '--prerelease' || '' }} |
| 254 | +
|
| 255 | + - name: Show GitHub Release Info (Dry Run) |
| 256 | + if: github.event.inputs.dry_run == 'true' |
| 257 | + run: | |
| 258 | + echo "🔍 DRY RUN: Would create GitHub release" |
| 259 | + echo "Tag: ${{ steps.bump_version.outputs.tag }}" |
| 260 | + echo "Prerelease: ${{ steps.prerelease.outputs.value == 'true' }}" |
| 261 | + echo "Release body:" |
| 262 | + echo "${{ steps.changelog.outputs.changelog_b64 }}" | base64 -d |
| 263 | +
|
| 264 | + - name: Publish to npm |
| 265 | + if: github.event.inputs.dry_run != 'true' |
| 266 | + env: |
| 267 | + NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} |
| 268 | + TYPEGRAPHQL_PRISMA_PRERELEASE: ${{ steps.prerelease.outputs.value }} |
| 269 | + run: | |
| 270 | + _tag= |
| 271 | + if [ "$TYPEGRAPHQL_PRISMA_PRERELEASE" = "true" ]; then |
| 272 | + _tag="next" |
| 273 | + else |
| 274 | + _tag="latest" |
| 275 | + fi |
| 276 | +
|
| 277 | + npm publish --ignore-scripts --access public --tag "$_tag" |
| 278 | +
|
| 279 | + - name: Show npm Publish Info (Dry Run) |
| 280 | + if: github.event.inputs.dry_run == 'true' |
| 281 | + env: |
| 282 | + TYPEGRAPHQL_PRISMA_PRERELEASE: ${{ steps.prerelease.outputs.value }} |
| 283 | + run: | |
| 284 | + _tag= |
| 285 | + if [ "$TYPEGRAPHQL_PRISMA_PRERELEASE" = "true" ]; then |
| 286 | + _tag="next" |
| 287 | + else |
| 288 | + _tag="latest" |
| 289 | + fi |
| 290 | +
|
| 291 | + echo "🔍 DRY RUN: Would publish to npm" |
| 292 | + echo "Package: @scope3/typegraphql-prisma@${{ steps.bump_version.outputs.new_version }}" |
| 293 | + echo "Tag: $_tag" |
| 294 | + echo "Access: public" |
| 295 | +
|
| 296 | + - name: Output summary |
| 297 | + run: | |
| 298 | + if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then |
| 299 | + echo "## 🔍 Manual Release Summary (DRY RUN)" >> $GITHUB_STEP_SUMMARY |
| 300 | + echo "- **Mode**: DRY RUN - No changes made" >> $GITHUB_STEP_SUMMARY |
| 301 | + else |
| 302 | + echo "## 🚀 Manual Release Summary" >> $GITHUB_STEP_SUMMARY |
| 303 | + fi |
| 304 | + echo "- **Previous Version**: ${{ steps.current_version.outputs.current }}" >> $GITHUB_STEP_SUMMARY |
| 305 | + echo "- **New Version**: ${{ steps.bump_version.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY |
| 306 | + echo "- **Bump Type**: ${{ steps.version_bump.outputs.bump_type }}" >> $GITHUB_STEP_SUMMARY |
| 307 | + echo "- **Tag**: ${{ steps.bump_version.outputs.tag }}" >> $GITHUB_STEP_SUMMARY |
| 308 | + echo "- **Description**: ${{ github.event.inputs.description || 'None provided' }}" >> $GITHUB_STEP_SUMMARY |
| 309 | + if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then |
| 310 | + echo "- **Commit**: Would amend last commit with version info" >> $GITHUB_STEP_SUMMARY |
| 311 | + echo "- **GitHub Release**: Would create with commit messages" >> $GITHUB_STEP_SUMMARY |
| 312 | + echo "- **npm Package**: Would publish successfully" >> $GITHUB_STEP_SUMMARY |
| 313 | + else |
| 314 | + echo "- **Commit**: Amended last commit with version info" >> $GITHUB_STEP_SUMMARY |
| 315 | + echo "- **GitHub Release**: Created with commit messages" >> $GITHUB_STEP_SUMMARY |
| 316 | + echo "- **npm Package**: Published successfully" >> $GITHUB_STEP_SUMMARY |
| 317 | + fi |
0 commit comments