From 5ba64c5c6e61d0afe3cb1dabe89f59c72cad7ce9 Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Wed, 17 Feb 2021 12:49:24 +0000 Subject: [PATCH] Add new Release Workflow using Github Actions and wangyoucao577/go-release-action --- .github/workflows/release.yaml | 30 ++++++++++++++++++++++++++++++ config.go | 5 +++-- main.go | 2 +- scripts/release.sh | 34 ---------------------------------- 4 files changed, 34 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/release.yaml delete mode 100755 scripts/release.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..cb12f15f --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,30 @@ +name: Release Go Binaries + +on: + release: + types: [created] + +jobs: + releases-matrix: + name: Release Go Binary + runs-on: ubuntu-latest + strategy: + matrix: + goos: [freebsd, linux, windows] + goarch: ["386", amd64] + steps: + - uses: actions/checkout@v2 + + - name: Set APP_VERSION env + run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV} + - name: Set BUILD_TIME env + run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV} + + - uses: wangyoucao577/go-release-action@v1.14 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + goos: ${{ matrix.goos }} + goarch: ${{ matrix.goarch }} + goversion: "https://golang.org/dl/go1.15.8.linux-amd64.tar.gz" + extra_files: LICENSE README.md smtprelay.ini + ldflags: -s -w -X "main.appVersion=${{ env.APP_VERSION }}" -X "main.buildTime=${{ env.BUILD_TIME }}" diff --git a/config.go b/config.go index b47c9541..2ff92a7f 100644 --- a/config.go +++ b/config.go @@ -6,8 +6,9 @@ import ( "github.com/vharitonsky/iniflags" ) -const ( - VERSION = "1.4.0" +var ( + appVersion = "unknown" + buildTime = "unknown" ) var ( diff --git a/main.go b/main.go index efc9d2af..2e7d518a 100644 --- a/main.go +++ b/main.go @@ -234,7 +234,7 @@ func main() { ConfigLoad() if *versionInfo { - fmt.Printf("smtprelay/%s\n", VERSION) + fmt.Printf("smtprelay/%s (%s)\n", appVersion, buildTime) os.Exit(0) } diff --git a/scripts/release.sh b/scripts/release.sh deleted file mode 100755 index 6d44ffd1..00000000 --- a/scripts/release.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh - -PROJECT=smtprelay -VERSION=1.3.0 - -for goos in freebsd linux windows -do - for goarch in 386 amd64 - do - export GOOS=${goos} - export GOARCH=${goarch} - - RELDIR=${PROJECT}-${VERSION}-${GOOS}-${GOARCH} - - rm -rf ${RELDIR} - mkdir ${RELDIR} || exit 1 - cp -p README.md LICENSE ${PROJECT}.ini ${RELDIR}/ || exit 1 - - if [ ${GOOS} = "windows" ]; then - BINARY=${PROJECT}.exe - sed -I '' -e 's/;logfile =.*/logfile =/g' ${RELDIR}/${PROJECT}.ini - sed -I '' -e 's/$/^M/' ${RELDIR}/${PROJECT}.ini - else - BINARY=${PROJECT} - fi - - go build -ldflags="-s -w" -o ${RELDIR}/${BINARY} || exit 1 - - chown -R root:wheel ${RELDIR} || exit 1 - tar cvfJ ${RELDIR}.tar.xz ${RELDIR} || exit 1 - rm -rf ${RELDIR} - done -done -