Skip to content

Commit

Permalink
action for releasing example binary
Browse files Browse the repository at this point in the history
  • Loading branch information
puffyCid committed Jan 13, 2025
1 parent dcfbe80 commit 373db99
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/scripts/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -eu

# Slightly tweaked from https://github.com/EmbarkStudios/cargo-about/blob/main/.github/workflows/rust-ci.yml (MIT LICENSE)
# When run in a container, the ownership will be messed up, so mark the
# checkout dir as safe regardless of our env
git config --global --add safe.directory "$GITHUB_WORKSPACE"

# Normally we'll only do this on tags, but add --always to fallback to the revision
# if we're iterating or the like
tag=$(git describe --tags --abbrev=0 --always)

if [[ ${tag:0:1} != "v" ]]; then
tag="nightly"
fi

release_name="$NAME-$tag-$TARGET"
release_zip="${release_name}.zip"
release_tar="${release_name}.tar.gz"

mkdir "$release_name"

if [[ "$TARGET" =~ windows ]]; then
bin="$NAME.exe"
cp "examples/target/$TARGET/release-action/$bin" "$release_name/"
cp README.md LICENSE "$release_name/"
7z a -tzip "$release_zip" "$release_name"
else
bin="$NAME"
cp "examples/target/$TARGET/release-action/$bin" "$release_name/"
cp README.md LICENSE "$release_name/"
tar czf "$release_tar" "$release_name"
fi

rm -r "$release_name"

# Windows environments in github actions don't have the gnu coreutils installed,
# which includes the shasum exe, so we just use powershell instead
if [[ "$TARGET" =~ windows ]]; then
echo "(Get-FileHash \"${release_zip}\" -Algorithm SHA256).Hash | Out-File -Encoding ASCII -NoNewline \"${release_zip}.sha256\"" | pwsh -c -
else
echo -n "$(shasum -ba 256 "${release_tar}" | cut -d " " -f 1)" > "${release_tar}.sha256"
fi
48 changes: 48 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Release Example Binary

permissions:
contents: write

on:
push:
tags:
- v[0-9]+.*

jobs:
upload-release:
strategy:
matrix:
info:
- os: "macOS-latest"
target: "x86_64-apple-darwin"
- os: "macOS-latest"
target: "aarch64-apple-darwin"
- os: "windows-latest"
target: "x86_64-pc-windows-msvc"
- os: "ubuntu-latest"
target: "x86_64-unknown-linux-gnu"
runs-on: ${{ matrix.info.os }}
steps:
- name: Setup Stable Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.info.target }}
components: clippy, rustfmt

- name: Build Example
run: cd examples && cargo build --release --target ${{ matrix.info.target }}

- name: Package Example
shell: bash
env:
NAME: unifiedlog_iterator
TARGET: ${{ matrix.info.target }}
run: .github/scripts/package.sh

- name: Release
uses: softprops/action-gh-release@v2
with:
files: "unifiedlog_iterator*"
name: "${{ vars.GITHUB_REF_NAME }} - Released!"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 373db99

Please sign in to comment.