diff options
author | sjlleo <[email protected]> | 2022-05-20 17:50:49 +0800 |
---|---|---|
committer | sjlleo <[email protected]> | 2022-05-20 17:50:49 +0800 |
commit | 39ec0454d1d2e5d0bf727eda0c176ce679174e0d (patch) | |
tree | 068d32a676cd6b1b376c1bf749a7aee18c722d9a | |
parent | 9b1eb23c4c052f5eca396843c81de14cc08fae50 (diff) |
Add: compile
-rw-r--r-- | .cross_compile.sh | 36 | ||||
-rw-r--r-- | .github/workflows/build.yml | 29 | ||||
-rw-r--r-- | .github/workflows/release.yaml | 29 |
3 files changed, 65 insertions, 29 deletions
diff --git a/.cross_compile.sh b/.cross_compile.sh new file mode 100644 index 0000000..19b754e --- /dev/null +++ b/.cross_compile.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -e + +DIST_PREFIX="nf" +DEBUG_MODE=${2} +TARGET_DIR="dist" +PLATFORMS="darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 linux/mips" + +rm -rf ${TARGET_DIR} +mkdir ${TARGET_DIR} + +for pl in ${PLATFORMS}; do + export GOOS=$(echo ${pl} | cut -d'/' -f1) + export GOARCH=$(echo ${pl} | cut -d'/' -f2) + export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH} + if [ "${GOOS}" == "windows" ]; then + export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH}.exe + fi + + echo "build => ${TARGET}" + if [ "${DEBUG_MODE}" == "debug" ]; then + go build -trimpath -gcflags "all=-N -l" -o ${TARGET} \ + -ldflags "-X 'main.version=${BUILD_VERSION}' \ + -X 'main.buildDate=${BUILD_DATE}' \ + -X 'main.commitID=${COMMIT_SHA1}'\ + -w -s" + else + go build -trimpath -o ${TARGET} \ + -ldflags "-X 'main.version=${BUILD_VERSION}' \ + -X 'main.buildDate=${BUILD_DATE}' \ + -X 'main.commitID=${COMMIT_SHA1}'\ + -w -s" + fi +done + diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..6290f5b --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,29 @@ +on: + push: # 每次带有 tag 的 push 候触发 + tags: + - 'v*' + +name: Build Release +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master # checkout 代码 + - uses: actions/setup-go@v2 # 配置 Go 环境 + with: + go-version: "1.18" # 改成自己的版本 + + - run: bash .cross_compile.sh + + - name: Release + uses: softprops/action-gh-release@v1 + with: # 将下述可执行文件 release 上去 + draft: false # Release草稿 + files: | + dist/nf_darwin_amd64 + dist/nf_darwin_arm64 + dist/nf_linux_amd64 + dist/nf_linux_arm64 + dist/nf_linux_mips + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index c620db4..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,29 +0,0 @@ -# .github/workflows/release.yaml -on: - push: - branches: - - master - -jobs: - releases-matrix: - name: Release Go Binary - runs-on: ubuntu-latest - strategy: - matrix: - # build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64 - goos: [linux, windows, darwin] - goarch: ["386", amd64] - exclude: - - goarch: "386" - goos: darwin - steps: - - uses: actions/checkout@v2 - - uses: wangyoucao577/[email protected] - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - goos: ${{ matrix.goos }} - goarch: ${{ matrix.goarch }} - goversion: "https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz" - project_path: "./cmd/test-binary" - binary_name: "test-binary" - extra_files: LICENSE README.md |