From 7a605a307883a4ec15a5048cbf1aeb663654c9d9 Mon Sep 17 00:00:00 2001 From: kanaduchi Date: Mon, 27 Jul 2026 11:47:11 +0100 Subject: [PATCH] Add release workflow --- .github/workflows/release.yml | 102 ++++++++++++++++++++++++++++++++++ 1 file changed, 102 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 000000000..71e5162f4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,102 @@ +name: release + +on: + workflow_dispatch: + inputs: + version: + description: "Version without v prefix (e.g. 1.10.1). Leave empty to bump from the latest tag." + required: false + type: string + bump: + description: "Used only when version is empty" + required: true + type: choice + options: + - patch + - minor + - major + default: patch + draft: + description: "Create as draft release" + required: true + type: boolean + default: false + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Resolve version + id: version + env: + INPUT_VERSION: ${{ inputs.version }} + INPUT_BUMP: ${{ inputs.bump }} + run: | + set -euo pipefail + + latest="$(git describe --tags --abbrev=0 2>/dev/null || true)" + latest="${latest#v}" + + if [ -n "${INPUT_VERSION}" ]; then + version="${INPUT_VERSION#v}" + else + if [ -z "${latest}" ]; then + case "${INPUT_BUMP}" in + major) version="1.0.0" ;; + minor) version="0.1.0" ;; + *) version="0.0.1" ;; + esac + else + IFS=. read -r major minor patch <&2 + exit 1 + fi + + if git rev-parse "refs/tags/${version}" >/dev/null 2>&1; then + echo "Tag ${version} already exists" >&2 + exit 1 + fi + + echo "version=${version}" >> "${GITHUB_OUTPUT}" + echo "Resolved version: ${version} (previous: ${latest:-none})" + + - name: Create GitHub Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + version="${{ steps.version.outputs.version }}" + args=(--generate-notes --target "${GITHUB_SHA}" --title "${version}" "${version}") + if [ "${{ inputs.draft }}" = "true" ]; then + args=(--draft "${args[@]}") + fi + gh release create "${args[@]}"