Skip to content

Build and Release

Build and Release #4

name: Build and Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: "Release version (e.g., v1.0.0)"
required: true
default: "v1.0.0"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 22
uses: actions/setup-java@v4
with:
java-version: "22"
distribution: "temurin"
- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn clean package
- name: Get version from pom.xml
id: get_version
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "jar_name=lukittu-simple-$VERSION.jar" >> $GITHUB_OUTPUT
- name: Create Release and Upload JAR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG_NAME="${{ github.event.inputs.version || github.ref_name }}"
RELEASE_NAME="Release $TAG_NAME"
JAR_PATH="target/${{ steps.get_version.outputs.jar_name }}"
# Create release with JAR file
gh release create "$TAG_NAME" "$JAR_PATH" \
--title "$RELEASE_NAME" \
--notes "## Changes
- Built from commit ${{ github.sha }}
## Download
Download the JAR file from the assets below."
- name: Upload JAR as Artifact
uses: actions/upload-artifact@v4
with:
name: lukittu-simple-jar
path: target/${{ steps.get_version.outputs.jar_name }}