Skip to content

调整: 同步 1.0.2 发布文档 #2

调整: 同步 1.0.2 发布文档

调整: 同步 1.0.2 发布文档 #2

Workflow file for this run

name: Release
on:
push:
tags:
- "*"
workflow_dispatch:
inputs:
tag:
description: "Tag to publish, for example 1.0.0"
required: true
type: string
permissions:
contents: write
jobs:
release:
name: GitHub Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create or update release
env:
GH_TOKEN: ${{ github.token }}
TAG_NAME: ${{ inputs.tag || github.ref_name }}
run: |
set -euo pipefail
tag="${TAG_NAME}"
if [[ ! "${tag}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Skip non-semver tag: ${tag}"
exit 0
fi
git fetch --tags --force
if ! git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then
echo "Tag does not exist: ${tag}" >&2
exit 1
fi
version="${tag#v}"
notes_file="$(mktemp)"
awk -v version="${version}" '
BEGIN { in_section = 0 }
$0 ~ "^##[[:space:]]+" version "([[:space:]]|-|$)" {
in_section = 1
next
}
in_section && /^##[[:space:]]+/ {
exit
}
in_section {
print
}
' CHANGELOG.md > "${notes_file}"
if [[ ! -s "${notes_file}" ]]; then
printf 'Release %s\n' "${tag}" > "${notes_file}"
fi
if gh release view "${tag}" >/dev/null 2>&1; then
gh release edit "${tag}" --title "${tag}" --notes-file "${notes_file}"
else
gh release create "${tag}" --title "${tag}" --notes-file "${notes_file}" --verify-tag
fi