From 48eef7cc6ea8eb1e336872e5e78828eef886e209 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Tue, 15 Oct 2019 15:00:24 +0200 Subject: [PATCH] Replace travis with GH actions (#16) --- .ci/checksum.ps1 | 12 -- .ci/install_musl.sh | 14 --- .ci/lint.sh | 30 ----- .ci/prep_deploy.sh | 58 --------- .ci/test.sh | 48 -------- .github/workflows/rust-ci.yml | 221 ++++++++++++++++++++++++++++++++++ rust.travis.yml | 179 --------------------------- 7 files changed, 221 insertions(+), 341 deletions(-) delete mode 100644 .ci/checksum.ps1 delete mode 100755 .ci/install_musl.sh delete mode 100755 .ci/lint.sh delete mode 100755 .ci/prep_deploy.sh delete mode 100755 .ci/test.sh create mode 100644 .github/workflows/rust-ci.yml delete mode 100644 rust.travis.yml diff --git a/.ci/checksum.ps1 b/.ci/checksum.ps1 deleted file mode 100644 index 51af720..0000000 --- a/.ci/checksum.ps1 +++ /dev/null @@ -1,12 +0,0 @@ -param ( - [string]$filename = $(throw "-filename is required.") -) - -$ErrorActionPreference="Stop" - -# Get-FileHash is sha256 by default, but explicit is better! -# Most (all?) of powerhshell's string output stuff is the wildly terrible -# UTf-16, which unnecessarily inflates the output and makes it more annoying -# to read, so we force it to ASCII, and tell it remove newlines so the actual -# contents are exactly 64 bytes, like god intended -(Get-FileHash "${filename}" -Algorithm SHA256).Hash | Out-File -Encoding ASCII -NoNewline "${filename}.sha256" \ No newline at end of file diff --git a/.ci/install_musl.sh b/.ci/install_musl.sh deleted file mode 100755 index e20dd6f..0000000 --- a/.ci/install_musl.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -set -e - -travis_fold start "apt-get.musl" - travis_time_start - sudo apt-get update && sudo -E apt-get -yq --no-install-suggests --no-install-recommends install musl-tools - travis_time_finish -travis_fold end "apt-get.musl" - -travis_fold start "rustup.target.musl" - travis_time_start - rustup target add x86_64-unknown-linux-musl - travis_time_finish -travis_fold end "rustup.target.musl" diff --git a/.ci/lint.sh b/.ci/lint.sh deleted file mode 100755 index fb75fde..0000000 --- a/.ci/lint.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -set -e - -travis_fold start "rustup.component.install" - travis_time_start - rustup component add rustfmt clippy - travis_time_finish -travis_fold end "rustup.component.install" - -# Ensure everything has been rustfmt'ed -travis_fold start "rustfmt" - travis_time_start - cargo fmt -- --check - travis_time_finish -travis_fold end "rustfmt" - -# Download in a separate step to separate -# building from fetching dependencies -travis_fold start "cargo.fetch" - travis_time_start - cargo fetch - travis_time_finish -travis_fold end "cargo.fetch" - -# Because rust isn't brutal enough itself -travis_fold start "clippy" - travis_time_start - cargo clippy -- -D warnings - travis_time_finish -travis_fold end "clippy" diff --git a/.ci/prep_deploy.sh b/.ci/prep_deploy.sh deleted file mode 100755 index f76d66a..0000000 --- a/.ci/prep_deploy.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash -set -e - -# Fetch dependencies in a different step to clearly -# delineate between downloading and building -travis_fold start "cargo.fetch" - travis_time_start - cargo fetch --target "$TARGET" - travis_time_finish -travis_fold end "cargo.fetch" - -# Build without running to clearly delineate between -# building and packaging -travis_fold start "cargo.build" - travis_time_start - cargo build --release --target "$TARGET" - travis_time_finish -travis_fold end "cargo.build" - -travis_fold start "package.release" - travis_time_start - name="$REPO_NAME" - release_name="$name-$TRAVIS_TAG-$TARGET" - mkdir "$release_name" - - if [ "$TARGET" == "x86_64-pc-windows-msvc" ]; then - # We don't use name again, so just add the exe extension - # to it and call it a day - name="$name.exe" - else - # If we're not on windows, strip the binary to remove - # debug symbols and minimize the resulting release - # size without much effort - strip "target/$TARGET/release/$name" - fi - - # Copy the files into a versioned directorya and tarball + gzip it - # we do this regardless of the platform, because Windows can still - # untar stuff, no need for zip! - cp "target/$TARGET/release/$name" "$release_name/" - cp README.md LICENSE-APACHE LICENSE-MIT "$release_name/" - tar czvf "$release_name.tar.gz" "$release_name" - - rm -r "$release_name" - - stat "$release_name.tar.gz" - - # Get the sha-256 checksum w/o filename and newline, on windows we use - # powershell because git bash only includes md5/sha1sum - if [ "$TARGET" == "x86_64-pc-windows-msvc" ]; then - powershell -NoLogo -ExecutionPolicy Bypass -File .ci/checksum.ps1 "$release_name.tar.gz" - else - echo -n "$(shasum -ba 256 "$release_name.tar.gz" | cut -d " " -f 1)" > "$release_name.tar.gz.sha256" - fi - - stat "$release_name.tar.gz.sha256" - travis_time_finish -travis_fold end "package.release" diff --git a/.ci/test.sh b/.ci/test.sh deleted file mode 100755 index 5f8587c..0000000 --- a/.ci/test.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -set -e - -HOST_OS_NAME=$(uname -s) -TARGET="" - -if [ "$(uname)" == "Darwin" ]; then - TARGET="apple-darwin" -elif [ "${HOST_OS_NAME::5}" == "Linux" ]; then - # If we're on linux, always build for musl - TARGET="unknown-linux-musl" - .ci/install_musl.sh -elif [ "${HOST_OS_NAME::10}" == "MINGW64_NT" ]; then - TARGET="pc-windows-msvc" -elif [ "${HOST_OS_NAME::7}" == "MSYS_NT" ]; then # travis uses msys - TARGET="pc-windows-msvc" -elif [ "${HOST_OS_NAME::10}" == "MINGW32_NT" ]; then - echo "Why are you on a 32-bit machine?" - exit 1 -else - echo "Unknown host platform! '$HOST_OS_NAME'" - exit 1 -fi - -TARGET="x86_64-$TARGET" - -# Fetch dependencies in a different step to clearly -# delineate between downloading and building -travis_fold start "cargo.fetch" - travis_time_start - cargo fetch - travis_time_finish -travis_fold end "cargo.fetch" - -# Build without running to clearly delineate between -# building and running the tests -travis_fold start "cargo.build" - travis_time_start - cargo test --no-run --target $TARGET - travis_time_finish -travis_fold end "cargo.build" - -# Run the actual tests -travis_fold start "cargo.test" - travis_time_start - cargo test --target $TARGET - travis_time_finish -travis_fold end "cargo.test" diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml new file mode 100644 index 0000000..bda4ffc --- /dev/null +++ b/.github/workflows/rust-ci.yml @@ -0,0 +1,221 @@ +on: [push, pull_request] +name: CI +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + # make sure all code has been formatted with rustfmt + - run: rustup component add rustfmt + - name: check rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check --color always + + # run clippy to verify we have no warnings + - run: rustup component add clippy + - name: cargo fetch + uses: actions-rs/cargo@v1 + with: + command: fetch + - name: cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --lib --tests -- -D warnings + + test: + name: Test + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: cargo fetch + uses: actions-rs/cargo@v1 + with: + command: fetch + - name: cargo test build + uses: actions-rs/cargo@v1 + with: + command: build + args: --tests --release + - name: cargo test + uses: actions-rs/cargo@v1 + with: + command: test + args: --release + + # Remove this check if you don't use cargo-deny in the repo + deny-check: + name: cargo-deny check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: download cargo-deny + shell: bash + env: + DVS: 0.3.0-beta + DREPO: EmbarkStudios/cargo-deny + TARGET: x86_64-unknown-linux-musl + run: | + temp_archive=$(mktemp --suffix=.tar.gz) + curl -L --output "$temp_archive" https://github.com/$DREPO/releases/download/$DVS/cargo-deny-$DVS-$TARGET.tar.gz + + tar -xzvf "$temp_archive" -C . --strip-components=1 --wildcards "*/cargo-deny" + - name: cargo-deny check licenses + run: ./cargo-deny -L debug check license + - name: cargo-deny check bans + run: ./cargo-deny -L debug check ban + + # Remove this check if you don't publish the crate(s) from this repo + publish-check: + name: Publish Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: cargo fetch + uses: actions-rs/cargo@v1 + with: + command: fetch + - name: copy README + shell: bash + run: | + cp README.md lib + cp README.md cli + - name: cargo publish lib + uses: actions-rs/cargo@v1 + with: + command: publish + args: --dry-run --allow-dirty --manifest-path lib/Cargo.toml + - name: cargo publish cli + uses: actions-rs/cargo@v1 + with: + command: publish + args: --dry-run --allow-dirty --manifest-path cli/Cargo.toml + + # Remove this job if you don't publish the crate(s) from this repo + # You must add a crates.io API token to your GH secrets called CRATES_IO_TOKEN + publish: + name: Publish + needs: [test, deny-check, publish-check] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: cargo fetch + uses: actions-rs/cargo@v1 + with: + command: fetch + - name: cargo publish + uses: actions-rs/cargo@v1 + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} + with: + command: publish + + # Remove this job if you don't release binaries + # Replace occurances of $BIN_NAME with the name of your binary + release: + name: Release + needs: [test, deny-check] + if: startsWith(github.ref, 'refs/tags/') + strategy: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + include: + - os: ubuntu-latest + rust: stable + target: x86_64-unknown-linux-musl + bin: $BIN_NAME + # We don't enable the progress feature when targeting + # musl since there are some dependencies on shared libs + features: "" + - os: windows-latest + rust: stable + target: x86_64-pc-windows-msvc + bin: $BIN_NAME.exe + features: --features=progress + - os: macOS-latest + rust: stable + target: x86_64-apple-darwin + bin: $BIN_NAME + features: --features=progress + runs-on: ${{ matrix.os }} + steps: + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + override: true + target: ${{ matrix.target }} + - name: Install musl tools + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get install -y musl-tools + - name: Checkout + uses: actions/checkout@v1 + - name: cargo fetch + uses: actions-rs/cargo@v1 + with: + command: fetch + args: --target ${{ matrix.target }} + - name: Release build + uses: actions-rs/cargo@v1 + if: matrix.os != 'ubuntu-latest' + with: + command: build + args: --release --target ${{ matrix.target }} ${{ matrix.features }} + - name: Package + shell: bash + run: | + name=$BIN_NAME + tag=$(git describe --tags --abbrev=0) + release_name="$name-$tag-${{ matrix.target }}" + release_tar="${release_name}.tar.gz" + mkdir "$release_name" + + if [ "${{ matrix.target }}" != "x86_64-pc-windows-msvc" ]; then + strip "target/${{ matrix.target }}/release/${{ matrix.bin }}" + fi + + cp "target/${{ matrix.target }}/release/${{ matrix.bin }}" "$release_name/" + cp README.md LICENSE-APACHE LICENSE-MIT "$release_name/" + tar czvf "$release_tar" "$release_name" + + rm -r "$release_name" + + # Windows environments in github actions don't have the gnu coreutils installed, + # which includes the shasum exe, so we just use powershell instead + if [ "${{ matrix.os }}" == "windows-latest" ]; then + echo "(Get-FileHash \"${release_tar}\" -Algorithm SHA256).Hash | Out-File -Encoding ASCII -NoNewline \"${release_tar}.sha256\"" | pwsh -c - + else + echo -n "$(shasum -ba 256 "${release_tar}" | cut -d " " -f 1)" > "${release_tar}.sha256" + fi + - name: Publish + uses: softprops/action-gh-release@v1 + with: + draft: true + files: '$BIN_NAME*' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/rust.travis.yml b/rust.travis.yml deleted file mode 100644 index 2882987..0000000 --- a/rust.travis.yml +++ /dev/null @@ -1,179 +0,0 @@ -# _chanting_ rust, Rust, RUst, RUSt, RUST -language: rust - -stages: -- test -# Deploy stage on runs on a valid semver tag, regardless of branch -- name: deploy - if: tag =~ /^\d+\.\d+\.\d+.*$/ - -env: - global: - # We always want full stack traces in the event of a panic - - RUST_BACKTRACE=1 - -# See http://www.garbers.co.za/2017/11/01/code-folding-and-timing-in-travis-ci/ -# this just allows us to give _somewhat_ better views of the build steps -before_script: -- export -f travis_nanoseconds -- export -f travis_fold -- export -f travis_time_start -- export -f travis_time_finish - -matrix: - # We allow failures for the 'nightly' channel, but are ok with failures on 'beta' - allow_failures: - - env: NIGHTLY=1 - fast_finish: true - - include: - # _ _ _ - # | | (_) | | - # | | _ _ __ | |_ - # | | | | '_ \| __| - # | |____| | | | | |_ - # |______|_|_| |_|\__| - - # 1. Ensure rustfmt does not produce diffs. We always use - # the default rustfmt settings. - # 2. Ensure there are no clippy warnings. - - name: "stable lint" - # We could use a lint stage here, but prefer to go wide - # - stage: test - rust: stable - os: linux - script: .ci/lint.sh - - # We do the exact same checks on the beta channel, as both - # rustfmt and clippy can change their behavior between releases - # and introduce new diffs/lints compared to stable - - name: "beta lint" - stage: test - rust: beta - os: linux - script: .ci/lint.sh - - # _______ _ - # |__ __| | | - # | | ___ ___| |_ - # | |/ _ \/ __| __| - # | | __/\__ \ |_ - # |_|\___||___/\__| - - # Tests all platforms on stable - # and additionally running beta and nightly - # tests on Linux as Linux runs are generally - # faster in every aspect on Travis - - - name: "stable test linux" - stage: test - rust: stable - os: linux - script: .ci/test.sh - - - name: "beta test linux" - stage: test - rust: beta - os: linux - script: .ci/test.sh - - - name: "nightly test linux" - stage: test - rust: nightly - script: .ci/test.sh - env: - # We set this environment variable to indicate it is ok if this job fails - - NIGHTLY=1 - - - name: "stable test osx" - rust: stable - os: osx - script: .ci/test.sh - - - name: "stable test windows" - rust: stable - os: windows - script: .ci/test.sh - - # Add more testing stages if you have them! - - # _____ _ _ _ _ - # | __ \ | | | (_) | | - # | |__) | _| |__ | |_ ___| |__ - # | ___/ | | | '_ \| | / __| '_ \ - # | | | |_| | |_) | | \__ \ | | | - # |_| \__,_|_.__/|_|_|___/_| |_| - - # Publish a release to crates.io. The only - # thing you need to do is to is change the repo - # below, and provide the output of the `travis encrypt ` - # in the deploy.token.secure value. Note that you will - # need to encrypt the same key for different repos, you - # can't just copy the value from another repo. - - stage: deploy - rust: stable - os: linux - script: echo "deploying $TRAVIS_TAG to crates.io" - deploy: - provider: cargo - token: - secure: - on: - repo: EmbarkStudios/$REPO_NAME - tags: true - - # Keep these step if you want to publish tarballed releases to Github. - # Generally, this will only make sense for binary crates, so normally - # you will want to remove them. If you do, you can also remove the - # .ci/prep_deploy and .ci/checksum.ps1 - - - name: "publish x86_64-unknown-linux-musl" - stage: deploy - rust: stable - os: linux - env: - - DEPLOY=1 - - TARGET=x86_64-unknown-linux-musl - script: - - .ci/install_musl.sh - - .ci/prep_deploy.sh - - - name: "publish x86_64-pc-windows-msvc" - stage: deploy - os: windows - env: - - DEPLOY=1 - - TARGET=x86_64-pc-windows-msvc - # Override Travis' rust version, we don't want the gnu default - # caused Travis running in bash, the normal Travis Rust install - # process will pick up this environment variable - - TRAVIS_RUST_VERSION=stable-x86_64-pc-windows-msvc - script: - - .ci/prep_deploy.sh - - - name: "publish x86_64-apple-darwin" - stage: deploy - rust: stable - os: osx - env: - - DEPLOY=1 - - TARGET=x86_64-apple-darwin - script: - - .ci/prep_deploy.sh - -# Just as with the crates.io publish step, you will need -# to encrypt your API key with `travis encrypt ` and -# place it in the deploy.api_key.secure value -deploy: -- provider: releases - api_key: - secure: - file: - - $REPO_NAME-$TRAVIS_TAG-$TARGET.tar.gz - - $REPO_NAME-$TRAVIS_TAG-$TARGET.tar.gz.sha256 - skip_cleanup: true - on: - condition: $DEPLOY = 1 - repo: EmbarkStudios/$REPO_NAME - tags: true