fixed release workflow #8
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create Release 🎉 | |
on: | |
push: | |
tags: | |
- 'v*' # Trigger on version tag pushes (e.g., v1.0, v2.0) | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository | |
- name: 🛎️ Checkout code | |
uses: actions/checkout@v4 | |
# Step 2: Set up JDK (using Zulu) | |
- name: ☕ Set up Zulu JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'zulu' | |
# Step 3: Build the project and create shadowJar | |
- name: 🚧 Build with Gradle | |
run: ./gradlew shadowJar --no-daemon | |
# Step 4: Get the JAR file name | |
- name: Get JAR file name | |
id: jar-name | |
run: | | |
JAR_FILE=$(ls build/libs/*.jar) | |
echo "jar_file=$JAR_FILE" >> $GITHUB_ENV | |
# Step 5: Create a new release | |
- name: 📦 Create Release | |
id: create_release | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const { promises: fs } = require('fs'); | |
// Get the latest tag | |
const tag = context.ref.replace('refs/tags/', ''); | |
// Read the release notes if available | |
const releaseNotes = await fs.readFile('CHANGELOG.md', 'utf-8').catch(() => 'No release notes.'); | |
// Create the release | |
const release = await github.rest.repos.createRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: tag, | |
name: tag, | |
body: releaseNotes, | |
draft: false, | |
prerelease: false, | |
}); | |
core.setOutput('release_id', release.data.id); | |
# Step 6: Install `ghr` (GitHub release tool) | |
- name: Install ghr | |
run: | | |
sudo apt-get update && sudo apt-get install -y ghr | |
# Step 7: Upload the JAR file to the release | |
- name: Upload JAR to Release | |
run: | | |
ghr -u "${GITHUB_REPOSITORY%/*}" \ | |
-r "${GITHUB_REPOSITORY#*/}" \ | |
"${GITHUB_REF#refs/tags/}" \ | |
"${{ env.jar_file }}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |