@@ -73,27 +73,35 @@ jobs:
7373 echo "next=$next" >> $GITHUB_OUTPUT
7474
7575 - name : Create tag and release
76+ id : create_release
7677 env :
7778 GITHUB_TOKEN : ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
7879 GH_TOKEN : ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
7980 run : |
8081 next="${{ steps.next.outputs.next }}"
8182 echo "Creating release: $next"
8283
83- # Create and push tag
84- git tag "$next"
85- git push origin "$next"
84+ # Check if tag already exists
85+ if git rev-parse "$next" >/dev/null 2>&1; then
86+ echo "Tag $next already exists, skipping tag creation"
87+ else
88+ # Create and push tag
89+ git tag "$next"
90+ git push origin "$next"
91+ fi
8692
8793 # Create release with proper error handling
88- if gh release create "$next" --generate-notes; then
94+ if gh release view "$next" >/dev/null 2>&1; then
95+ echo "Release $next already exists, will update it"
96+ elif gh release create "$next" --generate-notes; then
8997 echo "Release $next created successfully"
9098 else
91- echo "Failed to create release $next, but continuing... "
99+ echo "Failed to create release $next"
92100 exit 1
93101 fi
94102
95103 - name : Attach binaries (Linux/macOS)
96- if : success()
104+ if : steps.create_release.outcome == ' success'
97105 env :
98106 GITHUB_TOKEN : ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
99107 GH_TOKEN : ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
@@ -103,16 +111,31 @@ jobs:
103111
104112 # Build static binaries for common platforms
105113 mkdir -p dist
114+ echo "Building binaries..."
106115 GOOS=linux GOARCH=amd64 go build -o dist/golearn-linux-amd64 ./cmd/golearn
107116 GOOS=darwin GOARCH=arm64 go build -o dist/golearn-darwin-arm64 ./cmd/golearn
108117 GOOS=darwin GOARCH=amd64 go build -o dist/golearn-darwin-amd64 ./cmd/golearn
109118 GOOS=windows GOARCH=amd64 go build -o dist/golearn-windows-amd64.exe ./cmd/golearn
110119
111- # Upload binaries to the release
112- if gh release upload "$next" dist/* --clobber; then
113- echo "Binaries uploaded successfully"
114- else
115- echo "Failed to upload binaries"
116- exit 1
117- fi
120+ echo "Binaries built successfully:"
121+ ls -lh dist/
122+
123+ # Upload binaries to the release with retry logic
124+ max_attempts=3
125+ attempt=1
126+ while [ $attempt -le $max_attempts ]; do
127+ echo "Attempt $attempt of $max_attempts to upload binaries..."
128+ if gh release upload "$next" dist/* --clobber; then
129+ echo "Binaries uploaded successfully"
130+ exit 0
131+ else
132+ echo "Upload attempt $attempt failed"
133+ if [ $attempt -eq $max_attempts ]; then
134+ echo "Failed to upload binaries after $max_attempts attempts"
135+ exit 1
136+ fi
137+ attempt=$((attempt+1))
138+ sleep 2
139+ fi
140+ done
118141
0 commit comments