-
Notifications
You must be signed in to change notification settings - Fork 3
102 lines (87 loc) · 2.92 KB
/
Copy pathrelease.yml
File metadata and controls
102 lines (87 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "要发布的标签(例如 v0.14.1)"
required: true
type: string
permissions:
contents: read
concurrency:
group: release-${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
preflight:
name: Release preflight checks
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.meta.outputs.tag }}
version: ${{ steps.meta.outputs.version }}
ref: ${{ steps.meta.outputs.ref }}
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4
with:
fetch-depth: 0
- name: Resolve release metadata
id: meta
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
tag="${{ inputs.tag }}"
else
tag="${GITHUB_REF_NAME}"
fi
if [[ ! "${tag}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
echo "::error::标签 ${tag} 不符合约定,必须是 vX.Y.Z(可带预发布后缀)"
exit 1
fi
version="${tag#v}"
cargo_version="$(sed -n 's/^version = \"\(.*\)\"/\1/p' Cargo.toml | head -n 1)"
if [[ -z "${cargo_version}" ]]; then
echo "::error::未能从 Cargo.toml 读取版本号"
exit 1
fi
if [[ "${cargo_version}" != "${version}" ]]; then
echo "::warning::Tag 版本(${version})与 Cargo.toml 版本(${cargo_version})不一致,已按宽松模式继续发布"
fi
if ! git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then
echo "::error::标签 ${tag} 不存在,请先创建并推送标签"
exit 1
fi
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "ref=${tag}" >> "$GITHUB_OUTPUT"
publish-release:
name: Publish GitHub release
runs-on: ubuntu-latest
needs: preflight
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4
with:
fetch-depth: 0
- name: Create or update GitHub release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.preflight.outputs.tag }}
run: |
set -euo pipefail
if gh release view "${TAG}" >/dev/null 2>&1; then
echo "Release ${TAG} 已存在,更新标题与说明..."
gh release edit "${TAG}" \
--title "${TAG}"
else
echo "创建 Release ${TAG}..."
gh release create "${TAG}" \
--title "${TAG}" \
--generate-notes
fi