From b0fcb11abbfa3916ba57db3db18485a210f1a04a Mon Sep 17 00:00:00 2001 From: Riobard Date: Thu, 20 Feb 2020 19:20:25 +0800 Subject: [PATCH] Updated workflow --- .github/workflows/build.yml | 26 +++------------- .github/workflows/release.yml | 57 ++++++++--------------------------- Makefile | 28 +++++++++++++++-- 3 files changed, 44 insertions(+), 67 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe18be92..2b1b40c3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,28 +1,12 @@ -name: Build +name: Build and test on: [push] jobs: - build: - name: Build runs-on: ubuntu-latest steps: - - - name: Set up Go 1.13 - uses: actions/setup-go@v1 + - uses: actions/setup-go@v1 with: go-version: 1.13 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi - - - name: Build - run: go build -v . + - uses: actions/checkout@v2 + - run: make -j all + - run: make -j test \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c7f49d86..5d2a09fa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,47 +1,16 @@ -name: Release -on: release +name: Build and release +on: + release: + types: [published] jobs: - release-linux-amd64: - name: release linux/amd64 + build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master - - name: compile and release - uses: ngs/go-release.action@v1.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GOARCH: amd64 - GOOS: linux - release-darwin-amd64: - name: release darwin/amd64 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: compile and release - uses: ngs/go-release.action@v1.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GOARCH: amd64 - GOOS: darwin - release-windows-386: - name: release windows/386 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: compile and release - uses: ngs/go-release.action@v1.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GOARCH: "386" - GOOS: windows - release-windows-amd64: - name: release windows/amd64 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: compile and release - uses: ngs/go-release.action@v1.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GOARCH: amd64 - GOOS: windows + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13 + - run: make -j upload + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_RELEASE_UPLOAD_URL: ${{ github.event.release.upload_url }} \ No newline at end of file diff --git a/Makefile b/Makefile index 666ebba7..c585cea6 100644 --- a/Makefile +++ b/Makefile @@ -17,12 +17,36 @@ win64: win32: GOARCH=386 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe + +test: test-linux test-macos test-win64 test-win32 + +test-linux: + GOARCH=amd64 GOOS=linux go test + +test-macos: + GOARCH=amd64 GOOS=darwin go test + +test-win64: + GOARCH=amd64 GOOS=windows go test + +test-win32: + GOARCH=386 GOOS=windows go test + releases: linux macos win64 win32 chmod +x $(BINDIR)/$(NAME)-* gzip $(BINDIR)/$(NAME)-linux gzip $(BINDIR)/$(NAME)-macos - zip -m -j $(BINDIR)/$(NAME)-win64.zip $(BINDIR)/$(NAME)-win64.exe zip -m -j $(BINDIR)/$(NAME)-win32.zip $(BINDIR)/$(NAME)-win32.exe + zip -m -j $(BINDIR)/$(NAME)-win64.zip $(BINDIR)/$(NAME)-win64.exe clean: - rm $(BINDIR)/* \ No newline at end of file + rm $(BINDIR)/* + +# Remove trailing {} from the release upload url +GITHUB_UPLOAD_URL=$(shell echo $${GITHUB_RELEASE_UPLOAD_URL%\{*}) + +upload: releases + curl -H "Authorization: token $(GITHUB_TOKEN)" -H "Content-Type: application/gzip" --data-binary @$(BINDIR)/$(NAME)-linux.gz "$(GITHUB_UPLOAD_URL)?name=$(NAME)-linux.gz" + curl -H "Authorization: token $(GITHUB_TOKEN)" -H "Content-Type: application/gzip" --data-binary @$(BINDIR)/$(NAME)-macos.gz "$(GITHUB_UPLOAD_URL)?name=$(NAME)-macos.gz" + curl -H "Authorization: token $(GITHUB_TOKEN)" -H "Content-Type: application/zip" --data-binary @$(BINDIR)/$(NAME)-win64.zip "$(GITHUB_UPLOAD_URL)?name=$(NAME)-win64.zip" + curl -H "Authorization: token $(GITHUB_TOKEN)" -H "Content-Type: application/zip" --data-binary @$(BINDIR)/$(NAME)-win32.zip "$(GITHUB_UPLOAD_URL)?name=$(NAME)-win32.zip" \ No newline at end of file