Skip to content

Native Image Release #22

Native Image Release

Native Image Release #22

Workflow file for this run

name: Native Image Release
on: workflow_dispatch # Manually trigger the workflow
jobs:
build-and-upload:
strategy:
matrix:
include:
- os: ubuntu-latest
arch: "linux-amd64"
- os: windows-latest
arch: "windows-amd64"
runs-on: ${{ matrix.os }}
timeout-minutes: 20
outputs:
ubuntu: ${{ steps.set-output.outputs.ubuntu }}
steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
java-version: "21"
distribution: "graalvm-community"
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: "maven"
native-image-job-reports: "true"
- name: Build native image on Linux
if: matrix.os == 'ubuntu-latest'
run: |
echo "GRAALVM_HOME: $GRAALVM_HOME"
echo "JAVA_HOME: $JAVA_HOME"
java --version
native-image --version
mvn package -Pnative -DskipTests -Dnative.march="-march=x86-64";
- name: Build native image on Windows
if: matrix.os == 'windows-latest'
run: |
echo "GRAALVM_HOME: %GRAALVM_HOME%"
echo "JAVA_HOME: %JAVA_HOME%"
java --version
native-image.cmd --version
mvn package -Pnative -DskipTests "-Dnative.march=-march=x86-64";
- name: Set Output for Ubuntu
if: matrix.arch == 'linux-amd64'
id: set-output
run: echo "ubuntu=true" >> $GITHUB_OUTPUT
# Upload the binary artifact for linux-amd64 only
- name: Upload Binary Artifact
if: matrix.arch == 'linux-amd64'
uses: actions/upload-artifact@v4
with:
name: restheart
path: core/target/
- name: Upload Binary to Release
uses: actions/github-script@v7
with:
script: |
const fs = require('fs').promises;
const isWindows = '${{ matrix.os }}' === 'windows-latest';
const filePath = isWindows ? 'core/target/restheart.exe' : 'core/target/restheart';
const fileName = `restheart-${{ matrix.arch }}${isWindows ? '.exe' : ''}`;
const releaseTag = '8.1.0'; // Consider making this an input parameter
try {
const content = await fs.readFile(filePath);
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
const release = releases.find(r => r.tag_name === releaseTag);
if (!release) {
throw new Error(`Release with tag '${releaseTag}' not found.`);
}
// Check if an asset with the same name exists in the release
const existingAsset = release.assets.find(asset => asset.name === fileName);
if (existingAsset) {
console.log(`Asset ${fileName} already exists. Deleting it...`);
// Delete the existing asset
await github.rest.repos.deleteReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: existingAsset.id
});
console.log(`Deleted asset ${fileName}`);
}
console.log(`Uploading ${fileName} to release ${releaseTag}...`);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
name: fileName,
data: content,
headers: {
'content-type': 'application/octet-stream'
}
});
console.log(`Successfully uploaded ${fileName} to release ${releaseTag}`);
} catch (error) {
console.error('Error occurred:', error.message);
process.exit(1);
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker-publish:
runs-on: ubuntu-latest
needs: build-and-upload
if: needs.build-and-upload.outputs.ubuntu == 'true'
steps:
- uses: actions/checkout@v4
- name: Download Linux Binary Artifact
uses: actions/download-artifact@v4
with:
name: restheart
path: core/target/
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set VERSION
id: vars
run: |
echo "VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV
- name: Build and Push multi-arch native Docker images
uses: docker/build-push-action@v6
with:
context: ./core/
file: ./core/Dockerfile.native
platforms: linux/amd64
push: true # push all images built
pull: true # pull all required images before building
tags: |
softinstigate/restheart-native:latest,
softinstigate/restheart-native:8,
softinstigate/restheart-native:8.1,
softinstigate/restheart-native:8.1.0