Skip to content

Commit 27b818a

Browse files
committed
ci: skip duplicate codecane staging tags
1 parent 23ada55 commit 27b818a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

.github/workflows/cli-release-staging.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
if: contains(github.event.pull_request.title, '[codecane]')
1818
outputs:
1919
new_version: ${{ steps.bump_version.outputs.new_version }}
20+
tag_exists: ${{ steps.check_tag.outputs.exists }}
2021
steps:
2122
- uses: actions/checkout@v4
2223
with:
@@ -117,11 +118,28 @@ jobs:
117118
🤖 Generated with Codebuff
118119
Co-Authored-By: Codebuff <noreply@codebuff.com>"
119120
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+
120132
- name: Create and push staging tag
133+
if: steps.check_tag.outputs.exists != 'true'
121134
run: |
122135
git tag "v${{ steps.bump_version.outputs.new_version }}"
123136
git push origin "v${{ steps.bump_version.outputs.new_version }}"
124137
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+
125143
- name: Upload staging metadata
126144
uses: actions/upload-artifact@v4
127145
with:
@@ -189,6 +207,14 @@ jobs:
189207
env:
190208
VERSION: ${{ needs.prepare-and-commit-staging.outputs.new_version }}
191209
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+
192218
CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
193219
RELEASE_BODY=$(cat <<'EOF'
194220
## Codecane v${VERSION} (Staging)
@@ -266,7 +292,20 @@ jobs:
266292
node-version: 20
267293
registry-url: https://registry.npmjs.org/
268294

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+
269307
- name: Publish codecane staging package to npm
308+
if: steps.check_npm.outputs.published != 'true'
270309
run: |
271310
cd cli/release-staging
272311
npm publish --access public

0 commit comments

Comments
 (0)