Skip to content

Commit

Permalink
Update release.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykCholewa authored Nov 14, 2024
1 parent a5fa962 commit 27ddb4b
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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: |
Expand Down Expand Up @@ -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
});

0 comments on commit 27ddb4b

Please sign in to comment.