Test Version 3 (actions fix) #75
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: Java CI with Maven and Release | |
on: | |
push: | |
branches: [ "dev-master" ] | |
pull_request: | |
branches: [ "dev-master" ] | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest] | |
java: [21] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up JDK ${{ matrix.java }} | |
uses: actions/setup-java@v4 | |
with: | |
java-version: ${{ matrix.java }} | |
distribution: 'temurin' | |
cache: maven | |
- name: Get version from pom.xml | |
run: | | |
echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=revision -q -DforceStdout)" >> $GITHUB_ENV | |
shell: bash | |
- name: Build with Maven | |
run: mvn clean install -B -V | |
- name: Display Java version | |
run: java -version | |
- name: Display Maven version | |
run: mvn --version | |
- name: Calculate SHA-256 checksum | |
run: | | |
if [ "$RUNNER_OS" == "Linux" ]; then | |
sha256sum target/NovelAI-Studio-FX-${{ env.PROJECT_VERSION }}.jar > target/NovelAI-Studio-FX-${{ env.PROJECT_VERSION }}.jar.sha256 | |
elif [ "$RUNNER_OS" == "Windows" ]; then | |
$hash = (Get-FileHash -Path target\NovelAI-Studio-FX-${{ env.PROJECT_VERSION }}.jar -Algorithm SHA256).Hash.ToLower() | |
$hash + " *NovelAI-Studio-FX-${{ env.PROJECT_VERSION }}.jar" | Out-File -Encoding ASCII target\NovelAI-Studio-FX-${{ env.PROJECT_VERSION }}.jar.sha256 | |
else | |
echo "Unsupported operating system" | |
exit 1 | |
fi | |
shell: bash | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: NovelAI-Studio-FX-${{ matrix.os }}-${{ env.PROJECT_VERSION }} | |
path: | | |
target/NovelAI-Studio-FX-*.jar | |
target/NovelAI-Studio-FX-*.jar.sha256 | |
- name: Run tests | |
run: mvn test | |
- name: Upload test results | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-results-${{ matrix.os }}-${{ matrix.java }}-${{ env.PROJECT_VERSION }} | |
path: target/surefire-reports | |
- name: Upload Maven logs | |
if: failure() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: maven-logs-${{ matrix.os }}-${{ matrix.java }}-${{ env.PROJECT_VERSION }} | |
path: ~/.m2/repository/.m2.log | |
- name: Create Release | |
if: success() && matrix.os == 'ubuntu-latest' | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ env.PROJECT_VERSION }} | |
release_name: Release ${{ env.PROJECT_VERSION }} | |
draft: false | |
prerelease: false | |
- name: Upload Release Asset (JAR) | |
if: success() && matrix.os == 'ubuntu-latest' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./target/NovelAI-Studio-FX-${{ env.PROJECT_VERSION }}.jar | |
asset_name: NovelAI-Studio-FX-${{ env.PROJECT_VERSION }}.jar | |
asset_content_type: application/java-archive | |
- name: Upload Release Asset (SHA-256) | |
if: success() && matrix.os == 'ubuntu-latest' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./target/NovelAI-Studio-FX-${{ env.PROJECT_VERSION }}.jar.sha256 | |
asset_name: NovelAI-Studio-FX-${{ env.PROJECT_VERSION }}.jar.sha256 | |
asset_content_type: text/plain |