From c6e28024fe5fe816d3ce44e28090d5bddf055299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=8D=E1=B4=8F=E1=B4=8F=C9=B4D4=CA=80=E1=B4=8B?= Date: Mon, 29 Jun 2020 15:44:41 +0800 Subject: [PATCH] add release github action --- .github/workflows/build.yml | 30 ------------------- .github/workflows/release.yml | 39 +++++++++++++++++++++++++ build.sh | 26 +++++++++++++++++ entrypoint.sh | 54 +++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 30 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml create mode 100644 build.sh create mode 100644 entrypoint.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 257b4c9..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Go - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - - build: - name: Build - runs-on: macos-latest - steps: - - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ^1.14 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Get dependencies - run: | - go get -v -t -d ./... - - - name: Build - run: go build -v . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..70376fe --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +on: release +name: Build Release +jobs: + release-darwin-amd64: + name: release darwin/amd64 + runs-on: macos-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 + EXTRA_FILES: "LICENSE" + release-windows-386: + name: release windows/386 + runs-on: windows-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 + EXTRA_FILES: "LICENSE" + 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 + EXTRA_FILES: "LICENSE" diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..6ca98b0 --- /dev/null +++ b/build.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -eux + +PROJECT_ROOT="/go/src/github.com/${GITHUB_REPOSITORY}" + +mkdir -p $PROJECT_ROOT +rmdir $PROJECT_ROOT +ln -s $GITHUB_WORKSPACE $PROJECT_ROOT +cd $PROJECT_ROOT +go get -v ./... + +EXT='' + +if [ $GOOS == 'windows' ]; then +EXT='.exe' +fi + +if [ -x "./build.sh" ]; then + OUTPUT=`./build.sh "${CMD_PATH}"` +else + go build "${CMD_PATH}" + OUTPUT="${PROJECT_NAME}${EXT}" +fi + +echo ${OUTPUT} \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..4efc2ba --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,54 @@ + +#!/bin/sh + +set -eux + +if [ -z "${CMD_PATH+x}" ]; then + echo "::warning file=entrypoint.sh,line=6,col=1::CMD_PATH not set" + export CMD_PATH="" +fi + +FILE_LIST=`/build.sh` + +#echo "::warning file=/build.sh,line=1,col=5::${FILE_LIST}" + +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_NAME=$(echo $EVENT_DATA | jq -r .release.tag_name) +PROJECT_NAME=$(basename $GITHUB_REPOSITORY) +NAME="${NAME:-${PROJECT_NAME}_${RELEASE_NAME}}_${GOOS}_${GOARCH}" + +if [ -z "${EXTRA_FILES+x}" ]; then +echo "::warning file=entrypoint.sh,line=22,col=1::EXTRA_FILES not set" +fi + +FILE_LIST="${FILE_LIST} ${EXTRA_FILES}" + +FILE_LIST=`echo "${FILE_LIST}" | awk '{$1=$1};1'` + + +if [ $GOOS == 'windows' ]; then +ARCHIVE=tmp.zip +zip -9r $ARCHIVE ${FILE_LIST} +else +ARCHIVE=tmp.tgz +tar cvfz $ARCHIVE ${FILE_LIST} +fi + +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}_checksum.txt" \ No newline at end of file