diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4b125f9..247fd61 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,16 @@ name: Release Workflow on: - release: - types: [created] + workflow_dispatch: + inputs: + tag: + description: 'Tag for the release (format: v{x}.{y}.{z})' + required: true + default: '' + release_name: + description: 'Release name/title' + required: true + default: '' jobs: build-and-release: @@ -20,24 +28,21 @@ jobs: distribution: 'temurin' java-version: '21' - # Check if release is a draft - - name: Check if release is a draft - id: check_draft + # Extract version from the provided tag + - name: Extract version from input tag + id: extract_version run: | - if [ "${{ github.event.release.draft }}" != "true" ]; then - echo "This workflow only runs on draft releases. Exiting." + TAG="${{ github.event.inputs.tag }}" + if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: Tag format must be v{x}.{y}.{z}" exit 1 fi - - # Extract version from the release tag - - name: Extract version from tag - id: extract_version - run: | - VERSION="${GITHUB_REF#refs/tags/v}" + VERSION="${TAG#v}" IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" echo "RELEASE_VERSION=${MAJOR}.${MINOR}.${PATCH}-1.21.3" >> $GITHUB_ENV echo "NEXT_SNAPSHOT_VERSION=${MAJOR}.${MINOR}.$((PATCH + 1))-1.21.3-SNAPSHOT" >> $GITHUB_ENV + # Update pom.xml to release version - name: Update version in pom.xml for release run: | @@ -90,17 +95,18 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} - # Publish the draft release - - name: Publish draft release - if: ${{ steps.check_draft.outcome == 'success' }} + # Create and publish the release + - name: Create and publish release uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const release_id = context.payload.release.id; - await github.rest.repos.updateRelease({ + const tagName = context.payload.inputs.tag; + const releaseName = context.payload.inputs.release_name; + await github.rest.repos.createRelease({ owner: context.repo.owner, repo: context.repo.repo, - release_id: release_id, + tag_name: tagName, + name: releaseName, draft: false });