ci: Dynamically set version from pom (#161) #29
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 Installers | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push or pull request events but only for the "master" branch | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
jobs: | |
# SonarCloud Analysis | |
analyze: | |
runs-on: ubuntu-latest | |
permissions: write-all | |
steps: | |
- uses: actions/checkout@v4 | |
- id: setup-jdk | |
name: Setup JDK | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: 'temurin' | |
settings-path: ${{ github.workspace }} | |
- uses: s4u/maven-settings-action@v2.5.0 | |
with: | |
servers: '[{"id": "github","configuration": {"httpHeaders": {"property": {"name": "Authorization","value": "Bearer ${{ secrets.GITHUB_TOKEN }}"}}}}]' | |
- name: Cache SonarCloud Packages | |
uses: actions/cache@v1 | |
with: | |
path: ~/.sonar/cache | |
key: ${{ runner.os }}-sonar | |
restore-keys: ${{ runner.os }}-sonar | |
- name: Analyze | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: mvn -B clean install -Dmaven.test.skip=true -pl !WoPeD-Installer org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=woped_WoPeD | |
# Linux Installer | |
build-linux-installer: | |
name: Build Installer on Linux | |
runs-on: ubuntu-latest | |
needs: [analyze] | |
permissions: write-all | |
steps: | |
# Setup build environment | |
- id: checkout-code | |
name: Checkout | |
uses: actions/checkout@v4 | |
- id: setup-jdk | |
name: Setup JDK | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: 'temurin' | |
settings-path: ${{ github.workspace }} | |
- uses: s4u/maven-settings-action@v2.5.0 | |
with: | |
servers: '[{"id": "github","configuration": {"httpHeaders": {"property": {"name": "Authorization","value": "Bearer ${{ secrets.GITHUB_TOKEN }}"}}}}]' | |
# Build for linux | |
- name: Set Release version env variable | |
run: | | |
echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV | |
- id: build | |
name: Build for linux | |
run: | | |
mvn -U -pl !WoPeD-Installer clean install -Dmaven.test.skip=true --no-transfer-progress | |
jpackage --input /home/runner/work/WoPeD/WoPeD --name WoPeD --main-jar /home/runner/work/WoPeD/WoPeD/WoPeD-Starter/target/WoPeD-Starter-$RELEASE_VERSION.jar --main-class org.woped.starter.RunWoPeD --dest ./woped-installer/build/distributions | |
ls ./woped-installer/build/distributions | |
# Upload installer | |
- id: upload-installer | |
name: Upload installer | |
uses: actions/upload-artifact@v2 | |
with: | |
path: ./woped-installer/build/distributions/WoPeD.deb | |
name: linux-installer | |
retention-days: 1 | |
# Windows Installer | |
build-windows-installer: | |
name: Build Installer on Windows | |
runs-on: windows-latest | |
needs: [analyze] | |
steps: | |
# Setup build environment | |
- id: checkout-code | |
name: Checkout | |
uses: actions/checkout@v4 | |
- id: setup-jdk | |
name: Setup JDK | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: 'temurin' | |
settings-path: ${{ github.workspace }} | |
- uses: s4u/maven-settings-action@v2.5.0 | |
with: | |
servers: '[{"id": "github","configuration": {"httpHeaders": {"property": {"name": "Authorization","value": "Bearer ${{ secrets.GITHUB_TOKEN }}"}}}}]' | |
# Build for Windows | |
- name: Set Release version env variable | |
run: | | |
echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression="project.version" -q -DforceStdout)" >> $env:GITHUB_ENV | |
- id: build | |
name: Build for Windows | |
run: | | |
mvn -U -pl !WoPeD-Installer clean install '-Dmaven.test.skip=true' '--no-transfer-progress' | |
jpackage --input C:\Users\runneradmin\.m2\repository\de\dhbw\woped --name WoPeD --main-jar C:\Users\runneradmin\.m2\repository\de\dhbw\woped\WoPeD-Starter\$env:RELEASE_VERSION\WoPeD-Starter-$env:RELEASE_VERSION.jar --main-class org.woped.starter.RunWoPeD --dest C:\ --type msi | |
dir C:\ | |
# Upload installer | |
- id: upload-installer | |
name: Upload installer | |
uses: actions/upload-artifact@v2 | |
with: | |
path: C:\WoPeD.msi | |
name: windows-installer | |
retention-days: 1 | |
# MacOS Installer | |
build-macos-installer: | |
name: Build Installer on macOS | |
runs-on: macos-latest | |
needs: [analyze] | |
steps: | |
# Setup build environment | |
- id: checkout-code | |
name: Checkout | |
uses: actions/checkout@v4 | |
- id: setup-jdk | |
name: Setup JDK | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: 'temurin' | |
settings-path: ${{ github.workspace }} | |
- uses: s4u/maven-settings-action@v2.5.0 | |
with: | |
servers: '[{"id": "github","configuration": {"httpHeaders": {"property": {"name": "Authorization","value": "Bearer ${{ secrets.GITHUB_TOKEN }}"}}}}]' | |
# Build for MacOS | |
- name: Set Release version env variable | |
run: | | |
echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV | |
- id: build | |
name: Build for MacOS | |
run: | | |
mvn -U -pl !WoPeD-Installer clean install -Dmaven.test.skip=true --no-transfer-progress | |
jpackage --input /Users/runner/.m2/repository/de/dhbw/woped/ --name WoPeD --main-jar /Users/runner/.m2/repository/de/dhbw/woped/WoPeD-Starter/$RELEASE_VERSION/WoPeD-Starter-$RELEASE_VERSION.jar --main-class org.woped.starter.RunWoPeD --dest /Users/runner/.m2/ --type dmg | |
# Upload Installer | |
- id: upload-installer | |
name: Upload installer | |
uses: actions/upload-artifact@v2 | |
with: | |
path: /Users/runner/.m2/WoPeD.dmg | |
name: macos-installer | |
retention-days: 1 | |
create-release: | |
name: Create Release | |
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' | |
runs-on: ubuntu-latest | |
needs: [build-linux-installer, build-windows-installer, build-macos-installer] | |
steps: | |
- uses: actions/checkout@v4 | |
# Download installers | |
- id: download-linux-installer | |
name: Download Linux installer | |
uses: actions/download-artifact@v2 | |
with: | |
name: linux-installer | |
- id: download-windows-installer | |
name: Download Windows installer | |
uses: actions/download-artifact@v2 | |
with: | |
name: windows-installer | |
- id: download-macos-installer | |
name: Download macOS installer | |
uses: actions/download-artifact@v2 | |
with: | |
name: macos-installer | |
# Prepare version | |
- name: Set Release version env variable | |
run: | | |
echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV | |
- name: Add SHORT_SHA env property with commit short sha | |
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV | |
- name: If Version does contain SNAPSHOT add SHORT_SHA | |
if: contains(env.RELEASE_VERSION, 'SNAPSHOT') | |
run: echo "RELEASE_NAME=${{ env.RELEASE_VERSION }}-${{ env.SHORT_SHA }}" >> $GITHUB_ENV | |
- name: If Version does not contain SNAPSHOT add nothing | |
if: false == contains(env.RELEASE_VERSION, 'SNAPSHOT') | |
run: echo "RELEASE_NAME=${{ env.RELEASE_VERSION }}" >> $GITHUB_ENV | |
# Create GitHub Release and assets | |
- id: create-release | |
name: Create GitHub release | |
uses: actions/create-release@latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.RELEASE_NAME }} | |
release_name: ${{ env.RELEASE_NAME }} | |
draft: false | |
prerelease: false | |
- id: release-linux-installer | |
name: Release Linux installer | |
uses: actions/upload-release-asset@latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create-release.outputs.upload_url }} | |
asset_path: WoPeD.deb | |
asset_name: WoPeD.deb | |
asset_content_type: application/x-binary | |
- id: release-windows-installer | |
name: Release Windows installer | |
uses: actions/upload-release-asset@latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create-release.outputs.upload_url }} | |
asset_path: WoPeD.msi | |
asset_name: WoPeD.msi | |
asset_content_type: application/x-binary | |
- id: release-macos-installer | |
name: Release macOS installer | |
uses: actions/upload-release-asset@latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create-release.outputs.upload_url }} | |
asset_path: WoPeD.dmg | |
asset_name: WoPeD.dmg | |
asset_content_type: application/x-binary |