From 8ebace4d9abba0cc6e56543b6df4f49381b29f94 Mon Sep 17 00:00:00 2001 From: Miao Wang Date: Fri, 11 Sep 2020 17:43:31 +0800 Subject: [PATCH] Add support for multiarch builds --- .github/workflows/release.yml | 26 +++++++++----------------- .github/workflows/tunasync.yml | 2 +- .gitignore | 1 + Makefile | 25 ++++++++++++++----------- 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d66403d..bc6d1ec 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,16 +21,12 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2 - - name: Get dependencies - run: | - go get -v -t -d ./cmd/tunasync - go get -v -t -d ./cmd/tunasynctl - - name: Build run: | - make tunasync - make tunasynctl - tar -jcf build/tunasync-linux-bin.tar.bz2 -C build tunasync tunasynctl + for i in linux-amd64 linux-arm64; do + make ARCH=$i all + tar -cz --numeric-owner --owner root -f tunasync-$i-bin.tar.gz -C build-$i tunasync tunasynctl + done - name: Create Release id: create_release @@ -42,13 +38,9 @@ jobs: release_name: Release ${{ github.ref }} draft: false prerelease: false - - name: Upload Release Asset - id: upload-release-asset - uses: actions/upload-release-asset@v1 + - name: Upload Release Assets env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: ./build/tunasync-linux-bin.tar.bz2 - asset_name: tunasync-linux-bin.tar.bz2 - asset_content_type: application/x-bzip2 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG_NAME: ${{ github.ref }} + run: | + hub release edit $(find . -type f -name "tunasync-*.tar.gz" -printf "-a %p ") -m "" "${TAG_NAME##*/}" diff --git a/.github/workflows/tunasync.yml b/.github/workflows/tunasync.yml index 8a264b1..d6e6120 100644 --- a/.github/workflows/tunasync.yml +++ b/.github/workflows/tunasync.yml @@ -32,7 +32,7 @@ jobs: uses: actions/upload-artifact@v1 with: name: tunasync-bin - path: build/ + path: build-linux-amd64/ test: name: Test diff --git a/.gitignore b/.gitignore index 796b96d..7e6d811 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /build +/build-* diff --git a/Makefile b/Makefile index 371b495..f495a9f 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,22 @@ LDFLAGS="-X main.buildstamp=`date -u '+%s'` -X main.githash=`git rev-parse HEAD`" +ARCH ?= linux-amd64 +ARCH_LIST = $(subst -, ,$(ARCH)) +GOOS = $(word 1, $(ARCH_LIST)) +GOARCH = $(word 2, $(ARCH_LIST)) +BUILDBIN = tunasync tunasynctl -all: get tunasync tunasynctl +all: $(BUILDBIN) -get: - go get ./cmd/tunasync - go get ./cmd/tunasynctl +build-$(ARCH): + mkdir -p $@ -build: - mkdir -p build +$(BUILDBIN): % : build-$(ARCH) build-$(ARCH)/% -tunasync: build - go build -o build/tunasync -ldflags ${LDFLAGS} github.com/tuna/tunasync/cmd/tunasync - -tunasynctl: build - go build -o build/tunasynctl -ldflags ${LDFLAGS} github.com/tuna/tunasync/cmd/tunasynctl +$(BUILDBIN:%=build-$(ARCH)/%) : build-$(ARCH)/% : cmd/% + GOOS=$(GOOS) GOARCH=$(GOARCH) go get ./$< + GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $@ -ldflags ${LDFLAGS} github.com/tuna/tunasync/$< test: go test -v -covermode=count -coverprofile=profile.cov ./... + +.PHONY: all test $(BUILDBIN)