Skip to content

Instantly share code, notes, and snippets.

@GeePawHill
Created November 6, 2023 18:14
Show Gist options
  • Save GeePawHill/a710f647b22df17fb6be30ff2aad9bbb to your computer and use it in GitHub Desktop.
Save GeePawHill/a710f647b22df17fb6be30ff2aad9bbb to your computer and use it in GitHub Desktop.
Actual action file for release-on-push arrangement.
name: Alternate Java CLI Tool - All
on: [ push, pull_request ]
jobs:
build-jar-job:
name: 'Build Java CLI on ${{ matrix.os }}'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
steps:
- name: 'Checkout'
uses: actions/checkout@v4
- name: 'GraalVM Setup'
uses: graalvm/setup-graalvm@v1
with:
java-version: '17'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'
- name: 'Build Native Binary - ${{ matrix.os }}'
run: |
./gradlew -PBUILD=${{github.run_number}} nativeCompile
- name: 'save version id'
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v3
with:
name: nitpick-version-only.txt
path: ${{ github.workspace }}/cli/build/generated/version/nitpick-version-only.txt
- name: 'Upload binary- ${{ matrix.os }}'
uses: actions/upload-artifact@v3
with:
name: nitpick-${{ matrix.os }}
path: ${{ github.workspace }}/cli/build/native/nativeCompile/nitpick*
#only run for versioned tag
release-job:
name: 'Release ${{ github.ref_name }}'
needs: build-jar-job
runs-on: ubuntu-latest
steps:
- name: Download macOS Binary
uses: actions/download-artifact@v3
with:
name: nitpick-macos-latest
path: ${{ github.workspace }}/macos
- name: Zip macOS binary
run: zip -j nitpick-macos.zip ${{ github.workspace }}/macos/* -r
- name: Download Linux Binary
uses: actions/download-artifact@v3
with:
name: nitpick-ubuntu-latest
path: ${{ github.workspace }}/linux
- name: Zip Linux binary
run: zip -j nitpick-linux.zip ${{ github.workspace }}/linux/* -r
- name: Download Windoze Binary
uses: actions/download-artifact@v3
with:
name: nitpick-windows-latest
path: ${{ github.workspace }}/windows
- name: Zip Windoze binary
run: zip -j nitpick-windows.zip ${{ github.workspace }}/windows/* -r
- name: Download Version
uses: actions/download-artifact@v3
with:
name: nitpick-version-only.txt
path: ${{ github.workspace }}
- name: Assign Version Variable
shell: bash
run: |
LOCAL_VERSION=`head -n 1 nitpick-version-only.txt`
echo "VERSION_TAG=$LOCAL_VERSION" >> $GITHUB_ENV
echo "Version = ${{ env.VERSION_TAG }}"
- name: Release
uses: "marvinpinto/action-automatic-releases@latest"
with:
prerelease: false
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: ${{env.VERSION_TAG}}
title: "Release Build ${{env.VERSION_TAG}}"
files: |
*.zip
fun makeBuildString(properties: Properties): String {
val build = project.properties["BUILD"]
if (build == null) return "0-DEV"
val numeric_build = Integer.valueOf(build.toString())
val numeric_minor_offset = Integer.valueOf(properties["minor_offset"].toString())
val trueBuild = numeric_build - numeric_minor_offset
return "$trueBuild-RELEASE"
}
tasks.register("generateVersionString") {
doLast {
val properties = Properties().apply {
load(rootProject.file("build.properties").reader())
}
val major = properties["major"].toString()
val minor = properties["minor"].toString()
var trueBuild = makeBuildString(properties)
val version = "v$major.$minor.$trueBuild"
println(version)
val versionFolder = layout.buildDirectory.file("generated/version/")
println(versionFolder.get().asFile.toPath().toAbsolutePath())
versionFolder.get().asFile.mkdirs()
val destination = layout.buildDirectory.file("generated/version/nitpick.properties").get().asFile
val destinationStream = Files.newOutputStream(destination.toPath(), CREATE, TRUNCATE_EXISTING, WRITE)
val destinationWriter = PrintWriter(destinationStream)
destinationWriter.println("version=$version")
destinationWriter.flush()
destinationWriter.close()
val straight = layout.buildDirectory.file("generated/version/nitpick-version-only.txt").get().asFile
val straightStream = Files.newOutputStream(straight.toPath(), CREATE, TRUNCATE_EXISTING, WRITE)
val straightWriter = PrintWriter(straightStream)
straightWriter.println("$version")
straightWriter.flush()
straightWriter.close()
}
}
tasks.named("compileJava").configure {
dependsOn("generateVersionString")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment