diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f1c3fc4..707aed9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,6 +6,8 @@ on: - "README.md" branches: - main + tags: + - 'v*.*.*' pull_request: workflow_dispatch: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a8efb59 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,68 @@ +name: Release + +on: + push: + branches: + - prod + workflow_dispatch: + inputs: + version: + description: 'Version to release (e.g. 1.2.3, leave empty to auto-bump patch)' + required: false + type: string + +jobs: + release: + name: Create Release + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check for existing tag on HEAD + id: idempotency + run: | + EXISTING=$(git describe --exact-match --tags HEAD 2>/dev/null || true) + if echo "$EXISTING" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then + echo "HEAD is already tagged as $EXISTING — skipping release." + echo "skip=true" >> $GITHUB_OUTPUT + else + echo "skip=false" >> $GITHUB_OUTPUT + fi + + - name: Determine version + if: steps.idempotency.outputs.skip == 'false' + id: version + run: | + if [ -n "${{ inputs.version }}" ]; then + NEW_VERSION="v${{ inputs.version }}" + else + LATEST=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") + MAJOR=$(echo "${LATEST#v}" | cut -d. -f1) + MINOR=$(echo "${LATEST#v}" | cut -d. -f2) + PATCH=$(echo "${LATEST#v}" | cut -d. -f3) + NEW_VERSION="v${MAJOR}.${MINOR}.$((PATCH + 1))" + fi + echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT + echo "Releasing ${NEW_VERSION}" + + - name: Create and push tag + if: steps.idempotency.outputs.skip == 'false' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag ${{ steps.version.outputs.version }} + git push origin ${{ steps.version.outputs.version }} + + - name: Create GitHub Release + if: steps.idempotency.outputs.skip == 'false' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create ${{ steps.version.outputs.version }} \ + --generate-notes \ + --title "Release ${{ steps.version.outputs.version }}"