pingly 0.2.0

TLS and HTTP/1/2/3 fingerprint analysis server and Rust library
Documentation
name: CI

on:
  push:
    branches: ["main"]
    tags: ["v*"]
  pull_request:
  workflow_dispatch:
    inputs:
      docker_tag:
        description: Image tag for a manual Docker publish
        required: true
        default: latest
        type: string

concurrency:
  group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
  cancel-in-progress: true

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

permissions:
  contents: write
  packages: write

jobs:
  style:
    name: Style
    runs-on: ubuntu-latest
    environment: Linux

    steps:
      - uses: actions/checkout@v3

      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          components: clippy,rustfmt
          override: true

      - name: Style check
        run: cargo fmt --all -- --check

      - name: Clippy check
        run: |
          cargo clippy --all-targets -- -D warnings
          cargo clippy --all-targets --features server,mimalloc -- -D warnings
        
  build:
    name: Build
    runs-on: ubuntu-latest
    environment: Linux
    if: startsWith(github.ref, 'refs/tags/')
    needs: ["style"]
    container:
      image: ghcr.io/rust-cross/cargo-zigbuild:latest

    steps:
      - uses: actions/checkout@v3

      - name: Get tag
        if: startsWith(github.ref, 'refs/tags/')
        id: tag
        uses: dawidd6/action-get-tag@v1
        with:
          strip_v: true

      - name: Tag Check
        run: |
          echo "tag=${{ steps.tag.outputs.tag }}" >> $GITHUB_ENV
          echo "tag=${{ steps.tag.outputs.tag }}" >> $GITHUB_OUTPUT
          if [ -z "${{ steps.tag.outputs.tag }}" ]; then
            echo "tag=latest" >> $GITHUB_OUTPUT
            echo "tag=latest" >> $GITHUB_ENV
          fi
          
      - name: Install upx
        run: |
          wget https://github.com/upx/upx/releases/download/v4.2.1/upx-4.2.1-amd64_linux.tar.xz
          tar -xvf upx-4.2.1-amd64_linux.tar.xz
          mv upx-4.2.1-amd64_linux/upx /usr/bin/upx
          rm -rf upx-4.2.1-amd64_linux.tar.xz upx-4.2.1-amd64_linux
      
      - name: Install dependencies
        run: |
          apt-get update && apt-get install -y bison flex mingw-w64 nasm sudo

      - name: Setup Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true

      - name: Build Windows Target
        shell: bash
        run: |
          os=windows ./.github/build.sh

      - name: Build macOS Target
        run: |
          os=macos ./.github/build.sh

      - name: Build Linux Target
        run: |
          os=linux ./.github/build.sh
          
      - name: Upload binaries to GitHub Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          files: |
            bin/*
          prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
          generate_release_notes: true

  crates:
    name: Publish crates
    runs-on: ubuntu-latest
    environment: Linux
    needs: ["build"]
    if: startsWith(github.ref, 'refs/tags/')
    steps:
      - uses: actions/checkout@v3

      - name: Get tag
        if: startsWith(github.ref, 'refs/tags/')
        id: tag
        uses: dawidd6/action-get-tag@v1
        with:
          strip_v: true

      - name: Tag Check
        run: |
          echo "tag=${{ steps.tag.outputs.tag }}" >> $GITHUB_ENV
          echo "tag=${{ steps.tag.outputs.tag }}" >> $GITHUB_OUTPUT
          if [ -z "${{ steps.tag.outputs.tag }}" ]; then
            echo "tag=latest" >> $GITHUB_OUTPUT
            echo "tag=latest" >> $GITHUB_ENV
          fi

      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true

      - uses: katyo/publish-crates@v2
        if: startsWith(github.ref, 'refs/tags/')
        with:
          registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
          ignore-unpublished-changes: true

  docker:
    name: Build and push Docker image
    runs-on: ubuntu-latest
    needs: ["style"]
    if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
    permissions:
      contents: read
      packages: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6
        
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v4
        with:
          platforms: linux/amd64,linux/arm64
          
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v4
        
      - name: Log in to GitHub Container Registry
        uses: docker/login-action@v4
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v6
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
          flavor: latest=false
          tags: |
            type=raw,value=latest,enable=${{ github.event_name == 'push' && github.ref_name == github.event.repository.default_branch }}
            type=raw,value=${{ inputs.docker_tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
            type=semver,pattern={{version}}

      - name: Build and push Docker image
        uses: docker/build-push-action@v7
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          platforms: linux/amd64,linux/arm64
          pull: true
          cache-from: type=gha
          cache-to: type=gha,mode=max,ignore-error=true