v0.4.6 #48
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release分发 | |
on: | |
release: | |
types: [created] # 表示在创建新的 Release 时触发 | |
jobs: | |
changelog: | |
name: Generate Changelog | |
runs-on: ubuntu-latest | |
outputs: | |
release_body: ${{ steps.git-cliff.outputs.content }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Generate a changelog | |
uses: orhun/git-cliff-action@v2 | |
id: git-cliff | |
with: | |
config: git-cliff/cliff.toml | |
args: -vv --latest --strip 'footer' | |
env: | |
OUTPUT: CHANGES.md | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
body: ${{ steps.git-cliff.outputs.content }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
build-test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
go: [ '1.20', '1.21','stable' ] | |
name: Go ${{ matrix.go }} Build Test | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ matrix.go }} | |
check-latest: true | |
- name: Get Git Commit Log | |
id: git-commit-log | |
run: echo "GIT_COMMIT_LOG=${{ github.sha }}" >> $GITHUB_ENV | |
- name: Get current time | |
uses: josStorer/get-current-time@v2 | |
id: current-time | |
with: | |
format: YYYYMMDD-HH | |
utcOffset: "+08:00" | |
- name: Get Build Time | |
id: build-time | |
run: echo "BUILD_TIME=${{ steps.current-time.outputs.readableTime }}" >> $GITHUB_ENV | |
- name: Print Environment Variables | |
run: | | |
echo "${{env.GIT_COMMIT_LOG}}" | |
echo "${{env.BUILD_TIME}}" | |
- name: Go Build Binary - Windows amd64 | |
run: | | |
GOOS=windows GOARCH=amd64 go build | |
pwd | |
go-test: | |
runs-on: windows-latest | |
needs: [changelog, build-test] | |
environment: production | |
name: Go Test | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
cache: false | |
- name: Go Test | |
run: | | |
go test -v ./g_test -tag="@test" -baseurl="${{ secrets.BACKEND_URL }}" | |
pwd | |
build-go-binary: | |
runs-on: ubuntu-latest | |
needs: go-test | |
name: Go Build Binary | |
env: | |
GOOS: windows | |
GOARCH: amd64 | |
steps: | |
- name: Get version | |
id: get_version | |
run: echo "CURRENT_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV | |
- uses: actions/checkout@v4 | |
- uses: hamster1963/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} # 一个默认的变量,用来实现往 Release 中添加文件 | |
goos: ${{ env.GOOS }} | |
goarch: ${{ env.GOARCH }} | |
goversion: 1.21.0 # 可以指定编译使用的 Golang 版本 | |
ldflags: -X "main.GitTag=${{ env.CURRENT_VERSION }}" -X "main.BackendBaseUrl=${{ secrets.BACKEND_URL }}" # 通过 ldflags 注入版本号 | |
pre_command: export CGO_ENABLED=0 && export GODEBUG=http2client=0 | |
overwrite: true | |
asset_name: "speed_cron_${{ env.GOOS }}_${{ env.GOARCH }}" # 可以指定二进制文件的名称 | |
compress_assets: OFF # 可以指定是否压缩二进制文件 | |