fix: release workflow - delete old release before creating new one
All checks were successful
CI / build (push) Successful in 25s

Remove the skip-if-tag-exists check. Instead, delete old release+tag
for the version before creating a fresh one (like before but per-version).

💘 Generated with Crush

Assisted-by: GLM-5.1 via Crush <crush@charm.land>
This commit is contained in:
Augustin
2026-04-19 23:25:23 +02:00
parent e3cd618cb1
commit 5eb237fc98

View File

@@ -28,39 +28,19 @@ jobs:
BASE_VERSION=$(grep 'Version =' internal/version/version.go | cut -d'"' -f2)
COMMIT_COUNT=$(git rev-list --count HEAD)
SHORT_SHA=$(git rev-parse --short HEAD)
FULL_VERSION="${BASE_VERSION}-dev.${COMMIT_COUNT}+${SHORT_SHA}"
FULL_VERSION="${BASE_VERSION}-build.${COMMIT_COUNT}"
echo "base_version=v${BASE_VERSION}" >> $GITHUB_OUTPUT
echo "full_version=v${FULL_VERSION}" >> $GITHUB_OUTPUT
echo "sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
echo "commit_count=${COMMIT_COUNT}" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check
env:
GITEA_TOKEN: ${{ secrets.GITEATOKEN }}
run: |
if [ -z "$GITEA_TOKEN" ]; then
echo "skip=false" >> $GITHUB_OUTPUT
exit 0
fi
TAG="${{ steps.info.outputs.base_version }}"
API="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/${TAG}"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token ${GITEA_TOKEN}" "${API}")
if [ "$HTTP_CODE" = "200" ]; then
echo "Tag ${TAG} already exists, skipping release."
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Build all platforms
if: steps.check.outputs.skip != 'true'
run: |
export PATH=/usr/local/go/bin:$PATH
mkdir -p dist
VERSION=${{ steps.info.outputs.full_version }}
SHA=${{ steps.info.outputs.sha }}
LDFLAGS="-s -w -X github.com/muyue/muyue/internal/version.Version=${VERSION}-${SHA}"
LDFLAGS="-s -w -X github.com/muyue/muyue/internal/version.Version=${VERSION}"
echo "Building linux/amd64..."
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$LDFLAGS" -o dist/muyue-linux-amd64 ./cmd/muyue/
@@ -83,7 +63,6 @@ jobs:
ls -lh dist/
- name: Create checksums and archives
if: steps.check.outputs.skip != 'true'
run: |
cd dist
sha256sum * > checksums.txt
@@ -97,14 +76,34 @@ jobs:
rm -f muyue-linux-amd64 muyue-linux-arm64 muyue-darwin-amd64 muyue-darwin-arm64 muyue-windows-amd64.exe muyue-windows-arm64.exe
ls -lh
- name: Create release
if: steps.check.outputs.skip != 'true'
- name: Delete old release for this version
env:
GITEA_TOKEN: ${{ secrets.GITEATOKEN }}
run: |
if [ -z "$GITEA_TOKEN" ]; then
echo "Error: GITEA_TOKEN secret is not configured."
echo "Go to Settings > Actions > Secrets and add GITEA_TOKEN"
echo "Warning: GITEATOKEN not set, skipping delete"
exit 0
fi
TAG="${{ steps.info.outputs.base_version }}"
API="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases"
RESPONSE=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" "${API}" 2>/dev/null || echo "")
if [ -n "$RESPONSE" ]; then
echo "$RESPONSE" | grep -o '"id":[0-9]*' | while read line; do
ID=$(echo "$line" | grep -o '[0-9]*')
curl -s -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${API}/${ID}" > /dev/null 2>&1 || true
echo "Deleted release ${ID}"
done || true
fi
curl -s -X DELETE -H "Authorization: token ${GITEA_TOKEN}" \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/tags/${TAG}" > /dev/null 2>&1 || true
- name: Create release
env:
GITEA_TOKEN: ${{ secrets.GITEATOKEN }}
run: |
if [ -z "$GITEA_TOKEN" ]; then
echo "Error: GITEATOKEN secret is not configured."
echo "Go to Settings > Actions > Secrets and add GITEATOKEN"
exit 1
fi
VERSION=${{ steps.info.outputs.full_version }}