Build and Deploy JRE #3
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 Deploy JRE | |
on: | |
workflow_call: | |
inputs: | |
deploy: | |
type: boolean | |
description: Deploy JRE to Maven and Docker Repositories | |
required: true | |
default: false | |
workflow_dispatch: | |
inputs: | |
deploy: | |
type: boolean | |
description: Deploy JRE to Maven and Docker Repositories | |
required: true | |
default: false | |
env: | |
JDK_VERSION: 17.0.12+7 | |
jobs: | |
build-jre: | |
name: Build JRE | |
runs-on: ${{ matrix.os }} | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: ${{ env.JDK_VERSION }} | |
distribution: temurin | |
java-package: jdk | |
cache: maven | |
- name: Build Linux JRE | |
if: runner.os == 'Linux' | |
run: | | |
jlinkModules=$(cat modules.txt | tr '\n' ',') | |
jlink --strip-debug --no-header-files --no-man-pages --add-modules $jlinkModules --output jre-linux | |
echo "JRE_OS_NAME=linux">>${GITHUB_ENV} | |
cd jre-linux/ && zip -r ../metricshub-jre-linux.zip . | |
- name: Build Windows JRE | |
if: runner.os == 'Windows' | |
run: | | |
$jlinkModules=(Get-Content modules.txt) -join ',' | |
jlink --strip-debug --no-header-files --no-man-pages --add-modules $jlinkModules --output jre-windows | |
echo "JRE_OS_NAME=windows" >> $env:GITHUB_ENV | |
Compress-Archive -Path jre-windows\* -DestinationPath metricshub-jre-windows.zip | |
- name: Attach JRE Archive to the Build | |
uses: actions/upload-artifact@v4 | |
with: | |
name: metricshub-jre-${{ env.JDK_VERSION }}-${{ env.JRE_OS_NAME }} | |
path: metricshub-jre-${{ env.JRE_OS_NAME }}.zip | |
- name: Maven Deploy Archives | |
if: ${{ inputs.deploy }} | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
run: | | |
mvn deploy:deploy-file -Durl=https://maven.pkg.github.com/${{ env.GITHUB_REPOSITORY_OWNER }}/${{ env.GITHUB_REPOSITORY }} -Dfile=metricshub-jre-${{ env.JRE_OS_NAME }}.zip -DgroupId=org.sentrysoftware -DartifactId=metricshub-jre-${{ env.JRE_OS_NAME }} -Dversion=${{ env.JDK_VERSION }} -Dpackaging=jlink "-Ddescription=MetricsHub JRE for ${{ runner.os }}" | |
build-jre-docker: | |
name: Build JRE (docker) | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- | |
name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ vars.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
# Add support for more platforms with QEMU (optional) | |
# https://github.com/docker/setup-qemu-action | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v3 | |
- | |
# Docker Images Does Not Contains the plus (+) sign | |
# Must be replaced with underscore (_) | |
name: Prepare version number | |
run: echo "JDK_IMAGE_TAG=${{ env.JDK_VERSION }}" | sed 's/+/_/g' >> $GITHUB_ENV | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
build-args: | | |
JDK_VERSION=${{ env.JDK_IMAGE_TAG }} | |
platforms: linux/amd64,linux/arm64 | |
push: ${{ inputs.deploy }} | |
tags: | | |
${{ vars.DOCKERHUB_ORG }}/metricshub-jre:latest | |
${{ vars.DOCKERHUB_ORG }}/metricshub-jre:${{ env.JDK_IMAGE_TAG }} | |
ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest | |
ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${{ env.JDK_IMAGE_TAG }} |