|
| 1 | +name: VSCode Pre-release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + main_commit_sha: |
| 7 | + description: "Main branch commit SHA to create pre-release from - leave empty to use HEAD of main" |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + prerelease_version: |
| 11 | + description: "New pre-release version (e.g., 1.3.15) - leave empty to auto-increment" |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + create-prerelease: |
| 21 | + name: Create VSCode Pre-release |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@v5 |
| 26 | + with: |
| 27 | + ref: ${{ inputs.main_commit_sha || 'main' }} |
| 28 | + fetch-depth: 0 |
| 29 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + |
| 31 | + - name: Setup Node.js |
| 32 | + uses: actions/setup-node@v5 |
| 33 | + with: |
| 34 | + node-version: 20 |
| 35 | + |
| 36 | + - name: Determine version numbers |
| 37 | + id: version |
| 38 | + working-directory: extensions/vscode |
| 39 | + run: | |
| 40 | + # Get current version from package.json |
| 41 | + CURRENT_VERSION=$(node -p "require('./package.json').version") |
| 42 | + echo "Current version in package.json: $CURRENT_VERSION" |
| 43 | +
|
| 44 | + # Determine new pre-release version |
| 45 | + if [[ -n "${{ inputs.prerelease_version }}" ]]; then |
| 46 | + NEW_VERSION="${{ inputs.prerelease_version }}" |
| 47 | + echo "Using manually specified new version: $NEW_VERSION" |
| 48 | + else |
| 49 | + # Auto-increment patch version |
| 50 | + IFS='.' read -r major minor patch <<< "$CURRENT_VERSION" |
| 51 | + NEW_PATCH=$((patch + 1)) |
| 52 | + NEW_VERSION="${major}.${minor}.${NEW_PATCH}" |
| 53 | + echo "Auto-incremented version: $NEW_VERSION" |
| 54 | + fi |
| 55 | +
|
| 56 | + TAG_NAME="v${NEW_VERSION}-vscode" |
| 57 | +
|
| 58 | + echo "previous_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 59 | + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 60 | + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT |
| 61 | +
|
| 62 | + echo "Summary:" |
| 63 | + echo " Previous version: $CURRENT_VERSION" |
| 64 | + echo " New version: $NEW_VERSION" |
| 65 | + echo " Tag name: $TAG_NAME" |
| 66 | +
|
| 67 | + - name: Create pre-release branch |
| 68 | + id: branch |
| 69 | + run: | |
| 70 | + BRANCH_NAME="prerelease/vscode-${{ steps.version.outputs.new_version }}" |
| 71 | + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT |
| 72 | +
|
| 73 | + git config --local user.email "[email protected]" |
| 74 | + git config --local user.name "GitHub Action" |
| 75 | +
|
| 76 | + git checkout -b "$BRANCH_NAME" |
| 77 | + echo "Created branch: $BRANCH_NAME" |
| 78 | +
|
| 79 | + - name: Update package.json version |
| 80 | + working-directory: extensions/vscode |
| 81 | + run: | |
| 82 | + # Update version in package.json |
| 83 | + npm version ${{ steps.version.outputs.new_version }} --no-git-tag-version |
| 84 | +
|
| 85 | + echo "Updated package.json to version ${{ steps.version.outputs.new_version }}" |
| 86 | +
|
| 87 | + - name: Commit version bump |
| 88 | + run: | |
| 89 | + git config --local user.email "[email protected]" |
| 90 | + git config --local user.name "GitHub Action" |
| 91 | +
|
| 92 | + git add extensions/vscode/package.json |
| 93 | + git commit -m "chore: bump VSCode extension version to ${{ steps.version.outputs.new_version }}" |
| 94 | +
|
| 95 | + echo "Committed version bump" |
| 96 | +
|
| 97 | + - name: Push branch and create PR |
| 98 | + id: pr |
| 99 | + env: |
| 100 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + run: | |
| 102 | + git push origin "${{ steps.branch.outputs.branch_name }}" |
| 103 | + echo "Pushed branch: ${{ steps.branch.outputs.branch_name }}" |
| 104 | +
|
| 105 | + # Create pull request |
| 106 | + PR_URL=$(gh pr create \ |
| 107 | + --base main \ |
| 108 | + --head "${{ steps.branch.outputs.branch_name }}" \ |
| 109 | + --title "chore: VSCode pre-release ${{ steps.version.outputs.new_version }}" \ |
| 110 | + --body "$(cat <<'EOF' |
| 111 | + ## VSCode Pre-release ${{ steps.version.outputs.new_version }} |
| 112 | +
|
| 113 | + This PR bumps the VSCode extension version for pre-release. |
| 114 | +
|
| 115 | + ### Changes |
| 116 | + - Version bumped from ${{ steps.version.outputs.previous_version }} to ${{ steps.version.outputs.new_version }} |
| 117 | + - Based on commit: ${{ inputs.main_commit_sha }} |
| 118 | +
|
| 119 | + ### Release Process |
| 120 | + After merging this PR: |
| 121 | + 1. The tag \`${{ steps.version.outputs.tag_name }}\` will be created automatically |
| 122 | + 2. A GitHub pre-release will be created with auto-generated release notes |
| 123 | +
|
| 124 | + 🤖 This PR was created automatically by the VSCode Pre-release workflow. |
| 125 | + EOF |
| 126 | + )") |
| 127 | +
|
| 128 | + echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT |
| 129 | + echo "Created PR: $PR_URL" |
| 130 | +
|
| 131 | + - name: Auto-merge PR |
| 132 | + env: |
| 133 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 134 | + run: | |
| 135 | + # Get PR number from URL |
| 136 | + PR_NUMBER=$(echo "${{ steps.pr.outputs.pr_url }}" | grep -oE '[0-9]+$') |
| 137 | +
|
| 138 | + # Merge the PR |
| 139 | + gh pr merge "$PR_NUMBER" --squash --auto |
| 140 | +
|
| 141 | + echo "PR #$PR_NUMBER set to auto-merge" |
| 142 | +
|
| 143 | + # Wait for merge to complete (with timeout) |
| 144 | + echo "Waiting for PR to be merged..." |
| 145 | + TIMEOUT=300 # 5 minutes |
| 146 | + ELAPSED=0 |
| 147 | + INTERVAL=10 |
| 148 | +
|
| 149 | + while [ $ELAPSED -lt $TIMEOUT ]; do |
| 150 | + PR_STATE=$(gh pr view "$PR_NUMBER" --json state --jq '.state') |
| 151 | + if [ "$PR_STATE" = "MERGED" ]; then |
| 152 | + echo "PR successfully merged!" |
| 153 | + break |
| 154 | + fi |
| 155 | + sleep $INTERVAL |
| 156 | + ELAPSED=$((ELAPSED + INTERVAL)) |
| 157 | + echo "Still waiting... ($ELAPSED seconds elapsed)" |
| 158 | + done |
| 159 | +
|
| 160 | + if [ $ELAPSED -ge $TIMEOUT ]; then |
| 161 | + echo "Warning: Timed out waiting for PR merge. Please check manually." && exit 1 |
| 162 | + fi |
| 163 | +
|
| 164 | + - name: Checkout main branch |
| 165 | + run: | |
| 166 | + git fetch origin main |
| 167 | + git checkout main |
| 168 | + git pull origin main |
| 169 | +
|
| 170 | + - name: Create and push tag |
| 171 | + run: | |
| 172 | + git config --local user.email "[email protected]" |
| 173 | + git config --local user.name "GitHub Action" |
| 174 | +
|
| 175 | + git tag "${{ steps.version.outputs.tag_name }}" |
| 176 | + git push origin "${{ steps.version.outputs.tag_name }}" |
| 177 | +
|
| 178 | + echo "Created and pushed tag: ${{ steps.version.outputs.tag_name }}" |
| 179 | +
|
| 180 | + - name: Get previous tag for release notes |
| 181 | + id: prev_tag |
| 182 | + run: | |
| 183 | + # Find the previous vscode pre-release tag |
| 184 | + PREV_TAG=$(git tag -l "v*-vscode" --sort=-version:refname | head -n 2 | tail -n 1) |
| 185 | +
|
| 186 | + if [ -z "$PREV_TAG" ]; then |
| 187 | + echo "No previous tag found, using first commit" |
| 188 | + PREV_TAG=$(git rev-list --max-parents=0 HEAD) |
| 189 | + fi |
| 190 | +
|
| 191 | + echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT |
| 192 | + echo "Previous tag for release notes: $PREV_TAG" |
| 193 | +
|
| 194 | + - name: Create GitHub pre-release |
| 195 | + env: |
| 196 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 197 | + run: | |
| 198 | + # Generate release notes between previous tag and current tag |
| 199 | + RELEASE_NOTES=$(gh api \ |
| 200 | + --method POST \ |
| 201 | + -H "Accept: application/vnd.github+json" \ |
| 202 | + /repos/${{ github.repository }}/releases/generate-notes \ |
| 203 | + -f tag_name="${{ steps.version.outputs.tag_name }}" \ |
| 204 | + -f target_commitish="main" \ |
| 205 | + -f previous_tag_name="${{ steps.prev_tag.outputs.prev_tag }}" \ |
| 206 | + --jq '.body') |
| 207 | +
|
| 208 | + # Create the pre-release |
| 209 | + gh release create "${{ steps.version.outputs.tag_name }}" \ |
| 210 | + --title "VSCode Pre-release ${{ steps.version.outputs.new_version }}" \ |
| 211 | + --notes "$RELEASE_NOTES" \ |
| 212 | + --prerelease \ |
| 213 | + --target main |
| 214 | +
|
| 215 | + echo "Created pre-release: ${{ steps.version.outputs.tag_name }}" |
| 216 | +
|
| 217 | + - name: Summary |
| 218 | + run: | |
| 219 | + echo "## VSCode Pre-release Created Successfully! 🚀" >> $GITHUB_STEP_SUMMARY |
| 220 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 221 | + echo "### Version Information" >> $GITHUB_STEP_SUMMARY |
| 222 | + echo "- **Previous Version:** ${{ steps.version.outputs.previous_version }}" >> $GITHUB_STEP_SUMMARY |
| 223 | + echo "- **New Version:** ${{ steps.version.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY |
| 224 | + echo "- **Tag:** \`${{ steps.version.outputs.tag_name }}\`" >> $GITHUB_STEP_SUMMARY |
| 225 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 226 | + echo "### Links" >> $GITHUB_STEP_SUMMARY |
| 227 | + echo "- **PR:** ${{ steps.pr.outputs.pr_url }}" >> $GITHUB_STEP_SUMMARY |
| 228 | + echo "- **Release:** https://github.com/${{ github.repository }}/releases/tag/${{ steps.version.outputs.tag_name }}" >> $GITHUB_STEP_SUMMARY |
| 229 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 230 | + echo "### Commit" >> $GITHUB_STEP_SUMMARY |
| 231 | + echo "- **Base Commit:** \`${{ inputs.main_commit_sha }}\`" >> $GITHUB_STEP_SUMMARY |
0 commit comments