From 632d7030873c618a45891c8a4beaee0447b01697 Mon Sep 17 00:00:00 2001 From: Simone Margaritelli Date: Thu, 8 Aug 2024 16:52:14 +0200 Subject: [PATCH] new: added github workflows (ref #1114) --- .github/workflows/main.yml | 116 +++++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 36 ++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..568a09b0 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,116 @@ +name: Build, Test and Deploy + +on: + push: + tags: + - 'v*.*.*' # Match version tags + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + go-version: ['1.22.x'] + include: + - os: ubuntu-latest + arch: amd64 + target_os: linux + target_arch: amd64 + - os: ubuntu-latest + arch: arm64 + target_os: linux + target_arch: aarch64 + - os: ubuntu-latest + arch: amd64 + target_os: linux + target_arch: armhf + cross_build: true + - os: macos-latest + arch: amd64 + target_os: darwin + target_arch: amd64 + - os: windows-latest + arch: amd64 + target_os: windows + target_arch: amd64 + output: bettercap.exe + + env: + TARGET_OS: ${{ matrix.target_os }} + TARGET_ARCH: ${{ matrix.target_arch }} + GO_VERSION: ${{ matrix.go-version }} + OUTPUT: ${{ matrix.output || 'bettercap' }} + + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - name: Install Dependencies + if: ${{ matrix.os == 'ubuntu-latest' }} + run: sudo apt-get update && sudo apt-get install -y p7zip-full libpcap-dev libnetfilter-queue-dev libusb-1.0-0-dev + + - name: Install Dependencies (macOS) + if: ${{ matrix.os == 'macos-latest' }} + run: brew install libpcap libusb p7zip + + - name: Install Dependencies (Windows) + if: ${{ matrix.os == 'windows-latest' }} + run: | + choco install openssl.light -y + choco install make -y + choco install 7zip -y + choco install pkgconfiglite -y + mkdir C:\pkg-config + choco install zadig -y + curl -L "https://github.com/libusb/libusb/releases/download/v1.0.24/libusb-1.0.24.7z" -o "C:\libusb.7z" + 7z x -y "C:\libusb.7z" -o"C:\libusb" + curl -L "https://www.winpcap.org/install/bin/WpdPack_4_1_2.zip" -o "C:\wpcap-sdk.zip" + 7z x -y "C:\wpcap-sdk.zip" -o"C:\winpcap" + copy builder\libusb.pc C:\pkg-config\libusb.pc + copy builder\libusb.pc C:\pkg-config\libusb-1.0.pc + + - name: Install QEMU for Cross Compilation (Linux only) + if: matrix.cross_build && matrix.os == 'ubuntu-latest' + run: | + wget --show-progress -qcO "qemu.deb" "https://github.com/bettercap/buildutils/raw/main/qemu-user-static_5.2_dfsg-9_amd64.deb" + sudo dpkg -i "qemu.deb" + + - name: Build + run: | + if [ -n "${{matrix.cross_build}}" ]; then + sudo builder/arm_builder.sh bettercap make -e TARGET="${{ env.OUTPUT }}" + else + make -e TARGET="${{ env.OUTPUT }}" + fi + + - name: Verify Build + run: | + file "${{ env.OUTPUT }}" + openssl dgst -sha256 "${{ env.OUTPUT }}" | tee bettercap_${{ matrix.target_os }}_${{ matrix.target_arch }}_${{ env.VERSION }}.sha256 + 7z a "bettercap_${{ matrix.target_os }}_${{ matrix.target_arch }}_${{ env.VERSION }}.zip" "${{ env.OUTPUT }}" "bettercap_${{ matrix.target_os }}_${{ matrix.target_arch }}_${{ env.VERSION }}.sha256" + ls -la bettercap* + + # Deployment is triggered on push of version tags and the files are already zipped and hashed during the build job. + deploy: + needs: [build] + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Upload Release Assets + uses: softprops/action-gh-release@v1 + with: + files: | + bettercap_*.zip + bettercap_*.sha256 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..fc5f2907 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: Build and Test + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + go-version: ['1.22.x'] + + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - name: Install Dependencies + if: ${{ matrix.os == 'ubuntu-latest' }} + run: sudo apt-get update && sudo apt-get install -y p7zip-full libpcap-dev libnetfilter-queue-dev libusb-1.0-0-dev + + - name: Install Dependencies (macOS) + if: ${{ matrix.os == 'macos-latest' }} + run: brew install libpcap libusb p7zip + + - name: Run Tests + run: | + env GO111MODULE=on make test \ No newline at end of file