diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..604194b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,142 @@ +# Based on: https://github.com/ClementTsang/bottom/blob/master/.github/workflows/deployment.yml + +name: Release + +on: + push: + tags: + - v* + +env: + CARGO_TERM_COLOR: always + +jobs: + # publish-crate: + # name: Publish Crate + # runs-on: ubuntu-20.04 + # defaults: + # run: + # working-directory: ./pagebreak + # steps: + # - name: Clone + # uses: actions/checkout@v2 + # - name: Cache + # uses: actions/cache@v2 + # with: + # path: | + # ~/.cargo/registry + # ~/.cargo/git + # ~/.rustup + # target + # key: ${{ runner.os }}-stable + # - name: Setup + # run: | + # rustup install stable + # - name: Build + # run: cargo build --verbose + # - name: Run tests + # run: cargo test + # - name: Publish + # run: cargo publish + # env: + # CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + publish-to-github: + name: Publish to Github + runs-on: ${{matrix.os}} + defaults: + run: + working-directory: ./pagebreak + 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/pagebreak $stage/ + cd $stage + RELEASE_VERSION=${GITHUB_REF#refs/tags/} + ASSET_NAME="pagebreak-$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 }}