- Replaced actions/checkout with native git fetch (fixes directory not found) - Release workflow now triggers on every push to main (no tags needed) - Auto-creates/updates "latest" release with 6 cross-compiled binaries - Includes checksums, install instructions, and recent commit log - Requires GITEA_TOKEN secret in repo settings 💘 Generated with Crush Assisted-by: GLM-5.1 via Crush <crush@charm.land>
175 lines
6.8 KiB
YAML
175 lines
6.8 KiB
YAML
name: Release
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
git init
|
|
git remote add origin ${{ github.server_url }}/${{ github.repository }}.git
|
|
git fetch origin ${{ github.ref }}
|
|
git checkout FETCH_HEAD
|
|
|
|
- name: Setup Go
|
|
run: |
|
|
if ! command -v go &> /dev/null; then
|
|
wget -q https://go.dev/dl/go1.24.3.linux-amd64.tar.gz
|
|
sudo tar -C /usr/local -xzf go1.24.3.linux-amd64.tar.gz
|
|
export PATH=/usr/local/go/bin:$PATH
|
|
echo "PATH=/usr/local/go/bin:$PATH" >> $GITHUB_ENV
|
|
fi
|
|
go version
|
|
|
|
- name: Get version
|
|
id: info
|
|
run: |
|
|
VERSION=$(grep 'Version =' internal/version/version.go | cut -d'"' -f2)
|
|
SHORT_SHA=$(git rev-parse --short HEAD)
|
|
echo "version=v${VERSION}" >> $GITHUB_OUTPUT
|
|
echo "sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
|
|
echo "Building muyue v${VERSION} (${SHORT_SHA})"
|
|
|
|
- name: Build all platforms
|
|
run: |
|
|
mkdir -p dist
|
|
VERSION=${{ steps.info.outputs.version }}
|
|
SHA=${{ steps.info.outputs.sha }}
|
|
|
|
echo "Building linux/amd64..."
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
|
-ldflags="-s -w -X github.com/muyue/muyue/internal/version.Version=${VERSION}-${SHA}" \
|
|
-o dist/muyue-linux-amd64 ./cmd/muyue/
|
|
|
|
echo "Building linux/arm64..."
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build \
|
|
-ldflags="-s -w -X github.com/muyue/muyue/internal/version.Version=${VERSION}-${SHA}" \
|
|
-o dist/muyue-linux-arm64 ./cmd/muyue/
|
|
|
|
echo "Building darwin/amd64..."
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build \
|
|
-ldflags="-s -w -X github.com/muyue/muyue/internal/version.Version=${VERSION}-${SHA}" \
|
|
-o dist/muyue-darwin-amd64 ./cmd/muyue/
|
|
|
|
echo "Building darwin/arm64..."
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build \
|
|
-ldflags="-s -w -X github.com/muyue/muyue/internal/version.Version=${VERSION}-${SHA}" \
|
|
-o dist/muyue-darwin-arm64 ./cmd/muyue/
|
|
|
|
echo "Building windows/amd64..."
|
|
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build \
|
|
-ldflags="-s -w -X github.com/muyue/muyue/internal/version.Version=${VERSION}-${SHA}" \
|
|
-o dist/muyue-windows-amd64.exe ./cmd/muyue/
|
|
|
|
echo "Building windows/arm64..."
|
|
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build \
|
|
-ldflags="-s -w -X github.com/muyue/muyue/internal/version.Version=${VERSION}-${SHA}" \
|
|
-o dist/muyue-windows-arm64.exe ./cmd/muyue/
|
|
|
|
echo "Build complete:"
|
|
ls -lh dist/
|
|
|
|
- name: Create checksums
|
|
run: |
|
|
cd dist
|
|
sha256sum * > checksums.txt
|
|
cat checksums.txt
|
|
|
|
- name: Create archives
|
|
run: |
|
|
cd dist
|
|
tar czf muyue-linux-amd64.tar.gz muyue-linux-amd64
|
|
tar czf muyue-linux-arm64.tar.gz muyue-linux-arm64
|
|
tar czf muyue-darwin-amd64.tar.gz muyue-darwin-amd64
|
|
tar czf muyue-darwin-arm64.tar.gz muyue-darwin-arm64
|
|
zip muyue-windows-amd64.zip muyue-windows-amd64.exe
|
|
zip muyue-windows-arm64.zip muyue-windows-arm64.exe
|
|
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: Delete old latest release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
API="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases"
|
|
RELEASE_ID=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" "${API}?draft=false&pre-release=false" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*' || true)
|
|
if [ -n "$RELEASE_ID" ]; then
|
|
echo "Deleting old release ${RELEASE_ID}..."
|
|
curl -s -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${API}/${RELEASE_ID}"
|
|
fi
|
|
TAG_ID=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/tags" | grep -o '"name":"latest"' || true)
|
|
if [ -n "$TAG_ID" ]; then
|
|
curl -s -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/tags/latest"
|
|
fi
|
|
|
|
- name: Create release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
VERSION=${{ steps.info.outputs.version }}
|
|
SHA=${{ steps.info.outputs.sha }}
|
|
API="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases"
|
|
|
|
COMMIT_LOG=$(git log --oneline -10 | head -10)
|
|
|
|
BODY=$(cat <<BODY_END
|
|
## muyue ${VERSION} (${SHA})
|
|
|
|
### Downloads
|
|
| Platform | File |
|
|
|----------|------|
|
|
| Linux x86_64 | muyue-linux-amd64.tar.gz |
|
|
| Linux ARM64 | muyue-linux-arm64.tar.gz |
|
|
| macOS Intel | muyue-darwin-amd64.tar.gz |
|
|
| macOS Apple Silicon | muyue-darwin-arm64.tar.gz |
|
|
| Windows x86_64 | muyue-windows-amd64.zip |
|
|
| Windows ARM64 | muyue-windows-arm64.zip |
|
|
|
|
### Install (Linux)
|
|
\`\`\`bash
|
|
curl -sL ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/download/latest/muyue-linux-amd64.tar.gz | tar xz
|
|
chmod +x muyue-linux-amd64
|
|
sudo mv muyue-linux-amd64 /usr/local/bin/muyue
|
|
\`\`\`
|
|
|
|
### Recent commits
|
|
${COMMIT_LOG}
|
|
BODY_END
|
|
)
|
|
|
|
echo "Creating release..."
|
|
RESPONSE=$(curl -s -X POST "${API}" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$(jq -n \
|
|
--arg tag "latest" \
|
|
--arg name "muyue ${VERSION} (${SHA})" \
|
|
--arg body "$BODY" \
|
|
'{tag_name: $tag, target_commitish: "main", name: $name, body: $body, draft: false, prerelease: false}')")
|
|
|
|
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*')
|
|
echo "Release ID: ${RELEASE_ID}"
|
|
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "Failed to create release:"
|
|
echo "$RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
UPLOAD_URL="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets"
|
|
|
|
for file in dist/*.tar.gz dist/*.zip dist/checksums.txt; do
|
|
filename=$(basename "$file")
|
|
echo "Uploading ${filename}..."
|
|
curl -s -X POST "${UPLOAD_URL}" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@${file};filename=${filename}" | grep -o '"name":"[^"]*"' || echo "uploaded"
|
|
done
|
|
|
|
echo "Release published!"
|