Skip to content

Commit

Permalink
Workflow to publish on Github
Browse files Browse the repository at this point in the history
In addition to publishing on `crates.io`, also publish pre-built
binaries on `Github`, using Github actions and cross compilation.
Inspired by: https://github.com/lotabout/skim/blob/master/.github/workflows/publish-github.yml
  • Loading branch information
crodjer committed Jun 27, 2021
1 parent 3e9accf commit 160bdae
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
111 changes: 109 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ env:
CARGO_TERM_COLOR: always

jobs:
release:
name: Publish
publish-crate:
name: Publish Crate
runs-on: ubuntu-20.04
steps:
- name: Clone
Expand All @@ -35,3 +35,110 @@ jobs:
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

publish-to-github:
name: Publish to Github
runs-on: ${{matrix.os}}
strategy:
matrix:
include:
- build: linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-musl
cross: false
- build: arm-v7
os: ubuntu-latest
rust: stable
target: armv7-unknown-linux-gnueabihf
linker: gcc-arm-linux-gnueabihf
cross: true
- build: aarch64
os: ubuntu-latest
rust: stable
target: aarch64-unknown-linux-gnu
linker: gcc-aarch64-linux-gnu
cross: true
- build: macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
cross: false
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Cache
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.rustup
target
key: ${{ runner.os }}-${{ matrix.rust }}

- name: Install Linker
if: matrix.cross
run: |
sudo apt update
sudo apt install ${{ matrix.linker }}
- name: Install Rust
run: |
rustup install ${{ matrix.rust }}
rustup target add ${{ matrix.target }}
rustup show
- name: Build
run: cargo build --release --target ${{ matrix.target }}

- name: Package Artifacts
run: |
src=$(pwd)
stage=
case $RUNNER_OS in
Linux)
stage=$(mktemp -d)
;;
macOS)
stage=$(mktemp -d -t tmp)
;;
esac
cp target/${{ matrix.target }}/release/sysit $stage/
cd $stage
RELEASE_VERSION=${GITHUB_REF#refs/tags/}
ASSET_NAME="sysit-$RELEASE_VERSION-${{ matrix.target }}.tar.gz"
ASSET_PATH="$src/$ASSET_NAME"
CHECKSUM_PATH="$ASSET_PATH.sha256"
echo "ASSET_PATH=$ASSET_PATH" >> $GITHUB_ENV
echo "CHECKSUM_PATH=$CHECKSUM_PATH" >> $GITHUB_ENV
tar czf $ASSET_PATH *
cd $src
case $RUNNER_OS in
Linux)
sha256sum $ASSET_NAME > $CHECKSUM_PATH
;;
macOS)
shasum -a 256 $ASSET_NAME > $CHECKSUM_PATH
;;
esac
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
${{ env.ASSET_PATH }}
${{ env.CHECKSUM_PATH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 160bdae

Please sign in to comment.