Skip to content

Commit

Permalink
Merge #98
Browse files Browse the repository at this point in the history
98: ci: Improve distribution via GitHub Releases r=taiki-e a=taiki-e

* Distribute `*.tar.gz` file for Windows. The current Windows 10 has bsdtar by default, so this makes it easy to install cross-platform.

  ```sh
  host=$(rustc -Vv | grep host | sed 's/host: //')
  curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-"$host".tar.gz | tar xzf - -C ~/.cargo/bin
  ```

* Distribute x86_64-unknown-linux-musl binary.

Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e authored Dec 3, 2020
2 parents c8f232b + df5a796 commit 807f6ea
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 44 deletions.
33 changes: 14 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,20 @@ jobs:
test:
strategy:
matrix:
rust:
include:
# This is the minimum supported Rust version of this crate.
# When updating this, the reminder to update the minimum supported Rust version in README.md.
- 1.36.0
- 1.39.0
- 1.41.0
- stable
- beta
include:
- os: ubuntu-latest
rust: nightly
- os: macos-latest
rust: nightly
- os: windows-latest
rust: nightly
- os: windows-latest
rust: nightly-x86_64-gnu
- os: ubuntu-latest
rust: nightly
- rust: 1.36.0
- rust: 1.39.0
- rust: 1.41.0
- rust: stable
- rust: beta
- rust: nightly
- rust: nightly
os: macos-latest
- rust: nightly
os: windows-latest
- rust: nightly
target: x86_64-unknown-linux-musl
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
steps:
Expand All @@ -63,8 +58,8 @@ jobs:
strategy:
matrix:
rust:
# cargo-hack is usually runnable with Cargo versions older than the Rust version required for installation.
# When updating this, the reminder to update the minimum supported Rust version in README.md.
# cargo-hack is usually runnable with Cargo versions older than the Rust version required for installation.
# When updating this, the reminder to update the minimum supported Rust version in README.md.
- 1.26.0
runs-on: ubuntu-latest
steps:
Expand Down
18 changes: 11 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,30 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

upload-assets:
name: ${{ matrix.target }}
if: github.repository_owner == 'taiki-e'
needs:
- create-release
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
include:
- target: x86_64-unknown-linux-gnu
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: x86_64-unknown-linux-musl
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@v2
- uses: taiki-e/github-actions/install-rust@main
# Work around https://github.com/actions/cache/issues/403 by using GNU tar
# instead of BSD tar.
- name: Install GNU tar
if: matrix.os == 'macos-latest'
if: startsWith(matrix.os, 'macos')
run: |
brew install gnu-tar
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> "${GITHUB_PATH}"
- run: ci/upload-assets.sh
- run: ci/upload-assets.sh ${{ matrix.target }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58 changes: 40 additions & 18 deletions ci/upload-assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,66 @@
set -euo pipefail
IFS=$'\n\t'

PACKAGE="cargo-hack"

function error {
if [[ -n "${GITHUB_ACTIONS:-}" ]]; then
echo "::error::$*"
else
echo "error: $*" >&2
fi
}

cd "$(cd "$(dirname "${0}")" && pwd)"/..

ref="${GITHUB_REF:?}"
tag="${ref#*/tags/}"
if [[ "${GITHUB_REF:?}" != "refs/tags/"* ]]; then
error "GITHUB_REF should start with 'refs/tags/'"
exit 1
fi
tag="${GITHUB_REF#refs/tags/}"

host=$(rustc -Vv | grep host | sed 's/host: //')
target="${1:-"${host}"}"
cargo="cargo"
if [[ "${host}" != "${target}" ]]; then
cargo="cross"
cargo install cross
fi

export CARGO_PROFILE_RELEASE_LTO=true
host=$(rustc -Vv | grep host | sed 's/host: //')

package="cargo-hack"
cargo build --bin "${package}" --release
$cargo build --bin "${PACKAGE}" --release --target "${target}"

cd target/release
assets=("${PACKAGE}-${target}.tar.gz")
cd target/"${target}"/release
case "${OSTYPE}" in
linux* | darwin*)
strip "${package}"
asset="${package}-${host}.tar.gz"
strip "${PACKAGE}"
tar czf ../../"${assets[0]}" "${PACKAGE}"
# TODO: remove this when release the next major version.
asset2="${package}-${tag}-${host}.tar.gz"
tar czf ../../"${asset}" "${package}"
tar czf ../../"${asset2}" "${package}"
if [[ ${target} != "x86_64-unknown-linux-musl" ]]; then
assets+=("${PACKAGE}-${tag}-${target}.tar.gz")
tar czf ../../"${assets[1]}" "${PACKAGE}"
fi
;;
cygwin* | msys*)
asset="${package}-${host}.zip"
assets+=("${PACKAGE}-${target}.zip")
tar czf ../../"${assets[0]}" "${PACKAGE}".exe
7z a ../../"${assets[1]}" "${PACKAGE}".exe
# TODO: remove this when release the next major version.
asset2="${package}-${tag}-${host}.zip"
7z a ../../"${asset}" "${package}".exe
7z a ../../"${asset2}" "${package}".exe
assets+=("${PACKAGE}-${tag}-${target}.zip")
7z a ../../"${assets[2]}" "${PACKAGE}".exe
;;
*)
echo "unrecognized OSTYPE: ${OSTYPE}"
error "unrecognized OSTYPE: ${OSTYPE}"
exit 1
;;
esac
cd ../..

if [[ -z "${GITHUB_TOKEN:-}" ]]; then
echo "GITHUB_TOKEN not set, skipping deploy"
error "GITHUB_TOKEN not set, skipping deploy"
exit 1
else
gh release upload "${tag}" "${asset}" "${asset2}" --clobber
gh release upload "${tag}" "${assets[@]}" --clobber
fi

0 comments on commit 807f6ea

Please sign in to comment.