add release ci & add version cmd
This commit is contained in:
parent
3d70ce70d6
commit
5f4f5c5bd7
2
.github/workflows/e2e-linux.yml
vendored
2
.github/workflows/e2e-linux.yml
vendored
@ -1,4 +1,4 @@
|
|||||||
name: linux/macos e2e test
|
name: e2e test
|
||||||
on:
|
on:
|
||||||
# Trigger the workflow on push or pull request,
|
# Trigger the workflow on push or pull request,
|
||||||
# but only for the master branch
|
# but only for the master branch
|
||||||
|
2
.github/workflows/e2e-wins.yml
vendored
2
.github/workflows/e2e-wins.yml
vendored
@ -1,4 +1,4 @@
|
|||||||
name: windows e2e test
|
name: e2e test
|
||||||
on:
|
on:
|
||||||
# Trigger the workflow on push or pull request,
|
# Trigger the workflow on push or pull request,
|
||||||
# but only for the master branch
|
# but only for the master branch
|
||||||
|
55
.github/workflows/release.yml
vendored
Normal file
55
.github/workflows/release.yml
vendored
Normal file
@ -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
|
34
cmd/version.go
Normal file
34
cmd/version.go
Normal file
@ -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)
|
||||||
|
}
|
33
hack/release.sh
Executable file
33
hack/release.sh
Executable file
@ -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"
|
Loading…
Reference in New Issue
Block a user