2019-11-21 01:07:59 +00:00
name : CICD
2019-11-25 05:30:38 +00:00
# spell-checker:ignore CICD CODECOV MSVC MacOS SHAs buildable clippy esac gnueabihf libssl mkdir musl popd pushd rustfmt softprops toolchain
2019-11-21 01:07:59 +00:00
env :
PROJECT_NAME : lsd
on : [ push, pull_request]
jobs :
2019-11-21 02:04:54 +00:00
style :
name : Style
runs-on : ${{ matrix.os }}
strategy :
fail-fast : false
matrix :
2019-11-24 19:32:55 +00:00
os : [ ubuntu-latest, macos-latest, windows-latest ]
2019-11-21 02:04:54 +00:00
steps :
- uses : actions/checkout@v1
- name : Install `rust` toolchain
uses : actions-rs/toolchain@v1
with :
toolchain : stable
override : true
profile : minimal # minimal component installation (ie, no documentation)
components : rustfmt, clippy
- name : "`fmt` testing"
uses : actions-rs/cargo@v1
with :
command : fmt
args : --all -- --check
- name : "`clippy` testing"
uses : actions-rs/cargo@v1
with :
command : clippy
args : -- -D warnings
2019-11-24 23:41:45 +00:00
build :
name : Build
runs-on : ${{ matrix.os }}
2019-11-21 01:07:59 +00:00
strategy :
fail-fast : false
matrix :
target :
2019-11-21 05:09:19 +00:00
- arm-unknown-linux-gnueabihf
2019-11-21 01:07:59 +00:00
- i686-unknown-linux-gnu
2019-11-21 05:09:19 +00:00
- i686-unknown-linux-musl
2019-11-21 01:07:59 +00:00
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
2019-11-24 23:41:45 +00:00
# - i686-apple-darwin ## (deprecated/un-buildable)
2019-11-21 05:53:27 +00:00
- x86_64-apple-darwin
2019-11-24 23:41:45 +00:00
# - i686-pc-windows-gnu ## gnu targets on Windows are broken when alternate `gcc` compilers are in the PATH (refs: <https://github.com/rust-lang/rust/issues/47048>, <https://github.com/rust-lang/rust/issues/53454>, <https://github.com/rust-lang/cargo/issues/6754>)
2019-11-21 01:07:59 +00:00
- i686-pc-windows-msvc
2019-11-24 23:41:45 +00:00
# - x86_64-pc-windows-gnu ## gnu targets on Windows are broken when alternate `gcc` compilers are in the PATH (refs: <https://github.com/rust-lang/rust/issues/47048>, <https://github.com/rust-lang/rust/issues/53454>, <https://github.com/rust-lang/cargo/issues/6754>)
2019-11-21 01:07:59 +00:00
- x86_64-pc-windows-msvc
2019-11-24 23:41:45 +00:00
include :
- target : arm-unknown-linux-gnueabihf
os : ubuntu-latest
cross : true
- target : i686-unknown-linux-gnu
os : ubuntu-latest
cross : true
- target : i686-unknown-linux-musl
os : ubuntu-latest
cross : true
- target : x86_64-unknown-linux-gnu
os : ubuntu-latest
cross : true
- target : x86_64-unknown-linux-musl
os : ubuntu-latest
cross : true
- target : i686-apple-darwin
os : macos-latest
- target : x86_64-apple-darwin
os : macos-latest
- target : i686-pc-windows-gnu
os : windows-latest
- target : i686-pc-windows-msvc
os : windows-latest
- target : x86_64-pc-windows-gnu
os : windows-latest
- target : x86_64-pc-windows-msvc
os : windows-latest
2019-11-21 01:07:59 +00:00
steps :
- uses : actions/checkout@v1
2019-11-25 05:29:00 +00:00
- name : Install any prerequisites
shell : bash
run : |
case ${{ matrix.target }} in
arm-unknown-linux-gnueabihf) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
esac
2019-11-24 19:32:55 +00:00
- name : Initialize workflow variables
id : vars
2019-11-21 01:07:59 +00:00
shell : bash
run : |
2019-11-25 00:58:55 +00:00
# staging directory
STAGING='_staging'
echo set-output name=STAGING::${STAGING}
echo ::set-output name=STAGING::${STAGING}
2019-11-24 19:32:55 +00:00
# determine EXE suffix
2019-11-24 23:41:45 +00:00
EXE_suffix="" ; case ${{ matrix.target }} in *-pc-windows-*) EXE_suffix=".exe" ;; esac;
2019-11-24 21:22:55 +00:00
echo set-output name=EXE_suffix::${EXE_suffix}
echo ::set-output name=EXE_suffix::${EXE_suffix}
2019-11-24 23:41:45 +00:00
# parse commit reference info
2019-11-22 04:24:37 +00:00
REF_NAME=${GITHUB_REF#refs/*/}
2019-11-24 23:41:45 +00:00
unset REF_BRANCH ; case ${GITHUB_REF} in refs/heads/*) REF_BRANCH=${GITHUB_REF#refs/heads/} ;; esac;
unset REF_TAG ; case ${GITHUB_REF} in refs/tags/*) REF_TAG=${GITHUB_REF#refs/tags/} ;; esac;
2019-11-22 04:24:37 +00:00
REF_SHAS=${GITHUB_SHA:0:8}
2019-11-24 21:22:55 +00:00
echo set-output name=REF_NAME::${REF_NAME}
echo set-output name=REF_BRANCH::${REF_BRANCH}
echo set-output name=REF_TAG::${REF_TAG}
echo set-output name=REF_SHAS::${REF_SHAS}
2019-11-22 04:24:37 +00:00
echo ::set-output name=REF_NAME::${REF_NAME}
echo ::set-output name=REF_BRANCH::${REF_BRANCH}
echo ::set-output name=REF_TAG::${REF_TAG}
echo ::set-output name=REF_SHAS::${REF_SHAS}
2019-11-25 00:58:55 +00:00
# package name
PKG_suffix=".tar.gz" ; case ${{ matrix.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac;
PKG_BASENAME=${PROJECT_NAME}-${REF_TAG:-$REF_SHAS}-${{ matrix.target }}
PKG_NAME=${PKG_BASENAME}${PKG_suffix}
echo set-output name=PKG_suffix::${PKG_suffix}
echo set-output name=PKG_BASENAME::${PKG_BASENAME}
echo set-output name=PKG_NAME::${PKG_NAME}
echo ::set-output name=PKG_suffix::${PKG_suffix}
echo ::set-output name=PKG_BASENAME::${PKG_BASENAME}
2019-11-21 05:09:19 +00:00
echo ::set-output name=PKG_NAME::${PKG_NAME}
2019-11-24 19:32:55 +00:00
# deployable tag? (ie, leading "vM" or "M"; M == version number)
2019-11-24 23:41:45 +00:00
unset DEPLOY ; if [[ $REF_TAG =~ ^[vV]?[0-9].* ]]; then DEPLOY=true ; fi
2019-11-24 21:22:55 +00:00
echo set-output name=DEPLOY::${DEPLOY}
2019-11-24 19:32:55 +00:00
echo ::set-output name=DEPLOY::${DEPLOY}
# target-specific options
# * test only binary for arm-type targets
2019-11-24 23:41:45 +00:00
unset CARGO_TEST_OPTIONS ; case ${{ matrix.target }} in arm-*) CARGO_TEST_OPTIONS="--bin ${PROJECT_NAME}" ;; esac;
2019-11-24 21:22:55 +00:00
echo set-output name=CARGO_TEST_OPTIONS::${CARGO_TEST_OPTIONS}
2019-11-24 19:32:55 +00:00
echo ::set-output name=CARGO_TEST_OPTIONS::${CARGO_TEST_OPTIONS}
2019-11-25 00:58:55 +00:00
# * strip executable?
2019-11-25 05:29:00 +00:00
STRIP="strip" ; case ${{ matrix.target }} in arm-unknown-linux-gnueabihf) STRIP="arm-linux-gnueabihf-strip" ;; *-pc-windows-*) STRIP="" ;; esac;
2019-11-24 20:28:57 +00:00
echo set-output name=STRIP::${STRIP}
echo ::set-output name=STRIP::${STRIP}
2019-11-21 01:07:59 +00:00
- name : Create all needed build/work directories
shell : bash
2019-11-25 00:58:55 +00:00
run : |
mkdir -p '${{ steps.vars.outputs.STAGING }}'
mkdir -p '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}'
mkdir -p '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}/autocomplete'
2019-11-21 01:07:59 +00:00
- name : Install `rust` toolchain
uses : actions-rs/toolchain@v1
with :
toolchain : stable
target : ${{ matrix.target }}
override : true
profile : minimal # minimal component installation (ie, no documentation)
- name : Build
uses : actions-rs/cargo@v1
with :
2019-11-24 23:41:45 +00:00
use-cross : ${{ matrix.cross }}
2019-11-21 01:07:59 +00:00
command : build
args : --release --target=${{ matrix.target }}
- name : Test
uses : actions-rs/cargo@v1
with :
2019-11-24 23:41:45 +00:00
use-cross : ${{ matrix.cross }}
2019-11-21 01:07:59 +00:00
command : test
2019-11-24 19:32:55 +00:00
args : --target=${{ matrix.target }} ${{ steps.vars.outputs.CARGO_TEST_OPTIONS}}
2019-11-21 01:07:59 +00:00
- name : Archive executable artifacts
uses : actions/upload-artifact@master
with :
name : ${{ env.PROJECT_NAME }}-${{ matrix.target }}
2019-11-24 21:43:26 +00:00
path : target/${{ matrix.target }}/release/${{ env.PROJECT_NAME }}${{ steps.vars.outputs.EXE_suffix }}
2019-11-21 01:07:59 +00:00
- name : Package
shell : bash
2019-11-24 20:28:57 +00:00
run : |
2019-11-25 00:58:55 +00:00
# binary
cp 'target/${{ matrix.target }}/release/${{ env.PROJECT_NAME }}${{ steps.vars.outputs.EXE_suffix }}' '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}/'
# `strip` binary (if needed)
if [ -n "${{ steps.vars.outputs.STRIP }}" ]; then "${{ steps.vars.outputs.STRIP }}" '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}/${{ env.PROJECT_NAME }}${{ steps.vars.outputs.EXE_suffix }}' ; fi
# README and LICENSE
cp README.md '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}/'
cp LICENSE '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}/'
# autocomplete
cp 'target/${{ matrix.target }}/release/build/${{ env.PROJECT_NAME }}-'*/'out/${{ env.PROJECT_NAME }}.bash' '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}/autocomplete/${{ env.PROJECT_NAME }}.bash-completion'
cp 'target/${{ matrix.target }}/release/build/${{ env.PROJECT_NAME }}-'*/'out/${{ env.PROJECT_NAME }}.fish' '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}/autocomplete/'
cp 'target/${{ matrix.target }}/release/build/${{ env.PROJECT_NAME }}-'*/'out/_${{ env.PROJECT_NAME }}' '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}/autocomplete/'
# base compressed package
pushd '${{ steps.vars.outputs.STAGING }}/' >/dev/null
case ${{ matrix.target }} in
*-pc-windows-*) 7z -y a '${{ steps.vars.outputs.PKG_NAME }}' '${{ steps.vars.outputs.PKG_BASENAME }}'/* | tail -2 ;;
*) tar czf '${{ steps.vars.outputs.PKG_NAME }}' '${{ steps.vars.outputs.PKG_BASENAME }}'/* ;;
esac;
popd >/dev/null
2019-11-21 01:07:59 +00:00
- name : Publish
uses : softprops/action-gh-release@v1
2019-11-24 19:32:55 +00:00
if : steps.vars.outputs.DEPLOY
2019-11-21 01:07:59 +00:00
with :
2019-11-25 00:58:55 +00:00
files : |
${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_NAME }}
2019-11-21 01:07:59 +00:00
env :
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2019-11-25 05:30:38 +00:00
coverage :
name : Code Coverage
runs-on : ${{ matrix.os }}
strategy :
fail-fast : true
matrix :
# os: [ ubuntu-latest, macos-latest, windows-latest ]
os : [ ubuntu-latest ] ## cargo-tarpaulin is currently only available on linux
steps :
- uses : actions/checkout@v1
# - name: Reattach HEAD ## may be needed for accurate code coverage info
# run: git checkout ${{ github.head_ref }}
- name : Initialize workflow variables
id : vars
shell : bash
run : |
# staging directory
STAGING='_staging'
echo set-output name=STAGING::${STAGING}
echo ::set-output name=STAGING::${STAGING}
# check for CODECOV_TOKEN availability (work-around for inaccessible 'secrets' object for 'if'; see <https://github.community/t5/GitHub-Actions/jobs-lt-job-id-gt-if-does-not-work-with-env-secrets/m-p/38549>)
unset HAS_CODECOV_TOKEN
if [ -n $CODECOV_TOKEN ]; then HAS_CODECOV_TOKEN='true' ; fi
echo set-output name=HAS_CODECOV_TOKEN::${HAS_CODECOV_TOKEN}
echo ::set-output name=HAS_CODECOV_TOKEN::${HAS_CODECOV_TOKEN}
env :
CODECOV_TOKEN : "${{ secrets.CODECOV_TOKEN }}"
- name : Create all needed build/work directories
shell : bash
run : |
mkdir -p '${{ steps.vars.outputs.STAGING }}/work'
- name : Install required packages
run : |
sudo apt-get -y install libssl-dev
pushd '${{ steps.vars.outputs.STAGING }}/work' >/dev/null
wget --no-verbose https://github.com/xd009642/tarpaulin/releases/download/0.9.3/cargo-tarpaulin-0.9.3-travis.tar.gz
tar xf cargo-tarpaulin-0.9.3-travis.tar.gz
cp cargo-tarpaulin "$(dirname -- "$(which cargo)")"/
popd >/dev/null
- name : Generate coverage
run : |
cargo tarpaulin --out Xml
- name : Upload coverage results (CodeCov.io)
# CODECOV_TOKEN (aka, "Repository Upload Token" for REPO from CodeCov.io) ## set via REPO/Settings/Secrets
# if: secrets.CODECOV_TOKEN (not supported {yet?}; see <https://github.community/t5/GitHub-Actions/jobs-lt-job-id-gt-if-does-not-work-with-env-secrets/m-p/38549>)
if : steps.vars.outputs.HAS_CODECOV_TOKEN
run : |
# CodeCov.io
cargo tarpaulin --out Xml
bash <(curl -s https://codecov.io/bash)
env :
CODECOV_TOKEN : "${{ secrets.CODECOV_TOKEN }}"