|
17 | 17 | if: contains(github.event.pull_request.title, '[codecane]') |
18 | 18 | outputs: |
19 | 19 | new_version: ${{ steps.bump_version.outputs.new_version }} |
| 20 | + tag_exists: ${{ steps.check_tag.outputs.exists }} |
20 | 21 | steps: |
21 | 22 | - uses: actions/checkout@v4 |
22 | 23 | with: |
@@ -117,11 +118,28 @@ jobs: |
117 | 118 | 🤖 Generated with Codebuff |
118 | 119 | Co-Authored-By: Codebuff <noreply@codebuff.com>" |
119 | 120 |
|
| 121 | + - name: Check if staging tag exists |
| 122 | + id: check_tag |
| 123 | + run: | |
| 124 | + TAG="v${{ steps.bump_version.outputs.new_version }}" |
| 125 | + if git ls-remote --tags origin "$TAG" | grep -q "$TAG"; then |
| 126 | + echo "Tag $TAG already exists on origin; skipping tag creation." |
| 127 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 128 | + else |
| 129 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 130 | + fi |
| 131 | +
|
120 | 132 | - name: Create and push staging tag |
| 133 | + if: steps.check_tag.outputs.exists != 'true' |
121 | 134 | run: | |
122 | 135 | git tag "v${{ steps.bump_version.outputs.new_version }}" |
123 | 136 | git push origin "v${{ steps.bump_version.outputs.new_version }}" |
124 | 137 |
|
| 138 | + - name: Tag already exists |
| 139 | + if: steps.check_tag.outputs.exists == 'true' |
| 140 | + run: | |
| 141 | + echo "Tag v${{ steps.bump_version.outputs.new_version }} already present on origin; continuing without pushing." |
| 142 | +
|
125 | 143 | - name: Upload staging metadata |
126 | 144 | uses: actions/upload-artifact@v4 |
127 | 145 | with: |
@@ -189,6 +207,14 @@ jobs: |
189 | 207 | env: |
190 | 208 | VERSION: ${{ needs.prepare-and-commit-staging.outputs.new_version }} |
191 | 209 | run: | |
| 210 | + EXISTING_RELEASE=$(curl -s -H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \ |
| 211 | + "https://api.github.com/repos/CodebuffAI/codebuff/releases/tags/v${VERSION}") |
| 212 | +
|
| 213 | + if echo "$EXISTING_RELEASE" | jq -e '.id' >/dev/null 2>&1; then |
| 214 | + echo "Release for v${VERSION} already exists; skipping creation." |
| 215 | + exit 0 |
| 216 | + fi |
| 217 | +
|
192 | 218 | CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
193 | 219 | RELEASE_BODY=$(cat <<'EOF' |
194 | 220 | ## Codecane v${VERSION} (Staging) |
@@ -266,7 +292,20 @@ jobs: |
266 | 292 | node-version: 20 |
267 | 293 | registry-url: https://registry.npmjs.org/ |
268 | 294 |
|
| 295 | + - name: Check if version already published |
| 296 | + id: check_npm |
| 297 | + env: |
| 298 | + VERSION: ${{ needs.prepare-and-commit-staging.outputs.new_version }} |
| 299 | + run: | |
| 300 | + if npm view codecane@"$VERSION" version >/dev/null 2>&1; then |
| 301 | + echo "codecane@$VERSION already published to npm; skipping publish." |
| 302 | + echo "published=true" >> "$GITHUB_OUTPUT" |
| 303 | + else |
| 304 | + echo "published=false" >> "$GITHUB_OUTPUT" |
| 305 | + fi |
| 306 | +
|
269 | 307 | - name: Publish codecane staging package to npm |
| 308 | + if: steps.check_npm.outputs.published != 'true' |
270 | 309 | run: | |
271 | 310 | cd cli/release-staging |
272 | 311 | npm publish --access public |
|
0 commit comments