dnsm 0.1.9

Toolkit for covert data exfiltration using DNS
Documentation
name: release-github

on:
  workflow_dispatch:
    inputs:
      version:
        description: "SemVer to build (e.g., 1.2.3). Leave empty to use Cargo.toml"
        required: false
        type: string
      create_release:
        description: "Also create a GitHub Release and publish to PyPI"
        required: false
        default: false
        type: boolean

permissions:
  contents: write
  id-token: write

jobs:
  # ── Native binaries (musl, static) ──
  build:
    name: build (${{ matrix.bin }} @ ${{ matrix.target }})
    runs-on: ubuntu-22.04
    strategy:
      fail-fast: false
      matrix:
        target: [x86_64-unknown-linux-musl, aarch64-unknown-linux-musl]
        bin: [dnsm-client, dnsm-server, dnsm-ws]

    env:
      CARGO_TERM_COLOR: always

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Rust (stable) and targets
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          target: ${{ matrix.target }}
          rustflags: ""

      - name: Setup Zig
        uses: mlugg/setup-zig@v1
        with:
          version: 0.12.0

      - name: Install cargo-zigbuild
        run: cargo install cargo-zigbuild --locked

      - name: Compute version
        shell: bash
        run: |
          set -euxo pipefail
          ver="${{ inputs.version }}"
          if [ -z "$ver" ]; then
            ver=$(sed -n 's/^version\s*=\s*"\([0-9]\+\.[0-9]\+\.[0-9]\+\)"/\1/p' Cargo.toml | head -n1)
          fi
          echo "TAG=v${ver}" >> "$GITHUB_ENV"
          echo "VERSION=$ver" >> "$GITHUB_ENV"

      - name: Verify Cargo.toml version matches tag/version
        shell: bash
        run: |
          set -euxo pipefail
          cargo_version=$(sed -n 's/^version\s*=\s*"\([0-9]\+\.[0-9]\+\.[0-9]\+\)"/\1/p' Cargo.toml | head -n1)
          if [ -z "$cargo_version" ]; then
            echo "Failed to parse version from Cargo.toml" >&2
            exit 1
          fi
          if [ "$cargo_version" != "$VERSION" ]; then
            echo "Tag ($VERSION) does not match Cargo.toml version ($cargo_version)" >&2
            exit 1
          fi

      - name: Build ${{ matrix.bin }} (musl, static)
        shell: bash
        env:
          BIN: ${{ matrix.bin }}
        run: |
          set -euxo pipefail
          case "$BIN" in
            dnsm-client) FEATURES="" ;;
            dnsm-server) FEATURES="sqlite" ;;
            dnsm-ws)     FEATURES="sqlite,ws-server" ;;
            *) echo "Unknown bin: $BIN" >&2; exit 1 ;;
          esac
          if [ -n "$FEATURES" ]; then
            cargo zigbuild --release --target ${{ matrix.target }} --bin "$BIN" --features "$FEATURES"
          else
            cargo zigbuild --release --target ${{ matrix.target }} --bin "$BIN"
          fi

      - name: Package artifacts
        shell: bash
        run: |
          set -euxo pipefail
          outdir="dist/${{ matrix.target }}"
          mkdir -p "$outdir"
          cp "target/${{ matrix.target }}/release/${{ matrix.bin }}" "$outdir/"
          strip -s "$outdir/${{ matrix.bin }}" || true
          tar_name="${{ matrix.bin }}-${VERSION}-${{ matrix.target }}.tar.gz"
          tar czf "$tar_name" -C "$outdir" "${{ matrix.bin }}"
          sha256sum "$tar_name" > "$tar_name.sha256"

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.bin }}-${{ matrix.target }}
          path: |
            ${{ matrix.bin }}-${{ env.VERSION }}-${{ matrix.target }}.tar.gz
            ${{ matrix.bin }}-${{ env.VERSION }}-${{ matrix.target }}.tar.gz.sha256

  # ── Python wheels ──
  build-wheels:
    name: wheel (${{ matrix.target }} / py${{ matrix.python }})
    runs-on: ubuntu-22.04
    strategy:
      fail-fast: false
      matrix:
        target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu]
        python: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]

    env:
      CARGO_TERM_COLOR: always

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python }}

      - name: Build wheel
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          manylinux: 2_17
          args: --release --no-default-features --features python -i python${{ matrix.python }} --zig
          sccache: false

      - name: Upload wheel
        uses: actions/upload-artifact@v4
        with:
          name: wheel-${{ matrix.target }}-py${{ matrix.python }}
          path: target/wheels/*.whl

  # ── Python sdist ──
  build-sdist:
    name: sdist
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.x"

      - name: Install maturin
        run: pip install maturin

      - name: Build sdist
        run: maturin sdist --out target/wheels

      - name: Upload sdist
        uses: actions/upload-artifact@v4
        with:
          name: sdist
          path: target/wheels/*.tar.gz

  # ── GitHub Release ──
  release:
    name: publish release
    needs: [build, build-wheels, build-sdist]
    runs-on: ubuntu-22.04
    if: inputs.create_release
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Compute version
        shell: bash
        run: |
          set -euxo pipefail
          ver="${{ inputs.version }}"
          if [ -z "$ver" ]; then
            ver=$(sed -n 's/^version\s*=\s*"\([0-9]\+\.[0-9]\+\.[0-9]\+\)"/\1/p' Cargo.toml | head -n1)
          fi
          echo "TAG=v${ver}" >> "$GITHUB_ENV"
          echo "VERSION=$ver" >> "$GITHUB_ENV"

      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: ./artifacts
          merge-multiple: true

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ env.TAG }}
          name: dnsm ${{ env.TAG }}
          draft: false
          prerelease: false
          generate_release_notes: true
          files: |
            artifacts/*.tar.gz
            artifacts/*.sha256
            artifacts/*.whl

  # ── PyPI publish ──
  publish-pypi:
    name: publish to PyPI
    needs: release
    runs-on: ubuntu-22.04
    permissions:
      id-token: write
    steps:
      - name: Download wheel and sdist artifacts
        uses: actions/download-artifact@v4
        with:
          path: dist
          pattern: "{wheel-*,sdist}"
          merge-multiple: true

      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          packages-dir: dist