Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4] Refactor workflow #8

Merged
merged 8 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 41 additions & 211 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name: Build and Release an SDK Generator
name: Build and Test

on:
workflow_dispatch:
workflow_call:
push:
branches:
- main

env:
FILE_NAME: aidbox-sdk
branches: [main]
pull_request:
branches: [main]

jobs:
build-jar:
name: Build jar
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

Expand All @@ -20,241 +22,69 @@ jobs:
distribution: temurin
java-version: 11

- name: Setup Clojure tools
- name: Setup Clojure
uses: DeLaGuardo/[email protected]
with:
cli: latest

- name: Cache clojure dependencies
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.gitlibs
~/.deps.clj
# List all files containing dependencies:
key: cljdeps-${{ hashFiles('deps.edn') }}
path: ~/.m2/repository
key: cljdeps-${{ hashFiles('**/deps.edn') }}
restore-keys: cljdeps-

- name: Build uberjar
run: |
clojure -T:build uberjar :jar-name ${{ env.FILE_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Run tests
run: clojure -M:test -m kaocha.runner

- name: Move jar into release directory
run: |
mkdir -p release
mv target/${{ env.FILE_NAME }}.jar release/${{ env.FILE_NAME }}.jar
- name: Build uberjar
run: clojure -T:build uberjar :jar-name aidbox-sdk

- name: Upload jar artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.FILE_NAME }}.jar
path: release/${{ env.FILE_NAME }}.jar

build-amd64:
runs-on: ubuntu-latest
needs: build-jar
steps:
- name: Download jar artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.FILE_NAME }}.jar
path: release/

- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
github-token: ${{ secrets.GH_TOKEN }}
native-image-job-reports: 'true'
name: build-jar
path: target/aidbox-sdk.jar

- name: Compile to native binary
run: |
native-image -jar release/${{ env.FILE_NAME }}.jar --no-fallback --no-server ${{ env.FILE_NAME }}
mv ${{ env.FILE_NAME }} release/${{ env.FILE_NAME }}
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- #

- name: Upload amd64 binary artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.FILE_NAME }}-amd64
path: release/${{ env.FILE_NAME }}

build-arm64:
runs-on: macos-latest
build-native:
name: Build for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: build-jar
steps:
- name: Download jar artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.FILE_NAME }}.jar
path: release/

- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
github-token: ${{ secrets.GH_TOKEN }}
native-image-job-reports: 'true'
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest

- name: Compile to native binary
run: |
native-image -jar release/${{ env.FILE_NAME }}.jar --no-fallback --no-server ${{ env.FILE_NAME }}
mv ${{ env.FILE_NAME }} release/${{ env.FILE_NAME }}-arm64

- name: Upload arm64 binary artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.FILE_NAME }}-arm64
path: release/${{ env.FILE_NAME }}-arm64

build-windows:
runs-on: windows-latest
needs: build-jar
steps:
- uses: actions/checkout@v4

- name: Download jar artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.FILE_NAME }}.jar
path: release/
name: build-jar
path: ./

- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
github-token: ${{ secrets.GH_TOKEN }}
native-image-job-reports: 'true'
java-version: "21"
distribution: "graalvm"
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: "true"

- name: Compile to native binary
run: |
native-image -jar release/${{ env.FILE_NAME }}.jar --no-fallback --no-server ${{ env.FILE_NAME }}
mv ${{ env.FILE_NAME }}.exe release/${{ env.FILE_NAME }}.exe
make compile_native_image project_dir=${{ github.workspace }} jar_path=aidbox-sdk.jar image_name=aidbox-sdk-${{ matrix.os }}
chmod +x aidbox-sdk-${{ matrix.os }}

- name: Upload arm64 binary artifact
- name: Upload amd64 binary artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.FILE_NAME }}.exe
path: release/${{ env.FILE_NAME }}.exe

create-release:
runs-on: ubuntu-latest
needs: [build-jar, build-amd64, build-arm64, build-windows]
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Download jar artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.FILE_NAME }}.jar
path: release/

- name: Download linux-amd64 artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.FILE_NAME }}-amd64
path: release/

- name: Download arm64 artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.FILE_NAME }}-arm64
path: release/

- name: Download windows artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.FILE_NAME }}.exe
path: release/

- name: Fetch all tags
run: git fetch --tags

- name: Determine next version
id: next_version
run: |
# Get the latest tag
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "Latest tag: $latest_tag"

if [ -z "$latest_tag" ]; then
next_version="v1"
else
# Parse the version number
IFS='.' read -r -a version_parts <<< "${latest_tag:1}"
major=${version_parts[0]}
minor=${version_parts[1]}
patch=${version_parts[2]}

# Increment the patch version
patch=$((patch + 1))

next_version="v$major.$minor.$patch"
fi

echo "Next version: $next_version"
echo "tag=$next_version" >> $GITHUB_OUTPUT

- name: Create a new tag
run: |
git tag ${{ steps.next_version.outputs.tag }}
git push origin ${{ steps.next_version.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Create Github Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: ${{ steps.next_version.outputs.tag }}
release_name: Release ${{ steps.next_version.outputs.tag }}
draft: false
prerelease: false

- name: Upload Release Asset (jar)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: release/${{ env.FILE_NAME }}.jar
asset_name: ${{ env.FILE_NAME }}.jar
asset_content_type: application/java-archive

- name: Upload Release Asset (amd64)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: release/${{ env.FILE_NAME }}
asset_name: ${{ env.FILE_NAME }}
asset_content_type: application/octet-stream

- name: Upload Release Asset (arm64)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: release/${{ env.FILE_NAME }}-arm64
asset_name: ${{ env.FILE_NAME }}-arm64
asset_content_type: application/octet-stream

- name: Upload Release Assets (Windows)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: release/${{ env.FILE_NAME }}.exe
asset_name: ${{ env.FILE_NAME }}.exe
asset_content_type: application/octet-stream
name: build-${{ matrix.os }}
path: ./aidbox-sdk-*
15 changes: 15 additions & 0 deletions .github/workflows/dependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Check dependencies
on:
push:
tags-ignore:
- "**"
# additionally run once per week (At 00:00 on Sunday) to maintain cache
schedule:
- cron: "0 0 * * 0"

jobs:
antq:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: liquidz/antq-action@main
13 changes: 13 additions & 0 deletions .github/workflows/git.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Git checks

on:
pull_request:

jobs:
block-fixup:
name: Block merge with fixup commits
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: 13rac1/[email protected]
39 changes: 39 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release an SDK Generator

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
release:
types: [published]

jobs:
build:
uses: ./.github/workflows/build.yaml
secrets: inherit

create-release:
name: Release new version
runs-on: ubuntu-latest
if: ${{ github.event_name == 'release' }}
needs: [build]
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: build-*
path: release/
merge-multiple: true

- name: Upload release assets
uses: AButler/[email protected]
with:
files: "release/*"
repo-token: ${{ secrets.GITHUB_TOKEN }}
release-id: ${{ github.event.release.id }}
18 changes: 11 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ pom.xml
pom.xml.asc
*.jar
*.class
/lib/
/classes/
/target/
/checkouts/
lib/
classes/
target/
out/
checkouts/
.lein-deps-sum
.lein-repl-history
.lein-plugins/
Expand All @@ -14,6 +15,9 @@ pom.xml.asc
.cpcache/
.DS_Store

/.lsp/
/.clj-kondo/
/.schemas/
.lsp/
.clj-kondo/
.schemas/

META/*
!META/.gitkeep
Empty file added META/.gitkeep
Empty file.
Loading