diff --git a/.github/workflows/e2e-linux.yml b/.github/workflows/e2e-linux.yml index 2fd0e7f..f93c7ca 100644 --- a/.github/workflows/e2e-linux.yml +++ b/.github/workflows/e2e-linux.yml @@ -1,4 +1,4 @@ -name: linux/macos e2e test +name: e2e test on: # Trigger the workflow on push or pull request, # but only for the master branch diff --git a/.github/workflows/e2e-wins.yml b/.github/workflows/e2e-wins.yml index da3d87e..83581f1 100644 --- a/.github/workflows/e2e-wins.yml +++ b/.github/workflows/e2e-wins.yml @@ -1,4 +1,4 @@ -name: windows e2e test +name: e2e test on: # Trigger the workflow on push or pull request, # but only for the master branch diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5890ac0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,55 @@ +on: + release: + types: [published,edited] +name: Build Release +jobs: + release-linux-amd64: + name: release linux/amd64 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.14.x + - name: compile and release + run: | + ./hack/release.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GOARCH: amd64 + GOOS: linux + + release-linux-386: + name: release linux/386 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.14.x + - name: compile and release + run: | + ./hack/release.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GOARCH: "386" + GOOS: linux + + release-darwin-amd64: + name: release darwin/amd64 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.14.x + - name: compile and release + run: | + ./hack/release.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GOARCH: amd64 + GOOS: darwin \ No newline at end of file diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..5f78e3b --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "fmt" + "runtime/debug" + + "github.com/spf13/cobra" +) + +var version = "unstable" + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the goc version information", + Example: ` +# Print the client and server versions for the current context +goc version + `, + Run: func(cmd *cobra.Command, args []string) { + // if it is "Unstable", means user build local or with go get + if version == "unstable" { + if info, ok := debug.ReadBuildInfo(); ok { + fmt.Println(info.Main.Version) + } + } else { + // otherwise the value is injected in CI + fmt.Println(version) + } + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/hack/release.sh b/hack/release.sh new file mode 100755 index 0000000..d888a5d --- /dev/null +++ b/hack/release.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -eux + +EVENT_DATA=$(cat $GITHUB_EVENT_PATH) +echo $EVENT_DATA | jq . +UPLOAD_URL=$(echo $EVENT_DATA | jq -r .release.upload_url) +UPLOAD_URL=${UPLOAD_URL/\{?name,label\}/} +RELEASE_VERSION=$(echo $EVENT_DATA | jq -r .release.tag_name) +PROJECT_NAME=$(basename $GITHUB_REPOSITORY) +NAME="${NAME:-${PROJECT_NAME}-${RELEASE_VERSION}}-${GOOS}-${GOARCH}" + +CGO_ENABLED=0 go build -ldflags "-X 'github.com/qiniu/goc/cmd.version=${RELEASE_VERSION}'" . + +ARCHIVE=tmp.tar.gz +FILE_LIST=goc +tar cvfz $ARCHIVE ${FILE_LIST} + +CHECKSUM=$(md5sum ${ARCHIVE} | cut -d ' ' -f 1) + +curl \ + -X POST \ + --data-binary @${ARCHIVE} \ + -H 'Content-Type: application/octet-stream' \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + "${UPLOAD_URL}?name=${NAME}.${ARCHIVE/tmp./}" + +curl \ + -X POST \ + --data $CHECKSUM \ + -H 'Content-Type: text/plain' \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + "${UPLOAD_URL}?name=${NAME}_md5.txt" \ No newline at end of file