Skip to content

发布

发布 #5

Workflow file for this run

name: 发布
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "要发布的版本标签,例如 v0.1.1"
required: true
type: string
permissions:
contents: write
jobs:
test:
name: 测试 (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.23.x"
- run: go test ./...
- run: go vet ./...
- name: 检查 Linux 安装脚本
if: runner.os == 'Linux'
run: |
sh -n scripts/install.sh
sh scripts/install_sh_test.sh
build:
name: ${{ matrix.goos }}-${{ matrix.goarch }}
needs: test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: windows
goarch: amd64
extension: .exe
archive: zip
- goos: linux
goarch: amd64
extension: ""
archive: tar.gz
- goos: linux
goarch: arm64
extension: ""
archive: tar.gz
- goos: darwin
goarch: amd64
extension: ""
archive: tar.gz
- goos: darwin
goarch: arm64
extension: ""
archive: tar.gz
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.23.x"
- name: 构建并压缩
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
EXTENSION: ${{ matrix.extension }}
ARCHIVE: ${{ matrix.archive }}
VERSION: ${{ inputs.tag || github.ref_name }}
run: |
VERSION="${VERSION#v}"
mkdir -p dist
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X github.com/certd/certd-client/internal/version.Version=${VERSION}" -o "dist/certd-client${EXTENSION}" ./cmd/certd-client
if [ "$ARCHIVE" = "zip" ]; then
(cd dist && zip "certd-client-${GOOS}-${GOARCH}.zip" "certd-client${EXTENSION}")
else
tar -C dist -czf "dist/certd-client-${GOOS}-${GOARCH}.tar.gz" "certd-client${EXTENSION}"
fi
- uses: actions/upload-artifact@v4
with:
name: certd-client-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/certd-client-${{ matrix.goos }}-${{ matrix.goarch }}.${{ matrix.archive }}
if-no-files-found: error
github-release:
name: 创建 GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.ref }}
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: 读取发布说明
env:
TAG: ${{ inputs.tag || github.ref_name }}
run: |
version="${TAG#v}"
heading="## [${version}]"
if ! grep -Fq "$heading - " CHANGELOG.md; then
echo "CHANGELOG.md 中未找到 ${heading}" >&2
exit 1
fi
awk -v version="$version" '
index($0, "## [" version "] - ") == 1 { found = 1; next }
found && /^## \[/ { exit }
found { print }
' CHANGELOG.md > release-notes.md
- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.tag || github.ref_name }}
target_commitish: ${{ github.sha }}
body_path: release-notes.md
files: dist/*