From 08d68ba316e6e60f09ed07a55c28aef2a3c5aca5 Mon Sep 17 00:00:00 2001 From: heartleo Date: Mon, 24 Jul 2023 17:40:51 +0800 Subject: [PATCH] fix release workflow --- .github/workflows/release.yml | 59 +++++++-------------------- Makefile | 5 ++- build-release.sh | 76 +++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 45 deletions(-) create mode 100644 build-release.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4596d2b..9f53cbc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,70 +8,41 @@ permissions: contents: write jobs: - build: - strategy: - matrix: - build: [ macos, linux, windows ] - include: - - build: macos - os: macos-latest - release_suffix: macos - - build: linux - os: ubuntu-latest - release_suffix: linux - - build: windows - os: windows-latest - release_suffix: windows - runs-on: ${{ matrix.os }} + release: + runs-on: ubuntu-latest steps: - - name: Checkout + - name: Checkout Code uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set Up Go uses: actions/setup-go@v3 with: go-version: 1.19 - name: Download Dependencies - run: go mod download - - - run: mkdir dist - - - name: Build Linux - if: matrix.os == 'ubuntu-latest' - run: | - uname -a - make build - export GOARCH=amd64 - tar czvf chat2data-linux-amd64.tar.gz chat2data - mv chat2data-linux-amd64.tar.gz dist/ - - - name: Build Mac - if: matrix.os == 'macos-latest' run: | - make build - export GOARCH=amd64 - tar czvf chat2data-darwin-amd64.tar.gz chat2data - mv chat2data-darwin-amd64.tar.gz dist/ + go mod download + go install github.com/crazy-max/xgo@latest + docker pull crazymax/xgo:latest - - name: Build Windows - if: matrix.os == 'windows-latest' + - name: Build Release run: | - make build - tar czvf chat2data-windows-amd64.tar.gz chat2data - mv chat2data-windows-amd64.tar.gz dist/ + make release - name: Upload Artifacts uses: actions/upload-artifact@v3 with: - name: dist - path: dist + name: compress + path: dist/compress - - name: GitHub Release + - name: Publish Release uses: softprops/action-gh-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} if: "startsWith(github.ref, 'refs/tags/')" with: files: | - dist/chat2data* + dist/compress/* generate_release_notes: true \ No newline at end of file diff --git a/Makefile b/Makefile index 24ddd75..e72e0f7 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,5 @@ build: - export CGO_ENABLED=1 && go build -o ./chat2data ./cmd/chat2data \ No newline at end of file + export CGO_ENABLED=1 && go build -o ./chat2data ./cmd/chat2data + +release: + bash ./build-release.sh \ No newline at end of file diff --git a/build-release.sh b/build-release.sh new file mode 100644 index 0000000..90cb632 --- /dev/null +++ b/build-release.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +set -ex + +appName="chat2data" +mkdir "dist" +muslflags="--extldflags '-static -fpic'" +BASE="https://musl.nn.ci/" +FILES=( + x86_64-linux-musl-cross + aarch64-linux-musl-cross + arm-linux-musleabihf-cross +# mips-linux-musl-cross +# mips64-linux-musl-cross +# mips64el-linux-musl-cross +# mipsel-linux-musl-cross +# powerpc64le-linux-musl-cross +# s390x-linux-musl-cross +) +for i in "${FILES[@]}"; do + url="${BASE}${i}.tgz" + curl -L -o "${i}.tgz" "${url}" + sudo tar xf "${i}.tgz" --strip-components 1 -C /usr/local +done +OS_ARCHES=( + linux-musl-amd64 + linux-musl-arm64 + linux-musl-arm +# linux-musl-mips +# linux-musl-mips64 +# linux-musl-mips64le +# linux-musl-mipsle +# linux-musl-ppc64le +# linux-musl-s390x +) +CGO_ARGS=( + x86_64-linux-musl-gcc + aarch64-linux-musl-gcc + arm-linux-musleabihf-gcc +# mips-linux-musl-gcc +# mips64-linux-musl-gcc +# mips64el-linux-musl-gcc +# mipsel-linux-musl-gcc +# powerpc64le-linux-musl-gcc +# s390x-linux-musl-gcc +) +for i in "${!OS_ARCHES[@]}"; do + os_arch=${OS_ARCHES[$i]} + cgo_cc=${CGO_ARGS[$i]} + echo building for "${os_arch}" + export GOOS=${os_arch%%-*} + export GOARCH=${os_arch##*-} + export CC=${cgo_cc} + export CGO_ENABLED=1 + go build -o ./dist/$appName-"$os_arch" -ldflags="$muslflags" ./cmd/chat2data +done +xgo --pkg cmd/chat2data -targets=windows/amd64,darwin/amd64,darwin/arm64 -out "$appName" . +mv "$appName"-* ./dist + +cd dist +mkdir compress +for i in $(find . -type f -name "$appName-linux-*"); do + cp "$i" "$appName" + tar -czvf compress/"$i".tar.gz "$appName" + rm -f "$appName" +done +for i in $(find . -type f -name "$appName-darwin-*"); do + cp "$i" "$appName" + tar -czvf compress/"$i".tar.gz "$appName" + rm -f "$appName" +done +for i in $(find . -type f -name "$appName-windows-*"); do + cp "$i" "$appName".exe + zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$appName".exe + rm -f "$appName".exe +done \ No newline at end of file