From 074e4502c276643099d704900d3062fd45b80435 Mon Sep 17 00:00:00 2001 From: O96u Date: Sat, 22 Aug 2026 19:14:25 +0800 Subject: [PATCH] ci: auto-create GitHub Release from CHANGELOG on version tags Add workflow_dispatch to backfill releases for existing tags. --- .github/workflows/release.yml | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..86da3aa --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,59 @@ +name: GitHub Release + +on: + push: + tags: + - 'v*' + workflow_dispatch: + inputs: + tag: + description: '要发布 Release 的标签(如 v1.0.1)' + required: true + type: string + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }} + + - name: Extract release notes from CHANGELOG + id: notes + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + TAG="${{ inputs.tag }}" + else + TAG="${GITHUB_REF#refs/tags/}" + fi + VERSION="${TAG#v}" + BODY_FILE="${RUNNER_TEMP}/release-notes.md" + awk -v ver="$VERSION" ' + /^## \[/ { + if (found) exit + if ($0 ~ "\\[" ver "\\]") found = 1 + next + } + found { print } + ' CHANGELOG.md > "$BODY_FILE" + if [ ! -s "$BODY_FILE" ]; then + echo "未在 CHANGELOG.md 找到版本 ${VERSION},使用自动生成说明。" >&2 + echo "## PicHost ${TAG}" > "$BODY_FILE" + fi + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + echo "body_path=${BODY_FILE}" >> "$GITHUB_OUTPUT" + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.notes.outputs.tag }} + name: PicHost ${{ steps.notes.outputs.tag }} + body_path: ${{ steps.notes.outputs.body_path }} + draft: false + prerelease: false + make_latest: true