From 2a2018de670ac7f3cdc0ae84dfd050ce1efea80a Mon Sep 17 00:00:00 2001 From: Samuele Maci <macisamuele@gmail.com> Date: Sun, 7 Mar 2021 17:28:38 +0000 Subject: [PATCH] Define github actions workflows and publish binaries artifacts Among the definition of github actions I've cleanup * the build of examples as the project does not publish any example * the usage of env variables in makefile * the usage of `-Zunstable-options` in windows build (as no longer needed) --- .cargo/config | 2 +- .github/workflows/build.yml | 118 ++++++++++++++++++++++++++++++++++++ .travis.yml | 5 -- Makefile | 8 +-- 4 files changed, 122 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.cargo/config b/.cargo/config index 8a08da9..0beee4e 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,2 +1,2 @@ [target.x86_64-pc-windows-msvc] -rustflags = ["-Ctarget-feature=+crt-static", "-Zunstable-options"] +rustflags = ["-Ctarget-feature=+crt-static"] \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..b9d4a45 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,118 @@ +name: ci + +on: + pull_request: {} + push: {} + release: + types: [published] + +jobs: + fmt: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + override: true + components: rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + override: true + components: clippy + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-targets --all-features -- -F warnings + + test: + name: Unitest (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + override: true + components: clippy + - uses: actions-rs/cargo@v1 + env: + RUST_BACKTRACE: full + RUSTFLAGS: -F warnings + with: + command: test + args: --all --all-features + - name: "Ensure Cargo.lock is not modified" + run: git diff --exit-code Cargo.lock + + build-release: + name: Build release Executable (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + matrix: + 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 + env: + BINARY_EXTENSION: ${{ endsWith(matrix.target, '-msvc') && '.exe' || '' }} + PATH_BINARY: ${{ github.workspace }}/target/release/simple-http-server${{ endsWith(matrix.target, '-msvc') && '.exe' || '' }} + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + override: true + components: clippy + target: ${{ matrix.target }} + - uses: actions-rs/cargo@v1 + with: + command: build + args: --release --bin simple-http-server --locked + - uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.target }}-simple-http-server${{ env.BINARY_EXTENSION }} + path: ${{ env.PATH_BINARY }} + - name: Evaluate shasum + run: echo -n $(shasum -ba 256 ${{ env.PATH_BINARY }} | cut -d " " -f 1) > ${{ env.PATH_BINARY }}.sha256 + - uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.target }}-simple-http-server.sha256 + path: ${{ env.PATH_BINARY }}.sha256 + + - name: '[Optional] Publish Artifact' + if: ${{ github.event_name == 'release' }} + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ env.PATH_BINARY }} + asset_name: ${{ matrix.target }}-simple-http-server${{ env.BINARY_EXTENSION }} + tag: ${{ github.ref }} + overwrite: true + - name: '[Optional] Publish Artifact (shasum)' + if: ${{ github.event_name == 'release' }} + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ env.PATH_BINARY }}.sha256 + asset_name: ${{ matrix.target }}-simple-http-server${{ env.BINARY_EXTENSION }}.sha256 + tag: ${{ github.ref }} + overwrite: true diff --git a/.travis.yml b/.travis.yml index a02575b..02c0e2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ script: stages: - Check - Clippy - - Example - Test jobs: include: @@ -21,10 +20,6 @@ jobs: name: Clippy script: - make clippy - - stage: Example - name: Example - script: - - make example - stage: Test name: Unitest script: diff --git a/Makefile b/Makefile index e275e17..7fd623b 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,11 @@ fmt: cargo fmt --all -- --check clippy: - RUSTFLAGS='-F warnings' cargo clippy --all --tests --all-features - -example: - cargo build --examples + cargo clippy --all --tests --all-features -- -F warnings +test: export RUST_BACKTRACE := full test: - RUSTFLAGS='-F warnings' RUST_BACKTRACE=full cargo test --all --all-features + RUSTFLAGS='-F warnings' cargo test --all --all-features ci: fmt clippy example test git diff --exit-code Cargo.lock -- GitLab