Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
release: | |
types: [created] | |
permissions: | |
contents: write | |
jobs: | |
update-version: | |
runs-on: ubuntu-latest | |
outputs: | |
default-branch: ${{ steps.env.outputs.default-branch }} | |
remote: ${{ steps.env.outputs.remote }} | |
steps: | |
- name: ⬇️ Checkout | |
uses: actions/[email protected] | |
- name: ⚙️ Setup environment | |
id: env | |
run: | | |
export REMOTE=$(git remote show | cut -d' ' -f1) | |
export DEFAULT_BRANCH=$(git remote show $REMOTE | sed -n '/HEAD branch/s/.*: //p') | |
echo "remote=$REMOTE" >> $GITHUB_OUTPUT | |
echo "default-branch=$DEFAULT_BRANCH" >> $GITHUB_OUTPUT | |
echo "Branch $DEFAULT_BRANCH on remote $REMOTE" | |
- name: 📝 Update version from git tag | |
run: | | |
git config --global user.name 'GitHub Action' | |
git config --global user.email '[email protected]' | |
git fetch --tags | |
git checkout ${{ steps.env.outputs.default-branch }} | |
git pull ${{ steps.env.outputs.remote }} ${{ steps.env.outputs.default-branch }} | |
sed -i --regexp-extended --expression="s/^version = \"[0-9\.]+\"/version = \"${{ github.event.release.tag_name }}\"/g" Cargo.toml | |
git add Cargo.toml | |
git add Cargo.lock | |
git commit -m "bump version to ${{ github.event.release.tag_name }}" | |
git push ${{ steps.env.outputs.remote }} ${{ steps.env.outputs.default-branch }} | |
build: | |
needs: update-version | |
strategy: | |
matrix: | |
os: | |
- windows-latest | |
- ubuntu-latest | |
- macos-latest | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: ⬇️ Checkout | |
uses: actions/[email protected] | |
- name: ⬇️ Force fetch of repo to get the absolute latest version | |
run: | | |
git fetch --tags | |
git checkout ${{ needs.update-version.outputs.default-branch }} | |
git pull ${{ needs.update-version.outputs.remote }} ${{ needs.update-version.outputs.default-branch }} | |
- name: ⚙️ Install UPX on windows | |
if: matrix.os == 'windows-latest' | |
uses: crazy-max/ghaction-upx@v3 | |
with: | |
install-only: true | |
- name: ⬇️ Get Current Release | |
id: get-release | |
uses: joutvhu/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: ⬇️ Setup rust toolchain | |
uses: actions-rust-lang/[email protected] | |
- name: 📦 Build library (Linux, Windows) | |
if: matrix.os != 'macos-latest' | |
run: cargo build --release | |
- name: 📦 Build library (macOS) | |
if: matrix.os == 'macos-latest' | |
run: cargo rustc --release -- -C link-arg=-undefined -C link-arg=dynamic_lookup | |
- name: 📦 Compress DLL with UPX on windows | |
if: matrix.os == 'windows-latest' | |
run: upx --best --lzma target/release/balalib.dll | |
- name: 🚀 Push library to release assets (Windows) | |
uses: actions/[email protected] | |
if: matrix.os == 'windows-latest' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.get-release.outputs.upload_url }} | |
asset_path: 'target/release/balalib.dll' | |
asset_name: 'balalib.dll' | |
asset_content_type: application/octet-stream | |
- name: 🚀 Push library to release assets (Linux) | |
uses: actions/[email protected] | |
if: matrix.os == 'ubuntu-latest' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.get-release.outputs.upload_url }} | |
asset_path: 'target/release/libbalalib.so' | |
asset_name: 'balalib.so' | |
asset_content_type: application/octet-stream | |
- name: 🚀 Push library to release assets (MacOS) | |
uses: actions/[email protected] | |
if: matrix.os == 'macos-latest' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.get-release.outputs.upload_url }} | |
asset_path: 'target/release/libbalalib.dylib' | |
asset_name: 'balalib.dylib' | |
asset_content_type: application/octet-stream |