Build and Release #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: Build and Release | |
on: | |
push: | |
branches: | |
- '*' | |
tags: | |
- '*' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
JVM_OPTS: -Xmx3200m | |
TERM: dumb | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'adopt' | |
java-version: '17' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Cache Gradle and Maven dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.m2 | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle/wrapper/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Download dependencies | |
run: ./gradlew dependencies | |
- name: Run tests | |
run: ./gradlew test | |
- name: Clean build environment | |
run: ./gradlew clean | |
- name: Build JAR | |
run: ./gradlew jar | |
- name: Archive artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: JAR Artifact(s) | |
path: build/libs/*.jar | |
- name: Extract release notes from CHANGELOG.md | |
if: startsWith(github.ref, 'refs/tags/') | |
id: extract_release_notes | |
uses: actions/github-script@v7 | |
with: | |
result-encoding: string | |
script: | | |
const fs = require('fs'); | |
const tag = context.ref.replace('refs/tags/', ''); | |
const tagPattern = '^##\\s*' + tag.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '\\s*'; | |
const versionPattern = new RegExp(tagPattern); | |
const changelog = fs.readFileSync('CHANGELOG.md', 'utf8'); | |
const lines = changelog.split('\n'); | |
let inSection = false; | |
let releaseTitle = ''; | |
let releaseBodyLines = []; | |
for (let i = 0; i < lines.length; i++) { | |
const line = lines[i]; | |
if (versionPattern.test(line)) { | |
releaseTitle = line.replace(/^##\s+/, '').trim(); | |
inSection = true; | |
continue; | |
} | |
if (inSection) { | |
if (/^##\s+/.test(line)) { | |
break; | |
} else { | |
releaseBodyLines.push(line); | |
} | |
} | |
} | |
const releaseBody = releaseBodyLines.join('\n').trim(); | |
core.setOutput('release_title', releaseTitle); | |
core.setOutput('release_body', releaseBody); | |
- name: Upload release asset | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: build/libs/*.jar | |
body: ${{ steps.extract_release_notes.outputs.release_body }} | |
name: ${{ steps.extract_release_notes.outputs.release_title }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |