vproxy 2.5.5

A high-performance HTTP/HTTPS/SOCKS5 proxy server
name: CI

on:
  push:
    tags: ["v*"]
  pull_request:
  workflow_dispatch:

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@v5

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

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

      - name: Clippy check
        run: cargo clippy --all-targets

  tests:
    name: Tests
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        rust: [stable]

    steps:
      - uses: actions/checkout@v5

      - uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          override: true

      - name: Run tests
        run: cargo test

  build:
    name: Build
    runs-on: ubuntu-latest
    needs: ["style", "tests"]
    environment: Linux
    if: startsWith(github.ref, 'refs/tags/')
    container:
      image: ghcr.io/rust-cross/cargo-zigbuild:latest

    steps:
      - uses: actions/checkout@v5

      - 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 mingw-w64 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@v2
        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

  docker:
    name: Build Docker Image
    runs-on: ubuntu-latest
    needs: ["style", "tests"]
    if: startsWith(github.ref, 'refs/tags/')
    permissions:
      contents: read
      packages: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v5
        
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
        with:
          platforms: linux/amd64,linux/arm64
          
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
        
      - name: Log in to the Container registry
        if: startsWith(github.ref, 'refs/tags/')
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract metadata (tags, labels) for Docker
        if: startsWith(github.ref, 'refs/tags/')
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

      - name: Build and push Docker image
        if: startsWith(github.ref, 'refs/tags/')
        uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          platforms: linux/amd64,linux/arm64

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

      - 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