From 2a2561eeaa16b8aff64ae6bdcc68f25e45ad169d Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 28 Dec 2021 11:18:50 +0800 Subject: [PATCH] Update Release.yml --- .github/workflows/Release.yml | 58 +++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 95a8aa3..01f68dc 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -1,27 +1,45 @@ -on: - push: # 每次 push 的时候触发 - -name: Build Release +name: Release +on: [push] jobs: - release: - if: startsWith(github.ref, 'refs/tags/') # 只有这次 Commit 是 创建 Tag 时,才进行后续发布操作 + build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master # checkout 代码 - - uses: actions/setup-go@v2 # 配置 Go 环境 + - name: Get latest go version + id: version + run: | + echo ::set-output name=go_version::$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g') + + - name: Setup Go + uses: actions/setup-go@v2 with: - go-version: "1.17" # 改成自己的版本 - - run: go get ../. - - run: go build -o ./linux_amd64/mweb_export . # 这 3 条是交叉编译 Go 的指令,酌情修改。 - - run: CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o ./windows_amd64/mweb_export.exe . - - run: CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o ./darwin_amd64/mweb_export . + go-version: ${{ steps.version.outputs.go_version }} - - name: Release - uses: softprops/action-gh-release@v1 - with: # 将下述可执行文件 release 上去 - files: | - ./linux_amd64/mweb_export - ./windows_amd64/mweb_export.exe - ./darwin_amd64/mweb_export + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Cache go module + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Get dependencies, run test + run: | + go test ./... + + - name: Build + if: startsWith(github.ref, 'refs/tags/') env: + NAME: mweb-export + BINDIR: bin + run: make -j releases + + - name: Upload Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + files: bin/* + draft: true