Skip to content

Commit

Permalink
chore: add github action to release binary
Browse files Browse the repository at this point in the history
  • Loading branch information
fioncat committed Nov 29, 2022
1 parent 16cfb8b commit d139b74
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 22 deletions.
18 changes: 0 additions & 18 deletions .gitflow.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Features:**

**Fixes:**
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build Go

on:
push:
branches:
- "main"
pull_request:
branches:
- "main"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up go
uses: actions/setup-go@v3
with:
go-version: 1.19.2

- name: Build
run: go build ./...

30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release

on:
push:
tags:
- '*'

jobs:
release:
if: contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up go
uses: actions/setup-go@v3
with:
go-version: 1.19.3

- name: Build
run: bash hack/github-release.sh

- name: Create release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.RELEASE_GITHUB_TOKEN }}
files: |
out/*.zip
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
out
.vscode/
.idea/
bin/
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ build-windows-amd64:
.PHONY : build-all
build-all: build-darwin-amd64 build-darwin-arm64 build-linux-arm64 build-linux-amd64 build-windows-amd64

.PHONY : release
release:
@gitflow run release -f .gitflow.yaml

.PHONY: fmt
fmt:
gofmt -w -s $(GOFMT_FILES)
26 changes: 26 additions & 0 deletions hack/github-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -ue

targets=( \
"darwin_amd64" \
"darwin_arm64" \
"linux_amd64" \
"linux_arm64" \
"windows_amd64" \
"windows_arm64" \
)

VERSION=${GITHUB_REF#refs/*/}
echo "VERSION=${VERSION}" >> $GITHUB_ENV

mkdir -p out

for target in "${targets[@]}"; do
echo "Build target: ${target}"
IFS='_' read -r -a tmp <<< "$target"
BUILD_OS="${tmp[0]}"
BUILD_ARCH="${tmp[1]}"
GOOS="${BUILD_OS}" GOARCH="${BUILD_ARCH}" go build -mod=vendor -o bin/ucloud
zip -r out/ucloud-${target}.zip ./bin LICENSE
done

0 comments on commit d139b74

Please sign in to comment.