@@ -119,8 +119,37 @@ jobs:
119119
120120 - name : Create and push staging tag
121121 run : |
122- git tag "v${{ steps.bump_version.outputs.new_version }}"
123- git push origin "v${{ steps.bump_version.outputs.new_version }}"
122+ set -euo pipefail
123+ TAG="v${{ steps.bump_version.outputs.new_version }}"
124+
125+ if git ls-remote --tags origin "$TAG" | grep -q "$TAG"; then
126+ echo "Tag $TAG already exists on origin; skipping push."
127+ exit 0
128+ fi
129+
130+ if git rev-parse "$TAG" >/dev/null 2>&1; then
131+ echo "Tag $TAG already exists locally; removing before re-tagging."
132+ git tag -d "$TAG"
133+ fi
134+
135+ git tag "$TAG"
136+
137+ set +e
138+ git push origin "$TAG"
139+ PUSH_STATUS=$?
140+ set -e
141+
142+ if [ "$PUSH_STATUS" -ne 0 ]; then
143+ echo "Push failed, re-checking remote for $TAG..."
144+ if git ls-remote --tags origin "$TAG" | grep -q "$TAG"; then
145+ echo "Tag $TAG is present on origin after push attempt; continuing."
146+ exit 0
147+ fi
148+ echo "Failed to push tag $TAG and it is not present on origin."
149+ exit 1
150+ fi
151+
152+ echo "Pushed tag $TAG to origin."
124153
125154 - name : Upload staging metadata
126155 uses : actions/upload-artifact@v4
@@ -189,6 +218,14 @@ jobs:
189218 env :
190219 VERSION : ${{ needs.prepare-and-commit-staging.outputs.new_version }}
191220 run : |
221+ EXISTING_RELEASE=$(curl -s -H "Authorization: token ${{ secrets.CODEBUFF_GITHUB_TOKEN }}" \
222+ "https://api.github.com/repos/CodebuffAI/codebuff/releases/tags/v${VERSION}")
223+
224+ if echo "$EXISTING_RELEASE" | jq -e '.id' >/dev/null 2>&1; then
225+ echo "Release for v${VERSION} already exists; skipping creation."
226+ exit 0
227+ fi
228+
192229 CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
193230 RELEASE_BODY=$(cat <<'EOF'
194231 ## Codecane v${VERSION} (Staging)
@@ -266,7 +303,20 @@ jobs:
266303 node-version : 20
267304 registry-url : https://registry.npmjs.org/
268305
306+ - name : Check if version already published
307+ id : check_npm
308+ env :
309+ VERSION : ${{ needs.prepare-and-commit-staging.outputs.new_version }}
310+ run : |
311+ if npm view codecane@"$VERSION" version >/dev/null 2>&1; then
312+ echo "codecane@$VERSION already published to npm; skipping publish."
313+ echo "published=true" >> "$GITHUB_OUTPUT"
314+ else
315+ echo "published=false" >> "$GITHUB_OUTPUT"
316+ fi
317+
269318 - name : Publish codecane staging package to npm
319+ if : steps.check_npm.outputs.published != 'true'
270320 run : |
271321 cd cli/release-staging
272322 npm publish --access public
0 commit comments