From 661c45be4668d9bd2e1d6bd645122450dc4c7c7d Mon Sep 17 00:00:00 2001 From: Rob Young Date: Sun, 17 Jan 2021 21:43:36 +0000 Subject: [PATCH] Add CI and Release workflows --- .github/workflows/ci.yml | 48 +++++++++++++++++++ .github/workflows/release.yml | 89 +++++++++++++++++++++++++++++++++++ .gitignore | 1 + 3 files changed, 138 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..762a6c5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,48 @@ +name: CI + +on: + pull_request: + branches: [main] + push: + branches: [main] + +jobs: + test: + name: Test + + strategy: + matrix: + rust: + - stable + - nightly + os: + - ubuntu-latest + - macos-latest + - windows-2019 + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + override: true + + - run: cargo test + + static: + name: Static analysis + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - run: cargo fmt --all -- --check + - run: cargo install cargo-audit + - run: cargo clippy + - run: cargo audit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d788577 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,89 @@ +# A lot of this is lifted from https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/release.yml +name: Release + +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + +jobs: + build: + strategy: + matrix: + include: + - build: linux + os: ubuntu-latest + target: x86_64-unknown-linux-musl + + - build: linux-arm + os: ubuntu-latest + target: arm-unknown-linux-gnueabihf + + - build: macos + os: macos-latest + target: x86_64-apple-darwin + + - build: win-msvc + os: windows-2019 + target: x86_64-pc-windows-msvc + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + + - name: Install packages (Ubuntu) + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends musl-tools + + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + profile: minimal + override: true + target: ${{ matrix.target }} + + - name: Install Cross + run: | + cargo install cross + + - name: Build release binary + run: | + cross build --verbose --release --target ${{ matrix.target }} + + - name: Strip release binary (linux and macos) + if: matrix.build == 'linux' || matrix.build == 'macos' + run: strip "target/${{ matrix.target }}/release/y2j" + + - name: Strip release binary (arm) + if: matrix.build == 'linux-arm' + run: | + docker run --rm \ + -v "$PWD/target:/target:Z" \ + rustembedded/cross:arm-unknown-linux-gnueabihf \ + arm-linux-gnueabihf-strip \ + /target/arm-unknown-linux-gnueabihf/release/rg + + - name: Release vars + id: vars + run: | + version=${GITHUB_REF#refs/tags/} + echo ::set-output name=VERSION::${version} + echo ::set-output name=FILE_NAME::y2j-${version}-${{ matrix.target }} + + - name: Rename release binary + run: | + cp "target/${{ matrix.target }}/release/y2j" ${{ steps.vars.FILE_NAME }} + + - uses: actions/upload-artifact@v2 + with: + path: ${{ steps.vars.FILE_NAME }} + + release: + runs-on: ubuntu-latest + + steps: + - uses: actions/download-artifact@v2 + - run: ls -l diff --git a/.gitignore b/.gitignore index ea8c4bf..51dc1f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +!/.github/