lazydns 0.2.63

A light and fast DNS server/forwarder implementation in Rust
Documentation
name: Release

on:
  push:
    tags:
      - "v*"

  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  release:
    name: Cross build for ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            exe: lazydns
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            exe: lazydns
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            exe: lazydns
          - os: ubuntu-latest
            target: aarch64-unknown-linux-musl
            exe: lazydns
          - os: ubuntu-latest
            target: i686-unknown-linux-musl
            exe: lazydns
          - os: ubuntu-latest
            target: arm-unknown-linux-musleabihf
            exe: lazydns
          - os: macos-latest
            target: x86_64-apple-darwin
            exe: lazydns
          - os: macos-latest
            target: aarch64-apple-darwin
            exe: lazydns
          - os: ubuntu-latest
            target: x86_64-unknown-freebsd
            exe: lazydns
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            exe: lazydns.exe
          - os: windows-latest
            target: i686-pc-windows-msvc
            exe: lazydns.exe
          - os: windows-latest
            target: aarch64-pc-windows-msvc
            exe: lazydns.exe
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          target: ${{ matrix.target }}

      - name: Install cross
        run: cargo install --version 0.2.5 cross

      - name: Install cross toolchain for aarch64
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
          echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
          echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV

      - name: Install cargo-deb (only for deb targets)
        if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'aarch64-unknown-linux-gnu'
        run: cargo install cargo-deb

      - name: Build release
        run: |
          cross build --profile minimal --target ${{ matrix.target }}
          cross build --profile full --all-features --target ${{ matrix.target }}

      - name: Generate deb for target
        # Generate .deb packages for Linux targets x86_64 and ARM64 only
        if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          cargo deb --no-build --profile full --target ${{ matrix.target }}

      - name: Run UPX (non-Windows)
        # UPX may not support some platforms; ignore errors
        if: matrix.os != 'windows-latest'
        continue-on-error: true
        uses: crazy-max/ghaction-upx@v1
        with:
          version: v5.0.2
          files: |
            target/${{ matrix.target }}/minimal/lazydns
            target/${{ matrix.target }}/full/lazydns
          args: -q --best --lzma

      - name: Run UPX (Windows)
        # Use .exe paths on Windows runners
        if: matrix.os == 'windows-latest'
        continue-on-error: true
        uses: crazy-max/ghaction-upx@v1
        with:
          version: v5.0.2
          files: |
            target\${{ matrix.target }}\minimal\lazydns.exe
            target\${{ matrix.target }}\full\lazydns.exe
          args: -q --best --lzma
      - name: Package release (non-Windows)
        if: matrix.os != 'windows-latest'
        shell: bash
        run: |
          set -euo pipefail
          TARGET=${{ matrix.target }}
          EXE="${{ matrix.exe }}"
          DIR=target/${{ matrix.target }}/minimal
          # Ensure the executable exists
          ls -lah "$DIR" || true
          # Create an unversioned archive matching installer expectations:
          # lazydns-<target>.tar.gz
          cp config.yaml LICENSE "$DIR"/
          tar czf "$DIR/lazydns-${TARGET}.tar.gz" -C "$DIR" lazydns config.yaml LICENSE

      - name: Package release (Windows)
        if: matrix.os == 'windows-latest'
        shell: pwsh
        run: |
          $TARGET = '${{ matrix.target }}'
          $EXE = 'lazydns.exe'
          $DIR = "target/${{ matrix.target }}/minimal"
          # Use ${} to avoid accidental variable-token parsing when followed by punctuation
          Write-Output "Files in ${DIR}`n"
          Get-ChildItem -Path $DIR | Write-Output
          # Copy config and license files
          Copy-Item -Path "config.yaml" -Destination "$DIR/"
          Copy-Item -Path "LICENSE" -Destination "$DIR/"
          # Create an unversioned zip matching installer expectations: lazydns-<target>.zip
          Compress-Archive -Path "$DIR/$EXE", "$DIR/config.yaml", "$DIR/LICENSE" -DestinationPath "$DIR/lazydns-$TARGET.zip" -Force

      - name: Package release (non-Windows, full)
        if: matrix.os != 'windows-latest'
        shell: bash
        run: |
          set -euo pipefail
          TARGET=${{ matrix.target }}
          EXE="${{ matrix.exe }}"
          DIR=target/${{ matrix.target }}/full
          # Ensure the executable exists
          ls -lah "$DIR" || true
          # Create an unversioned archive matching installer expectations:
          # lazydns-full-<target>.tar.gz
          cp config.yaml LICENSE "$DIR"/
          tar czf "$DIR/lazydns-full-${TARGET}.tar.gz" -C "$DIR" lazydns config.yaml LICENSE

      - name: Package release (Windows, full)
        if: matrix.os == 'windows-latest'
        shell: pwsh
        run: |
          $TARGET = '${{ matrix.target }}'
          $EXE = 'lazydns.exe'
          $DIR = "target/${{ matrix.target }}/full"
          # Use ${} to avoid accidental variable-token parsing when followed by punctuation
          Write-Output "Files in ${DIR}`n"
          Get-ChildItem -Path $DIR | Write-Output
          # Copy config and license files
          Copy-Item -Path "config.yaml" -Destination "$DIR/"
          Copy-Item -Path "LICENSE" -Destination "$DIR/"
          # Create an unversioned zip matching installer expectations: lazydns-full-<target>.zip
          Compress-Archive -Path "$DIR/$EXE", "$DIR/config.yaml", "$DIR/LICENSE" -DestinationPath "$DIR/lazydns-full-$TARGET.zip" -Force

      - name: Upload artifact (non-Windows)
        if: matrix.os != 'windows-latest'
        uses: actions/upload-artifact@v5
        with:
          name: lazydns-${{ matrix.target }}.tar.gz
          path: target/${{ matrix.target }}/minimal/lazydns-${{ matrix.target }}.tar.gz

      - name: Upload artifact (Windows)
        if: matrix.os == 'windows-latest'
        uses: actions/upload-artifact@v5
        with:
          name: lazydns-${{ matrix.target }}.zip
          path: target/${{ matrix.target }}/minimal/lazydns-${{ matrix.target }}.zip

      - name: Upload artifact (non-Windows, full)
        if: matrix.os != 'windows-latest'
        uses: actions/upload-artifact@v5
        with:
          name: lazydns-full-${{ matrix.target }}.tar.gz
          path: target/${{ matrix.target }}/full/lazydns-full-${{ matrix.target }}.tar.gz

      - name: Upload artifact (Windows, full)
        if: matrix.os == 'windows-latest'
        uses: actions/upload-artifact@v5
        with:
          name: lazydns-full-${{ matrix.target }}.zip
          path: target/${{ matrix.target }}/full/lazydns-full-${{ matrix.target }}.zip

      - name: Find deb artifacts
        run: |
          echo 'Listing created .deb artifacts:'
          find target -type f -name "*.deb" -print || true

      - name: Upload built .deb artifacts
        uses: actions/upload-artifact@v5
        with:
          name: lazydns-${{ matrix.target }}.deb
          path: |
            target/debian/*.deb

  publish:
    name: Publish release
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/')
    needs: [release]
    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v6
        with:
          path: artifacts
      - name: List artifacts
        run: |
          # List only release assets we intend to attach to the GitHub release
          find artifacts -type f \( -name "*.zip" -o -name "*.tar.gz" -o -name "*.deb" \) | sort
      - name: Create release
        uses: softprops/action-gh-release@v2
        with:
          # Support .zip, .tar.gz and .deb release artifacts
          files: |
            artifacts/**/*.{zip,tar.gz,deb}
          generate_release_notes: true
          draft: false

  publish-crate:
    name: Publish to crates.io
    if: startsWith(github.ref, 'refs/tags/')
    runs-on: ubuntu-latest
    needs: publish
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
      - name: Publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}
        run: cargo publish

  # Trigger Docker build/push workflow (reusable workflow)
  docker:
    name: Trigger Docker Build and Push
    needs: publish
    uses: ./.github/workflows/docker.yml
    with:
      LAZYDNS_VERSION: ${{ github.ref_name }}
    secrets:
      DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
      DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}