From 160bdae51b2c90c3b6e8a0e6c4832506ebc55694 Mon Sep 17 00:00:00 2001 From: Rohan Jain Date: Sun, 27 Jun 2021 13:10:38 +0530 Subject: [PATCH] Workflow to publish on Github 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 --- .cargo/config | 5 ++ .github/workflows/release.yml | 111 +++++++++++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 .cargo/config diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..beb596d --- /dev/null +++ b/.cargo/config @@ -0,0 +1,5 @@ +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" + +[target.armv7-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1ee97fe..3c04e64 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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 }}