Skip to content

Commit

Permalink
closes pepijnve#12 build native images
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Apr 23, 2023
1 parent cdff0ee commit 4d1bcfc
Show file tree
Hide file tree
Showing 2 changed files with 240 additions and 0 deletions.
173 changes: 173 additions & 0 deletions .github/workflows/native-image-on-demand.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
name: Native Images On-Demand

run-name: Native Images ${{ inputs.tag }} by @${{ github.actor }}

on:
workflow_dispatch:
inputs:
tag:
required: true

defaults:
run:
shell: bash

jobs:
build_artifacts:
outputs:
release_version: ${{ steps.version.outputs.release_version }}
runs-on: ubuntu-latest
steps:
- name: Set release version
id: version
env:
REF: ${{ github.event.inputs.tag }}
run: |
echo "release_version=${REF#v}" >> $GITHUB_ENV
echo "release_version=${REF#v}" >> $GITHUB_OUTPUT
- name: Checkout the repository
uses: actions/checkout@v3
with:
ref: "refs/tags/${{ github.event.inputs.tag }}"

- name: Set up java
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
cache: gradle

- name: Set version from tag
env:
RELEASE_VERSION: ${{ env.release_version }}
run: sed -i "s/version = .*/version = $RELEASE_VERSION/" gradle.properties

- name: Build artifacts
run: |
gradle -q clean build \
pdfJar \
-x test
- name: Cache libs
uses: actions/cache/save@v3
with:
path: |
build/libs
key: "libs-${{ github.run_id }}"
enableCrossOsArchive: true

native_images:
needs: build_artifacts
uses: ./.github/workflows/native-image.yml
with:
release-version: ${{ needs.build_artifacts.outputs.release_version }}

native_arm_image:
needs: build_artifacts
runs-on: [ self-hosted, ARM64 ]
steps:
- uses: graalvm/setup-graalvm@v1
with:
version: '22.3.1'
java-version: '17'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}

- run: |
rm -rf ./build/libs
- uses: actions/cache/restore@v3
with:
path: |
build/libs
key: "libs-${{ github.run_id }}"
fail-on-cache-miss: true
enableCrossOsArchive: true

- name: Generate GraalVM configuration
run: |
mkdir native-image-config-dir
printf '+--+--------+
| | |
| | |
| | /---+
| | | |
| | | |
+--+----+---/' | java -agentlib:native-image-agent=config-output-dir=native-image-config-dir -jar "./build/libs/ditaamini-$RELEASE_VERSION.jar" --svg -
printf '+--+--------+
| | |
| | |
| | /---+
| | | |
| | | |
+--+----+---/' | java -agentlib:native-image-agent=config-output-dir=native-image-config-dir -jar "./build/libs/ditaamini-$RELEASE_VERSION.jar" -
env:
RELEASE_VERSION: ${{ needs.build_artifacts.outputs.release_version }}

- name: Generate native image
run: |
native-image -H:ConfigurationFileDirectories=native-image-config-dir --no-fallback --report-unsupported-elements-at-runtime -jar "build/libs/ditaamini-$RELEASE_VERSION.jar" -H:Path="build/libs" -H:Name="ditaamini-linux-arm64-$RELEASE_VERSION"
env:
RELEASE_VERSION: ${{ needs.build_artifacts.outputs.release_version }}

- name: Cache native image
uses: actions/cache/save@v3
with:
path: "build/libs/ditaamini-linux-arm64-*"
key: "native-image-linux-arm64-${{ github.run_id }}"
enableCrossOsArchive: true

upload:
needs: [ build_artifacts, native_images, native_arm_image ]
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3

- name: Restore Libs cache
uses: actions/cache/restore@v3
with:
path: |
build/libs
key: "libs-${{ github.run_id }}"
fail-on-cache-miss: true
enableCrossOsArchive: true

- name: Restore Native-image-darwin-amd64 cache
uses: actions/cache/restore@v3
with:
path: "build/libs/ditaamini-darwin-amd64-*"
key: "native-image-darwin-amd64-${{ github.run_id }}"
fail-on-cache-miss: true
enableCrossOsArchive: true

- name: Restore Native-image-win-amd64 cache
uses: actions/cache/restore@v3
with:
path: "build/libs/ditaamini-win-amd64-*"
key: "native-image-win-amd64-${{ github.run_id }}"
fail-on-cache-miss: true
enableCrossOsArchive: true

- name: Restore Native-image-linux-amd64 cache
uses: actions/cache/restore@v3
with:
path: "build/libs/ditaamini-linux-amd64-*"
key: "native-image-linux-amd64-${{ github.run_id }}"
fail-on-cache-miss: true
enableCrossOsArchive: true

- name: Restore Native-image-linux-arm64 cache
uses: actions/cache/restore@v3
with:
path: "build/libs/ditaamini-linux-arm64-*"
key: "native-image-linux-arm64-${{ github.run_id }}"
fail-on-cache-miss: true
enableCrossOsArchive: true

- name: Create release
run: |
gh release upload "v$RELEASE_VERSION" ./build/libs/ditaamini-darwin-* ./build/libs/ditaamini-linux-* ./build/libs/ditaamini-win-* --clobber
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_VERSION: ${{ needs.build_artifacts.outputs.release_version }}
67 changes: 67 additions & 0 deletions .github/workflows/native-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Native Image

on:
workflow_call:
inputs:
release-version:
required: true
type: string

jobs:
build_non_win_images:
name: 'Build Native Image ${{ matrix.platform }}'
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
include:
- os: 'ubuntu-latest'
platform: 'linux-amd64'
- os: 'macos-latest'
platform: 'darwin-amd64'
- os: 'windows-latest'
platform: 'win-amd64'
runs-on: ${{matrix.os}}
steps:
- uses: graalvm/setup-graalvm@v1
with:
version: '22.3.1'
java-version: '17'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/cache/restore@v3
with:
path: |
build/libs
key: "libs-${{ github.run_id }}"
fail-on-cache-miss: true
enableCrossOsArchive: true

- name: Generate GraalVM configuration
run: |
mkdir native-image-config-dir
printf '+--+--------+
| | |
| | |
| | /---+
| | | |
| | | |
+--+----+---/' | java -agentlib:native-image-agent=config-output-dir=native-image-config-dir -jar "./build/libs/ditaamini-${{ inputs.release-version }}.jar" --svg -
printf '+--+--------+
| | |
| | |
| | /---+
| | | |
| | | |
+--+----+---/' | java -agentlib:native-image-agent=config-output-dir=native-image-config-dir -jar "./build/libs/ditaamini-${{ inputs.release-version }}.jar" -
- name: Generate native image
run: |
native-image -H:ConfigurationFileDirectories=native-image-config-dir --no-fallback --report-unsupported-elements-at-runtime -jar "build/libs/ditaamini-${{ inputs.release-version }}.jar" -H:Path="build/libs" -H:Name="ditaamini-${{ matrix.platform }}-${{ inputs.release-version }}"
- name: Cache native image
uses: actions/cache/save@v3
with:
path: "build/libs/ditaamini-${{ matrix.platform }}-*"
key: "native-image-${{ matrix.platform }}-${{ github.run_id }}"
enableCrossOsArchive: true

0 comments on commit 4d1bcfc

Please sign in to comment.