From 2c4ccfd19f0cefb02468351c3ae9ae83bfd50335 Mon Sep 17 00:00:00 2001 From: hunterlong Date: Tue, 5 May 2020 02:22:07 -0700 Subject: [PATCH] xgo builds --- .github/workflows/master.yml | 98 +++++++++++++++++++----------------- Makefile | 54 ++++++++++---------- 2 files changed, 78 insertions(+), 74 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 2e3ea54c..35e43c09 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -204,10 +204,7 @@ jobs: shell: bash - name: Download Go mods - if: steps.golangcache.outputs.cache-hit != 'true' run: | - go mod download - go mod verify make test-deps - name: Download Compiled Frontend (rice-box.go) @@ -216,11 +213,17 @@ jobs: name: static-rice-box path: ./source - - name: Build Binaries - env: - VERSION: ${{ env.VERSION }} - COMMIT: $GITHUB_SHA - run: make build-mac + - name: Build with xgo + uses: crazy-max/ghaction-xgo@v1 + with: + xgo_version: latest + go_version: 1.14.2 + dest: build + prefix: statping + targets: darwin/386,darwin/amd64 + v: true + x: false + ldflags: -s -w -X main.VERSION=$VERSION - name: Upload MacOSX Builds uses: actions/upload-artifact@v1 @@ -237,11 +240,6 @@ jobs: go-version: '1.14.2' - uses: actions/checkout@v2 - - name: Install Libraries - run: | - sudo apt update - sudo apt install libc-dev gcc-multilib build-essential musl-dev gcc g++ -y - - name: Setting ENV's run: | echo "::add-path::$(go env GOPATH)/bin" @@ -250,10 +248,7 @@ jobs: shell: bash - name: Download Go mods - if: steps.golangcache.outputs.cache-hit != 'true' run: | - go mod download - go mod verify make test-deps - name: Download Compiled Frontend (rice-box.go) @@ -262,13 +257,17 @@ jobs: name: static-rice-box path: ./source - - name: Build Binaries - env: - VERSION: ${{ env.VERSION }} - COMMIT: $GITHUB_SHA - run: | - go env - make build-linux + - name: Build with xgo + uses: crazy-max/ghaction-xgo@v1 + with: + xgo_version: latest + go_version: 1.14.2 + dest: build + prefix: statping + targets: linux/386,linux/amd64,linux/arm-6,linux/arm-7,linux/arm,linux/arm64 + v: true + x: false + ldflags: -s -w -extldflags -static -X main.VERSION=$VERSION - name: Upload Linux Builds uses: actions/upload-artifact@v1 @@ -293,10 +292,7 @@ jobs: shell: bash - name: Download Go mods - if: steps.golangcache.outputs.cache-hit != 'true' run: | - go mod download - go mod verify make test-deps - name: Download Compiled Frontend (rice-box.go) @@ -305,11 +301,17 @@ jobs: name: static-rice-box path: ./source - - name: Build Binaries - env: - VERSION: ${{ env.VERSION }} - COMMIT: $GITHUB_SHA - run: make build-win + - name: Build with xgo + uses: crazy-max/ghaction-xgo@v1 + with: + xgo_version: latest + go_version: 1.14.2 + dest: build + prefix: statping + targets: windows/386,windows/amd64 + v: true + x: false + ldflags: -s -w -extldflags -static -X main.VERSION=$VERSION - name: Upload Windows Builds uses: actions/upload-artifact@v1 @@ -348,6 +350,14 @@ jobs: name: windows-builds path: ./windows + - name: Compress Files + run: | + mkdir build + mv windows/*.* ./build/ + mv linux/*.* ./build/ + mv darwin/*.* ./build/ + make compress + - name: Upload Linux Release id: upload-linux-asset uses: softprops/action-gh-release@v1 @@ -359,17 +369,12 @@ jobs: draft: false prerelease: false files: | - linux/statping-freebsd-386.tar.gz - linux/statping-freebsd-amd64.tar.gz - linux/statping-freebsd-arm.tar.gz - linux/statping-linux-386.tar.gz - linux/statping-linux-amd64.tar.gz - linux/statping-linux-arm.tar.gz - linux/statping-linux-arm64.tar.gz - linux/statping-openbsd-386.tar.gz - linux/statping-openbsd-amd64.tar.gz - linux/statping-openbsd-arm.tar.gz - linux/statping-openbsd-arm64.tar.gz + build/statping-linux-386.tar.gz + build/statping-linux-amd64.tar.gz + build/statping-linux-arm.tar.gz + build/statping-linux-arm64.tar.gz + build/statping-linux-arm-7.tar.gz + build/statping-linux-arm-6.tar.gz - name: Upload MaxOSX Release id: upload-darwin-asset @@ -382,8 +387,8 @@ jobs: draft: false prerelease: false files: | - darwin/statping-darwin-386.tar.gz - darwin/statping-darwin-amd64.tar.gz + build/statping-darwin-386.tar.gz + build/statping-darwin-amd64.tar.gz - name: Upload Windows Release id: upload-windows-asset @@ -396,9 +401,8 @@ jobs: draft: false prerelease: false files: | - windows/statping-windows-386.zip - windows/statping-windows-amd64.zip - windows/statping-windows-arm.zip + build/statping-windows-386.zip + build/statping-windows-amd64.zip docker-release: needs: upload-release diff --git a/Makefile b/Makefile index c39f6afc..62d486d6 100644 --- a/Makefile +++ b/Makefile @@ -11,9 +11,8 @@ TRAVIS_BUILD_CMD='{ "request": { "branch": "master", "message": "Compile master TEST_DIR=$(GOPATH)/src/github.com/statping/statping PATH:=/usr/local/bin:$(GOPATH)/bin:$(PATH) OS = freebsd linux openbsd -WIN_ARCHS = 386 amd64 arm arm64 LINUX_ARCHS = 386 amd64 arm-7 arm-6 arm64 arm -OSX_ARCHS = 386 amd64 +BASIC_ARCHS = 386 amd64 all: clean yarn-install compile docker-base docker-vue build-all @@ -58,6 +57,7 @@ test-deps: go get golang.org/x/tools/cmd/cover go get github.com/mattn/goveralls go get github.com/GeertJohan/go.rice/rice + go get github.com/crazy-max/xgo deps: go get -d -v -t ./... @@ -153,38 +153,38 @@ install-local: build generate: cd source && go generate -build-linux: - xgo -go $(GOVERSION) --dest=build -ldflags "-X main.VERSION=${VERSION}" --targets=linux/amd64,linux/386,linux/arm-7,linux/arm-6,linux/arm64,linux/arm -out statping ./cmd +compress: + mkdir releases || true; @for arch in $(LINUX_ARCHS);\ do \ - echo "Releasing v$$VERSION for linux-$$arch"; \ + echo "Compressing v$$VERSION for linux-$$arch"; \ mkdir -p build/statping-linux-$$arch/; \ - chmod +x build/statping-linux-$$arch; \ - mv build/statping-linux-$$arch build/statping-linux-$$arch/statping; \ - tar -czf build/statping-linux-$$arch.tar.gz -C build/statping-linux-$$arch statping; \ + chmod +x build/statping-linux-$$arch && mv build/statping-linux-$$arch build/statping-linux-$$arch/statping; \ + tar -czf releases/statping-linux-$$arch.tar.gz -C build/statping-linux-$$arch statping; \ done + @for arch in $(BASIC_ARCHS);\ + do \ + echo "Compressing v$$VERSION for darwin-$$arch"; \ + mkdir -p build/statping-darwin-$$arch/; \ + chmod +x build/statping-darwin-10.6-$$arch && mv build/statping-darwin-10.6-$$arch build/statping-darwin-$$arch/statping; \ + tar -czf releases/statping-darwin-$$arch.tar.gz -C build/statping-darwin-$$arch statping; \ + done + @for arch in $(BASIC_ARCHS);\ + do \ + echo "Compressing v$$VERSION for windows-$$arch"; \ + mkdir -p build/statping-windows-$$arch/; \ + chmod +x build/statping-windows-6.0-$$arch.exe && mv build/statping-windows-6.0-$$arch.exe build/statping-windows-$$arch/statping.exe; \ + zip -j releases/statping-windows-$$arch.zip build/statping-windows-$$arch/statping.exe; \ + done + +build-linux: + xgo -go $(GOVERSION) --dest=build -ldflags "-s -w -extldflags -static -X main.VERSION=${VERSION}" --targets=linux/amd64,linux/386,linux/arm-7,linux/arm-6,linux/arm64,linux/arm -out statping ./cmd build-mac: - xgo -go $(GOVERSION) --dest=build -ldflags "-X main.VERSION=${VERSION}" --targets=darwin/amd64,darwin/386 -out statping ./cmd - @for arch in $(OSX_ARCHS);\ - do \ - echo "Releasing v$$VERSION for darwin-$$arch"; \ - mkdir -p build/statping-darwin-$$arch/; \ - chmod +x build/statping-darwin-10.6-$$arch; \ - mv build/statping-darwin-10.6-$$arch build/statping-darwin-$$arch/statping; \ - tar -czf build/statping-darwin-$$arch.tar.gz -C build/statping-darwin-$$arch statping; \ - done + xgo -go $(GOVERSION) --dest=build -ldflags "-s -w -X main.VERSION=${VERSION}" --targets=darwin/amd64,darwin/386 -out statping ./cmd build-win: - xgo -go $(GOVERSION) --dest=build -ldflags "-X main.VERSION=${VERSION}" --targets=windows-6.0/amd64,windows-6.0/386,windows-6.0/arm,windows-6.0/arm64 -out statping ./cmd - @for arch in $(WIN_ARCHS);\ - do \ - echo "Releasing v$$VERSION for windows-6.0-$$arch"; \ - mkdir -p build/statping-windows-6.0-$$arch/; \ - chmod +x build/statping-windows-6.0-$$arch; \ - mv build/statping-windows-6.0-$$arch build/statping-windows-$$arch/statping; \ - tar -czf build/statping-windows-$$arch.tar.gz -C build/statping-windows-$$arch statping; \ - done + xgo -go $(GOVERSION) --dest=build -ldflags "-s -w -extldflags -static -X main.VERSION=${VERSION}" --targets=windows-6.0/amd64,windows-6.0/386 -out statping ./cmd # remove files for a clean compile/build clean: @@ -225,7 +225,7 @@ print_details: @echo \==== Monitoring and IDE ==== @echo \Grafana: http://localhost:3000 \(username: admin, password: admin\) -build-all: clean compile build-linux build-mac build-win +build-all: clean compile build-linux build-mac build-win compress coverage: test-deps $(GOPATH)/bin/goveralls -coverprofile=coverage.out -service=travis -repotoken $(COVERALLS)