GITEA_ENV/GITHUB_ENV doesn't take effect in the same step with act_runner. Added explicit 'export PATH=/usr/local/go/bin:$PATH' in every step that uses go. 💘 Generated with Crush Assisted-by: GLM-5.1 via Crush <crush@charm.land>
139 lines
5.5 KiB
YAML
139 lines
5.5 KiB
YAML
name: Release
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- 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
|
|
fi
|
|
export PATH=/usr/local/go/bin:$PATH
|
|
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
|
|
|
|
- name: Build all platforms
|
|
run: |
|
|
export PATH=/usr/local/go/bin:$PATH
|
|
mkdir -p dist
|
|
VERSION=${{ steps.info.outputs.version }}
|
|
SHA=${{ steps.info.outputs.sha }}
|
|
LDFLAGS="-s -w -X github.com/muyue/muyue/internal/version.Version=${VERSION}-${SHA}"
|
|
|
|
echo "Building linux/amd64..."
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$LDFLAGS" -o dist/muyue-linux-amd64 ./cmd/muyue/
|
|
|
|
echo "Building linux/arm64..."
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$LDFLAGS" -o dist/muyue-linux-arm64 ./cmd/muyue/
|
|
|
|
echo "Building darwin/amd64..."
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="$LDFLAGS" -o dist/muyue-darwin-amd64 ./cmd/muyue/
|
|
|
|
echo "Building darwin/arm64..."
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="$LDFLAGS" -o dist/muyue-darwin-arm64 ./cmd/muyue/
|
|
|
|
echo "Building windows/amd64..."
|
|
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="$LDFLAGS" -o dist/muyue-windows-amd64.exe ./cmd/muyue/
|
|
|
|
echo "Building windows/arm64..."
|
|
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -ldflags="$LDFLAGS" -o dist/muyue-windows-arm64.exe ./cmd/muyue/
|
|
|
|
ls -lh dist/
|
|
|
|
- name: Create checksums and archives
|
|
run: |
|
|
cd dist
|
|
sha256sum * > checksums.txt
|
|
cat checksums.txt
|
|
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 release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
API="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases"
|
|
curl -s -H "Authorization: token ${GITEA_TOKEN}" "${API}" | 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}"
|
|
echo "Deleted release ${ID}"
|
|
done
|
|
curl -s -X DELETE -H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/tags/latest" 2>/dev/null || true
|
|
|
|
- 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"
|
|
|
|
BODY="## muyue ${VERSION} (${SHA})
|
|
|
|
| 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 amd64)
|
|
\`\`\`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
|
|
\`\`\`"
|
|
|
|
RESPONSE=$(curl -s -X POST "${API}" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"latest\",\"target_commitish\":\"main\",\"name\":\"muyue ${VERSION} (${SHA})\",\"body\":$(echo "$BODY" | jq -Rs .),\"draft\":false,\"prerelease\":false}")
|
|
|
|
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*')
|
|
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "Failed to create release:"
|
|
echo "$RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Release ID: ${RELEASE_ID}"
|
|
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}" > /dev/null
|
|
done
|
|
|
|
echo "Release published!"
|