From 55f360357d955c97bb52d3d0c886f03cbcff62a4 Mon Sep 17 00:00:00 2001 From: lyyyuna Date: Wed, 24 Jun 2020 11:08:42 +0800 Subject: [PATCH 1/3] Add release Action --- .github/workflows/release.yml | 55 +++++++++++++++++++++++++++++++++++ ci-build.sh | 33 +++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100755 ci-build.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..eb559a7 --- /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: | + ./ci-build.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: | + ./ci-build.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: | + ./ci-build.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GOARCH: amd64 + GOOS: darwin \ No newline at end of file diff --git a/ci-build.sh b/ci-build.sh new file mode 100755 index 0000000..3d357e8 --- /dev/null +++ b/ci-build.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_NAME=$(echo $EVENT_DATA | jq -r .release.tag_name) +PROJECT_NAME=$(basename $GITHUB_REPOSITORY) +NAME="${NAME:-${PROJECT_NAME}_${RELEASE_NAME}}_${GOOS}_${GOARCH}" + +go build . + +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}_checksum.txt" \ No newline at end of file From 55d927ba0de2bbae29aaf5a4f8f016e4ab807d46 Mon Sep 17 00:00:00 2001 From: lyyyuna Date: Wed, 24 Jun 2020 13:04:24 +0800 Subject: [PATCH 2/3] checksum file name --- ci-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci-build.sh b/ci-build.sh index 3d357e8..4f53e9e 100755 --- a/ci-build.sh +++ b/ci-build.sh @@ -30,4 +30,4 @@ curl \ --data $CHECKSUM \ -H 'Content-Type: text/plain' \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - "${UPLOAD_URL}?name=${NAME}_checksum.txt" \ No newline at end of file + "${UPLOAD_URL}?name=${NAME}_md5.txt" \ No newline at end of file From 4daa2f43cff74dbcc45411934b112ea382b1dc02 Mon Sep 17 00:00:00 2001 From: lyyyuna Date: Wed, 24 Jun 2020 13:13:49 +0800 Subject: [PATCH 3/3] name convention --- ci-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci-build.sh b/ci-build.sh index 4f53e9e..f9fc2d9 100755 --- a/ci-build.sh +++ b/ci-build.sh @@ -8,7 +8,7 @@ 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}" +NAME="${NAME:-${PROJECT_NAME}-${RELEASE_NAME}}-${GOOS}-${GOARCH}" go build .