From 02aaee42c567c93c39af10717eb2c4a8a5ad1f8a Mon Sep 17 00:00:00 2001 From: thezzisu Date: Tue, 12 Dec 2023 00:33:28 +0800 Subject: [PATCH] feat: add github actions --- .github/workflows/build.yml | 28 +++++++++++++++++ build.sh | 63 +++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100755 build.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..4bd6d0a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,28 @@ +name: Build + +on: + push: + branches: [master] + paths: + - "**/*.go" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version-file: "path/to/go.mod" + + - name: Build + run: ./build.sh + + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: build + path: build/releases diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..04d6971 --- /dev/null +++ b/build.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +BUILD_DIR=$(dirname "$0")/build/releases +mkdir -p $BUILD_DIR +cd $BUILD_DIR + +sum="sha256sum" +VERSION=$(git describe --tags --always --dirty) + +# AMD64 +OSES=(linux darwin windows freebsd) +for os in ${OSES[@]}; do + suffix="" + if [ "$os" == "windows" ] + then + suffix=".exe" + fi + env GOOS=$os GOARCH=amd64 go build -o azukiiro_${os}_amd64${suffix} github.com/zhzxdev/azukiiro + tar -zcf azukiiro-${os}-amd64-$VERSION.tar.gz azukiiro_${os}_amd64${suffix} + rm azukiiro_${os}_amd64${suffix} + HASH=$($sum azukiiro-${os}-amd64-$VERSION.tar.gz) + echo "$HASH azukiiro-${os}-amd64-$VERSION.tar.gz" > azukiiro-$VERSION.sha256 +done + +# 386 +OSES=(linux windows) +for os in ${OSES[@]}; do + suffix="" + if [ "$os" == "windows" ] + then + suffix=".exe" + fi + env GOOS=$os GOARCH=386 go build -o azukiiro_${os}_386${suffix} github.com/zhzxdev/azukiiro + tar -zcf azukiiro-${os}-386-$VERSION.tar.gz azukiiro_${os}_386${suffix} + rm azukiiro_${os}_386${suffix} + HASH=$($sum azukiiro-${os}-386-$VERSION.tar.gz) + echo "$HASH azukiiro-${os}-386-$VERSION.tar.gz" > azukiiro-$VERSION.sha256 +done + +# ARM +ARMS=(5 6 7) +for v in ${ARMS[@]}; do + env GOOS=linux GOARCH=arm GOARM=$v go build -o azukiiro_linux_arm$v github.com/zhzxdev/azukiiro + tar -zcf azukiiro-linux-arm$v-$VERSION.tar.gz azukiiro_linux_arm$v + rm azukiiro_linux_arm$v + HASH=$($sum azukiiro-linux-arm$v-$VERSION.tar.gz) + echo "$HASH azukiiro-linux-arm$v-$VERSION.tar.gz" > azukiiro-$VERSION.sha256 +done + +# ARM64 +OSES=(linux darwin windows) +for os in ${OSES[@]}; do + suffix="" + if [ "$os" == "windows" ] + then + suffix=".exe" + fi + env GOOS=$os GOARCH=arm64 go build -o azukiiro_${os}_arm64${suffix} github.com/zhzxdev/azukiiro + tar -zcf azukiiro-${os}-arm64-$VERSION.tar.gz azukiiro_${os}_arm64${suffix} + rm azukiiro_${os}_arm64${suffix} + HASH=$($sum azukiiro-${os}-arm64-$VERSION.tar.gz) + echo "$HASH azukiiro-${os}-arm64-$VERSION.tar.gz" > azukiiro-$VERSION.sha256 +done