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 e971058
Showing 1 changed file with 37 additions and 38 deletions.
75 changes: 37 additions & 38 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ 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
- os: macos-latest
target: aarch64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
shell: pwsh
ext: dylib
steps:
- uses: actions/checkout@v2

Expand All @@ -32,51 +35,47 @@ 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
artifact_name="partitioner-${{ matrix.target }}.${{ matrix.ext }}"
mv "./target/${{ matrix.target }}/release/libpartitioner.${{ matrix.ext }}" "./target/${{ matrix.target }}/release/$artifact_name"
echo "ARTIFACT_NAME=$artifact_name" >> $GITHUB_ENV
- 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
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.ARTIFACT_NAME }}
path: ./target/${{ matrix.target }}/release/${{ env.ARTIFACT_NAME }}

prepare_release:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
if: github.run_number == 1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
draft: false
prerelease: false

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download all artifacts
uses: actions/download-artifact@v2
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' }}
path: artifacts/

- name: Upload Release Assets
run: |
cd artifacts
for artifact in *; do
echo "Uploading $artifact"
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-F "name=$(basename "$artifact")" \
-F "file=@$artifact" \
"${{ steps.create_release.outputs.upload_url }}"
done

0 comments on commit e971058

Please sign in to comment.