调整: 同步 1.0.2 发布文档 #2
Workflow file for this run
This file contains hidden or 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: | |
| 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 { | |
| } | |
| ' 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 |