diff options
author | remgodow <remgodow@users.noreply.github.com> | 2020-09-20 12:22:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-20 12:22:53 +0200 |
commit | 58187b49d13c2c7da186ac103c5b064cd0c6ce50 (patch) | |
tree | 6ee704949e9cbc5baef5a2647fec13b3a4188dc6 | |
parent | 2ef120fa7a983583253e4967d119c7e1a61ef154 (diff) |
chore(ci): build binaries using Github actions. (#181)
* Remove connections vector from OpenSockets, use common OpenSockets implementation based on sysinfo and netstat2.
* Replace termion backend with crossterm, which works on Windows as well.
* More fixes for windows build.
* Remove tui default-features (termion), update unit tests for crossterm.
* Windows compilation fixes.
* Remove unused get_open_sockets implementations for linux and mac. Fix formatting.
* Add build.rs for windows to download and extract Packet.lib from npcap SDK.
* Resolve Cargo.lock after merging main.
* fix(tests): adjust snapshots new location of the dns resolution
* style(clippy): clippy
* style(clippy): remove dead code
* Test github actions.
* Fix action syntax.
* Fix "Show build.rs stderr" step.
* Add artifact upload step.
* style(clippy): use write_all in build.rs
* Fix path in upload binary step
* style(clippy): remove unused import added by Intellij
* Separate upload artifacts actions for Windows.
* Troubleshooting windows artifacts upload.
* Fix typo
* Bump upload-artifact to v2.
* fix(review): change branch name to main, remove nightly
* feat(infra): test builds on nightly rust
* fix(infra): remove debug logs from ci action
* feat(infra): release github action
* fix: merge issues
* fix(release): add linux generic
* feat(infra): build musl on release
* feat(infra): fix release verioning
* feat(infra): another try for fixing versioning
* fix(infra): use version from version step instead of release id
* fix(infra): fix add macos target variable, use --target for cargo build
* fix(infra): add musl-tools required by musl target
* fix(infra): fix action
* fix(infra): fix action
* fix(build): trigger build-release action when release has been created on github, tar executable without directories
* fix(debug): remove actions branch
Co-authored-by: Aram Drevekenin <aram@poor.dev>
-rw-r--r-- | .github/workflows/ci.yaml | 83 | ||||
-rw-r--r-- | .github/workflows/nightly.yaml | 62 | ||||
-rw-r--r-- | .github/workflows/release.yaml | 109 |
3 files changed, 254 insertions, 0 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..6d449fe --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,83 @@ +name: ci +on: + pull_request: + push: + branches: + - main +jobs: + test: + name: test + env: + # Emit backtraces on panics. + RUST_BACKTRACE: 1 + runs-on: ${{ matrix.os }} + strategy: + matrix: + build: + - stable + - macos + - win-msvc + include: + - build: stable + os: ubuntu-18.04 + rust: stable + - build: macos + os: macos-latest + rust: stable + - build: win-msvc + os: windows-2019 + rust: stable + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + components: rustfmt, clippy + + - name: Check formatting + run: cargo fmt --all -- --check + + - name: Run clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + - name: Build + run: cargo build --verbose + + # This is useful for debugging problems when the expected build artifacts + # (like shell completions and man pages) aren't generated. + - name: Show build.rs stderr + if: matrix.os == 'windows-2019' + shell: bash + run: | + set +x + stderr="$(find "./target/debug" -name stderr -print0 | xargs -0 ls -t | head -n1)" + if [ -s "$stderr" ]; then + echo "===== $stderr ===== " + cat "$stderr" + echo "=====" + fi + set -x + + - name: Run tests + run: cargo test --verbose + + - name: Upload unix binary + if: matrix.os != 'windows-2019' + uses: actions/upload-artifact@v1 + with: + name: ${{ matrix.os }}-${{ matrix.rust }} + path: target/debug/bandwhich + + - name: Upload windows binary + if: matrix.os == 'windows-2019' + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.os }}-${{ matrix.rust }} + path: | + target/debug/bandwhich.exe + target/debug/bandwhich.pdb diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml new file mode 100644 index 0000000..b6fc001 --- /dev/null +++ b/.github/workflows/nightly.yaml @@ -0,0 +1,62 @@ +name: nightly +on: + pull_request: + push: + branches: + - main + - actions +jobs: + test: + name: test + env: + # Emit backtraces on panics. + RUST_BACKTRACE: 1 + runs-on: ${{ matrix.os }} + strategy: + matrix: + build: + - ubuntu + - macos + - win-msvc + include: + - build: ubuntu + os: ubuntu-18.04 + rust: nightly + - build: macos + os: macos-latest + rust: nightly + - build: win-msvc + os: windows-2019 + rust: nightly + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + + - name: Build + run: cargo build --verbose + + # This is useful for debugging problems when the expected build artifacts + # (like shell completions and man pages) aren't generated. + - name: Show build.rs stderr + if: matrix.os == 'windows-2019' + shell: bash + run: | + set +x + stderr="$(find "./target/debug" -name stderr -print0 | xargs -0 ls -t | head -n1)" + if [ -s "$stderr" ]; then + echo "===== $stderr ===== " + cat "$stderr" + echo "=====" + fi + set -x + + - name: Run tests + run: cargo test --verbose + diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2ffccea --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,109 @@ +# The way this works is the following: +# +# - create-release job runs purely to initialize the GitHub release itself +# and to output upload_url for the following job. +# +# - build-release job runs only once create-release is finished. It gets +# the release upload URL from create-release job outputs, then builds +# the release executables for each supported platform and attaches them +# as release assets to the previously created release. +# +# The key here is that we create the release only once. +# +# Reference: +# - https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/ + +name: release +on: + release: + types: + - created + +jobs: + build-release: + name: build-release + runs-on: ${{ matrix.os }} + env: + # Emit backtraces on panics. + RUST_BACKTRACE: 1 + strategy: + matrix: + build: + - linux glib x64 + - linux musl x64 + - macos x64 + - win-msvc x64 + include: + - build: linux glib x64 + os: ubuntu-18.04 + rust: stable + target: x86_64-unknown-linux-gnu + - build: linux musl x64 + os: ubuntu-18.04 + rust: stable + target: x86_64-unknown-linux-musl + - build: macos x64 + os: macos-latest + rust: stable + target: x86_64-apple-darwin + - build: win-msvc x64 + os: windows-2019 + rust: stable + target: x86_64-pc-windows-msvc + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + target: ${{ matrix.target }} + + - name: Install musl-tools + if: matrix.target == 'x86_64-unknown-linux-musl' + run: sudo apt-get install -y --no-install-recommends musl-tools + + - name: Build release binary + run: cargo build --verbose --release --target ${{ matrix.target }} + + - name: Strip release binary (unix) + if: matrix.os != 'windows-2019' + run: strip "target/${{ matrix.target }}/release/bandwhich" + + - name: Tar release (unix) + if: matrix.os != 'windows-2019' + working-directory: ./target/${{ matrix.target }}/release + run: tar cvfz bandwhich-v${{ github.event.release.tag_name }}-${{matrix.target}}.tar.gz "bandwhich" + + - name: Zip Windows release + if: matrix.os == 'windows-2019' + working-directory: ./target/${{ matrix.target }}/release + run: tar.exe -a -c -f bandwhich-v${{ github.event.release.tag_name }}-${{matrix.target}}.zip "bandwhich.exe" + + - name: Upload release archive (linux) + if: matrix.os != 'windows-2019' + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./target/${{ matrix.target }}/release/bandwhich-v${{ github.event.release.tag_name }}-${{matrix.target}}.tar.gz + asset_name: bandwhich-v${{ github.event.release.tag_name }}-${{matrix.target}}.tar.gz + asset_content_type: application/octet-stream + + - name: Upload Windows release archive + if: matrix.os == 'windows-2019' + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./target/${{ matrix.target }}/release/bandwhich-v${{ github.event.release.tag_name }}-${{matrix.target}}.zip + asset_name: bandwhich-v${{ github.event.release.tag_name }}-${{matrix.target}}.zip + asset_content_type: application/octet-stream |