diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..83ac6f6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,81 @@ +on: [push, pull_request] + +name: Continuous Integration + +jobs: + dependencies: + name: cargo build | dependencies + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + + - id: cargo-cache + name: cache + uses: austinjones/rust-cache@v1 + with: + key: ci + + - name: cargo build | dependencies + uses: actions-rs/cargo@v1 + if: steps.cargo-cache.outputs.cache-hit != 'true' + with: + command: build + args: --locked + + - name: cargo build | dev dependencies + uses: actions-rs/cargo@v1 + if: steps.cargo-cache.outputs.cache-hit != 'true' + with: + command: test + args: --locked --no-run + + check: + name: cargo check + needs: dependencies + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + + - id: cargo-cache + name: cache + uses: austinjones/rust-cache@v1 + with: + key: ci + + - name: cargo check + uses: actions-rs/cargo@v1 + with: + command: check + + - name: cargo clippy + uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: cargo fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + test: + name: cargo test + runs-on: ubuntu-latest + needs: dependencies + steps: + - name: checkout + uses: actions/checkout@v2 + + - id: cargo-cache + name: cache + uses: austinjones/rust-cache@v1 + with: + key: ci + + - name: cargo test + uses: actions-rs/cargo@v1 + with: + command: test + args: -- --nocapture \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0182bf0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,183 @@ +name: Release +on: + release: + types: [published] + +jobs: + dependencies: + name: cargo build --dependencies + strategy: + fail-fast: false + matrix: + target: + - x86_64-unknown-linux-gnu + - x86_64-unknown-linux-musl + - armv7-unknown-linux-gnueabihf + - x86_64-apple-darwin + - x86_64-pc-windows-msvc + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + - target: armv7-unknown-linux-gnueabihf + os: ubuntu-latest + - target: x86_64-apple-darwin + os: macOS-latest + - target: x86_64-pc-windows-msvc + os: windows-latest + runs-on: ${{ matrix.os }} + steps: + - name: Setup | Checkout + uses: actions/checkout@v2 + + - name: Setup | Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + target: ${{ matrix.target }} + + - id: cargo-cache + name: cache + uses: austinjones/rust-cache@v1 + with: + key: release-${{ matrix.target }} + + - name: Setup | musl tools + if: steps.cargo-cache.outputs.cache-hit != 'true' && matrix.target == 'x86_64-unknown-linux-musl' + run: sudo apt install -y musl-tools + + - name: Setup | armv7 tools + if: steps.cargo-cache.outputs.cache-hit != 'true' && matrix.target == 'armv7-unknown-linux-gnueabihf' + run: | + sudo apt install -y build-essential gcc-arm-linux-gnueabihf + echo '[target.armv7-unknown-linux-gnueabihf]' >> ~/.cargo/config + echo 'linker = "arm-linux-gnueabihf-gcc"' >> ~/.cargo/config + + - name: Build | Dependencies + if: steps.cargo-cache.outputs.cache-hit != 'true' + run: cargo build --release --target ${{ matrix.target }} + + - name: Build | Dev Dependencies + if: steps.cargo-cache.outputs.cache-hit != 'true' && matrix.target != 'armv7-unknown-linux-gnueabihf' + run: cargo test --release --target ${{ matrix.target }} --no-run + + binaries: + name: cargo build + needs: dependencies + strategy: + fail-fast: false + matrix: + target: + - x86_64-unknown-linux-gnu + - x86_64-unknown-linux-musl + - armv7-unknown-linux-gnueabihf + - x86_64-apple-darwin + - x86_64-pc-windows-msvc + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + name: gur-x86_64-linux-gnu.tar.gz + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + name: gur-x86_64-linux-musl.tar.gz + - target: armv7-unknown-linux-gnueabihf + os: ubuntu-latest + name: gur-armv7-linux-gnueabihf.tar.gz + - target: x86_64-apple-darwin + os: macOS-latest + name: gur-x86_64-osx.tar.gz + - target: x86_64-pc-windows-msvc + os: windows-latest + name: gur-x86_64-windows.zip + runs-on: ${{ matrix.os }} + steps: + - name: Setup | Checkout + uses: actions/checkout@v2 + + - name: Setup | Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + target: ${{ matrix.target }} + + - id: cargo-cache + name: cache + uses: austinjones/rust-cache@v1 + with: + key: release-${{ matrix.target }} + + - name: Setup | musl tools + if: matrix.target == 'x86_64-unknown-linux-musl' + run: sudo apt install -y musl-tools + + - name: Setup | armv7 tools + if: matrix.target == 'armv7-unknown-linux-gnueabihf' + run: | + sudo apt install -y build-essential gcc-arm-linux-gnueabihf + echo '[target.armv7-unknown-linux-gnueabihf]' >> ~/.cargo/config + echo 'linker = "arm-linux-gnueabihf-gcc"' >> ~/.cargo/config + + - name: Build | Integration Tests + if: matrix.target != 'armv7-unknown-linux-gnueabihf' + run: cargo test --release --target ${{ matrix.target }} -- --nocapture + + - name: Build | Build + run: cargo build --release --target ${{ matrix.target }} + + - name: Post Setup | Prepare artifacts [Windows] + if: matrix.os == 'windows-latest' + run: | + cd target/${{ matrix.target }}/release + strip gur.exe + 7z a ../../../${{ matrix.name }} gur.exe + cd - + + - name: Post Setup | Prepare artifacts [-nix] + if: matrix.target != 'armv7-unknown-linux-gnueabihf' && matrix.os != 'windows-latest' + run: | + cd target/${{ matrix.target }}/release + strip gur + tar czvf ../../../${{ matrix.name }} gur + cd - + + - name: Post Setup | Prepare artifacts [-nix] + if: matrix.target == 'armv7-unknown-linux-gnueabihf' + run: | + cd target/${{ matrix.target }}/release + tar czvf ../../../${{ matrix.name }} gurr + cd - + + - name: Post Setup | Prepare checksums [Windows] + if: matrix.os == 'windows-latest' + run: Get-FileHash "${{ matrix.name }}" | Format-List > "${{ matrix.name }}.sha256" + + - name: Post Setup | Prepare checksums [-nix] + if: matrix.os != 'windows-latest' + run: openssl dgst -sha256 -r "${{ matrix.name }}" | awk '{print $1}' > "${{ matrix.name }}.sha256" + + - name: Post Setup | Upload artifacts + uses: AButler/upload-release-assets@v2.0 + with: + files: '${{ matrix.name }}*' + repo-token: ${{ secrets.GITHUB_TOKEN }} + + crates_io: + name: crates.io publish + needs: binaries + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + + - name: toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: cargo publish + run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }} diff --git a/src/bin/gur.rs b/src/bin/gur.rs index ccf8f33..1bbd56e 100644 --- a/src/bin/gur.rs +++ b/src/bin/gur.rs @@ -23,7 +23,7 @@ enum Command { watch_dir: Vec, #[clap(long, default_value = "1s", parse(try_from_str = humantime::parse_duration), help = "Duration of file watching delay. Default to 1 second.")] watch_duration: Duration, - } + }, } fn main() { diff --git a/src/set_new.rs b/src/set_new.rs index 62f9633..4fe8bae 100644 --- a/src/set_new.rs +++ b/src/set_new.rs @@ -1,7 +1,7 @@ use notify::{DebouncedEvent, RecursiveMode, Watcher}; -use std::{ffi::OsStr, path::Path}; use std::sync::mpsc; use std::time::Duration; +use std::{ffi::OsStr, path::Path}; use crate::{Logged, LoggedSideEffect};