From 4d175ada13f442fe9ad0a8b50a37ca77f27936a5 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 28 Jan 2020 02:19:24 -0800 Subject: [PATCH] Build and upload release artifacts from GitHub Actions (#581) --- .github/workflows/{rust.yaml => main.yaml} | 22 +++++++++ bin/package | 54 ++++++++++++++++++++++ ci/before_deploy.ps1 | 26 ----------- ci/before_deploy.sh | 36 --------------- ci/install.sh | 27 ----------- ci/script.sh | 24 ---------- 6 files changed, 76 insertions(+), 113 deletions(-) rename .github/workflows/{rust.yaml => main.yaml} (59%) create mode 100755 bin/package delete mode 100644 ci/before_deploy.ps1 delete mode 100644 ci/before_deploy.sh delete mode 100644 ci/install.sh delete mode 100644 ci/script.sh diff --git a/.github/workflows/rust.yaml b/.github/workflows/main.yaml similarity index 59% rename from .github/workflows/rust.yaml rename to .github/workflows/main.yaml index 02ca37e..dcdf18d 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/main.yaml @@ -10,6 +10,13 @@ jobs: - macos-latest - ubuntu-latest - windows-latest + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-musl + - os: macos-latest + target: x86_64-apple-darwin + - os: windows-latest + target: x86_64-pc-windows-msvc runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v1 @@ -17,6 +24,7 @@ jobs: uses: actions-rs/toolchain@v1 with: toolchain: stable + target: ${{ matrix.target }} profile: minimal components: clippy, rustfmt override: true @@ -44,3 +52,17 @@ jobs: cargo run -- --completions $shell > $script done git diff --no-ext-diff --quiet --exit-code + - name: Package + id: package + if: startsWith(github.ref, 'refs/tags/v') + run: ./bin/package ${{github.ref}} ${{matrix.os}} ${{ matrix.target }} + shell: bash + - name: Publish + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/v') + with: + draft: false + files: ${{ steps.package.outputs.archive }} + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/bin/package b/bin/package new file mode 100755 index 0000000..2b43630 --- /dev/null +++ b/bin/package @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +version=${1#"refs/tags/"} +os=$2 +target=$3 +src=`pwd` +dist=$src/dist +bin=just + +echo "Packaging $bin $version for $target..." + +test -f Cargo.lock || cargo generate-lockfile + +echo "Building $bin..." + +case $os in + ubuntu-latest | macos-latest) + cargo rustc --bin $bin --target $target --release -- -C lto + executable=target/$target/release/$bin + ;; + windows-latest) + cargo rustc --bin $bin --target $target --release -- -C lto -C target-feature="+crt-static" + executable=target/$target/release/$bin.exe + ;; +esac + +echo "Copying release files..." +mkdir dist +cp -r \ + $executable \ + Cargo.lock \ + Cargo.toml \ + GRAMMAR.md \ + LICENSE \ + README.adoc \ + man \ + $dist + +cd $dist +echo "Creating release archive..." +case $os in + ubuntu-latest | macos-latest) + archive=$dist/$bin-$version-$target.tar.gz + tar czf $archive * + echo "::set-output name=archive::$archive" + ;; + windows-latest) + archive=$dist/$bin-$version-$target.zip + 7z a $archive * + echo "::set-output name=archive::`pwd -W`/$bin-$version-$target.zip" + ;; +esac diff --git a/ci/before_deploy.ps1 b/ci/before_deploy.ps1 deleted file mode 100644 index 375bc05..0000000 --- a/ci/before_deploy.ps1 +++ /dev/null @@ -1,26 +0,0 @@ -# This script takes care of packaging the build artifacts that will go in the -# release zipfile - -$SRC_DIR = $PWD.Path -$STAGE = [System.Guid]::NewGuid().ToString() - -Set-Location $ENV:Temp -New-Item -Type Directory -Name $STAGE -Set-Location $STAGE - -$ZIP = "$SRC_DIR\$($Env:CRATE_NAME)-$($Env:APPVEYOR_REPO_TAG_NAME)-$($Env:TARGET).zip" - -# DONE Update this to package the right artifacts -Copy-Item "$SRC_DIR\target\$($Env:TARGET)\release\just.exe" '.\' -Copy-Item "$SRC_DIR\GRAMMAR.md" '.\' -Copy-Item "$SRC_DIR\LICENSE" '.\' -Copy-Item "$SRC_DIR\README.adoc" '.\' - -7z a "$ZIP" * - -Push-AppveyorArtifact "$ZIP" - -Remove-Item *.* -Force -Set-Location .. -Remove-Item $STAGE -Set-Location $SRC_DIR diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh deleted file mode 100644 index 9ada8d2..0000000 --- a/ci/before_deploy.sh +++ /dev/null @@ -1,36 +0,0 @@ -# This script takes care of building your crate and packaging it for release - -set -ex - -main() { - local src=$(pwd) \ - stage= - - case $TRAVIS_OS_NAME in - linux) - stage=$(mktemp -d) - ;; - osx) - stage=$(mktemp -d -t tmp) - ;; - esac - - test -f Cargo.lock || cargo generate-lockfile - - # DONE Update this to build the artifacts that matter to you - cross rustc --bin just --target $TARGET --release -- -C lto - - # DONE Update this to package the right artifacts - cp target/$TARGET/release/just $stage/ - cp GRAMMAR.md $stage/ - cp LICENSE $stage/ - cp README.adoc $stage/ - - cd $stage - tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz * - cd $src - - rm -rf $stage -} - -main diff --git a/ci/install.sh b/ci/install.sh deleted file mode 100644 index 748ad9a..0000000 --- a/ci/install.sh +++ /dev/null @@ -1,27 +0,0 @@ -set -ex - -main() { - local target= - if [ $TRAVIS_OS_NAME = linux ]; then - target=x86_64-unknown-linux-musl - sort=sort - else - target=x86_64-apple-darwin - sort=gsort # for `sort --sort-version`, from brew's coreutils. - fi - - # This fetches latest stable release - local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \ - | cut -d/ -f3 \ - | grep -E '^v[0.1.0-9.]+$' \ - | $sort --version-sort \ - | tail -n1) - curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- \ - --force \ - --git japaric/cross \ - --tag $tag \ - --target $target -} - -main diff --git a/ci/script.sh b/ci/script.sh deleted file mode 100644 index fabbb59..0000000 --- a/ci/script.sh +++ /dev/null @@ -1,24 +0,0 @@ -# This script takes care of testing your crate - -set -ex - -# DONE This is the "test phase", tweak it as you see fit -main() { - cross build --target $TARGET - cross build --target $TARGET --release - - if [ ! -z $DISABLE_TESTS ]; then - return - fi - - cross test --target $TARGET - cross test --target $TARGET --release - - cross run --target $TARGET - cross run --target $TARGET --release -} - -# we don't run the "test phase" when doing deploys -if [ -z $TRAVIS_TAG ]; then - main -fi