Skip to content

Commit

Permalink
Added workflow to build releases
Browse files Browse the repository at this point in the history
  • Loading branch information
nuuskamummu committed Mar 25, 2024
1 parent 66b131c commit d255407
Showing 1 changed file with 18 additions and 51 deletions.
69 changes: 18 additions & 51 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ on:
tags:
- 'v*.*.*'

permissions:
contents: write
actions: read

jobs:
build_and_release:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
ext: so
file_name: partitioner-x86_64-unknown-linux-gnu.so
- os: macos-latest
target: aarch64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
shell: pwsh
ext: dylib
file_name: partitioner-aarch64-apple-darwin.dylib

steps:
- uses: actions/checkout@v2

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
Expand All @@ -32,51 +37,13 @@ jobs:
- name: Build Release
run: |
cargo build --release --target ${{ matrix.target }}
if [ "${{ runner.os }}" = "Linux" ]; then
echo "ARTIFACT_PATH=./target/${{ matrix.target }}/release/libpartitioner.so" >> $GITHUB_ENV
elif [ "${{ runner.os }}" = "macOS" ]; then
echo "ARTIFACT_PATH=./target/${{ matrix.target }}/release/libpartitioner.dylib" >> $GITHUB_ENV
else
echo "ARTIFACT_PATH=./target/${{ matrix.target }}/release/libpartitioner.dll" >> $GITHUB_ENV
fi
shell: bash

- name: Package Release Asset
run: |
if ($env:RUNNER_OS -eq "Windows") {
Compress-Archive -Path $env:ARTIFACT_PATH -DestinationPath "${env:ARTIFACT_PATH}.zip"
echo "ASSET_PATH=${env:ARTIFACT_PATH}.zip" >> $env:GITHUB_ENV
}
elseif ($env:RUNNER_OS -eq "macOS") {
tar czvf libpartitioner.dylib-${{ matrix.target }}-${{ github.ref }}.tar.gz -C $(dirname $env:ARTIFACT_PATH) $(basename $env:ARTIFACT_PATH)
echo "ASSET_PATH=libpartitioner-${{ matrix.target }}-${{ github.ref }}.tar.gz" >> $env:GITHUB_ENV
}
else {
tar czvf libpartitioner.so-${{ matrix.target }}-${{ github.ref }}.tar.gz -C $(dirname $env:ARTIFACT_PATH) $(basename $env:ARTIFACT_PATH)
echo "ASSET_PATH=libpartitioner-${{ matrix.target }}-${{ github.ref }}.tar.gz" >> $env:GITHUB_ENV
}
shell: pwsh
mv "./target/${{ matrix.target }}/release/libpartitioner.${{ matrix.ext }}" "./target/${{ matrix.target }}/release/${{ matrix.file_name }}"
echo "ARTIFACT_NAME=$artifact_name" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: actions/create-release@v1
if: github.run_number == 1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload files to a GitHub release
uses: svenstaro/[email protected]
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.ASSET_PATH }}
asset_name: ${{ env.ASSET_PATH }}
asset_content_type: application/${{ endsWith(env.ASSET_PATH, '.zip') && 'zip' || 'gzip' }}


repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/release/${{ matrix.file_name }}
asset_name: ${{ matrix.file_name }}
tag: ${{ github.ref }}

0 comments on commit d255407

Please sign in to comment.