Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions .github/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/bin/bash

: ${root=$(pwd)}
: ${tag=latest}
: ${os=linux}
: ${name=pingly}

# Function to print colored text based on log level
log() {
local level=$1
local message=$2
local NC='\033[0m' # Reset to default color

case "$level" in
"info")
echo -e "\033[0;32m[INFO] $message${NC}" # Green for INFO
;;
"warning")
echo -e "\033[0;33m[WARNING] $message${NC}" # Yellow for WARNING
;;
"error")
echo -e "\033[0;31m[ERROR] $message${NC}" # Red for ERROR
;;
*)
echo "$message" # Default to printing message without color for other levels
;;
esac
}

[ ! -d bin ] && mkdir bin

# Build support paltform target
# 1. Linux (force musl)
linux_target=(
"x86_64-unknown-linux-musl:mimalloc"
"aarch64-unknown-linux-musl:mimalloc"
"armv7-unknown-linux-musleabihf:jemalloc"
"arm-unknown-linux-musleabihf:jemalloc"
"i686-unknown-linux-musl:jemalloc"
)

# 2. MacOS
macos_target=(
"x86_64-apple-darwin"
"aarch64-apple-darwin"
)

# 3. Windows
windows_target=(
"x86_64-pc-windows-gnu"
"i686-pc-windows-gnu"
)

# Check linux rustup target installed
check_linux_rustup_target_installed() {
for target in ${linux_target[@]}; do
target=$(echo $target | cut -d':' -f1)
installed=$(rustup target list | grep "${target} (installed)")
if [ -z "$installed" ]; then
log "info" "Installing ${target}..."
rustup target add ${target}
fi
done
}

# Check macos rustup target installed
check_macos_rustup_target_installed() {
for target in ${macos_target[@]}; do
installed=$(rustup target list | grep "${target} (installed)")
if [ -z "$installed" ]; then
log "info" "Installing ${target}..."
rustup target add ${target}
fi
done
}

# Check windows rustup target installed
check_windows_rustup_target_installed() {
for target in ${windows_target[@]}; do
installed=$(rustup target list | grep "${target} (installed)")
if [ -z "$installed" ]; then
log "info" "Installing ${target}..."
rustup target add ${target}
fi
done
}

# Build linux target
build_linux_target() {
for target in "${linux_target[@]}"; do
build_target=$(echo $target | cut -d':' -f1)
feature=$(echo $target | cut -d':' -f2)
log "info" "Building ${target}..."
if cargo zigbuild --release --no-default-features --target "${build_target}" --features "${feature}"; then
compress_and_move $build_target
log "info" "Build ${target} done"
else
log "error" "Build ${target} failed"
exit 1
fi
done
}

# Build macos target
build_macos_target() {
for target in "${macos_target[@]}"; do
log "info" "Building ${target}..."
if CARGO_PROFILE_RELEASE_STRIP=none cargo zigbuild --release --no-default-features --target "${target}"; then
compress_and_move $target
log "info" "Build ${target} done"
else
log "error" "Build ${target} failed"
exit 1
fi
done
}

# Build windows target
build_windows_target() {
for target in "${windows_target[@]}"; do
log "info" "Building ${target}..."
if cargo build --release --no-default-features --target "${target}"; then
compress_and_move $target
log "info" "Build ${target} done"
else
log "error" "Build ${target} failed"
exit 1
fi
done
}

# upx and move target
compress_and_move() {
build_target=$1
target_dir="target/${build_target}/release"
bin_name=$name
if [[ $build_target == *windows* ]]; then
bin_name="${name}.exe"
fi
upx "${target_dir}/${bin_name}"
chmod +x "${target_dir}/${bin_name}"
cd "${target_dir}"
tar czvf $name-$tag-${build_target}.tar.gz $bin_name
shasum -a 256 $name-$tag-${build_target}.tar.gz >$name-$tag-${build_target}.tar.gz.sha256
mv $name-$tag-${build_target}.tar.gz $root/bin/
mv $name-$tag-${build_target}.tar.gz.sha256 $root/bin/
cd -
}

# Execute
if [ "$os" == "linux" ]; then
log "info" "Building linux target..."
check_linux_rustup_target_installed
build_linux_target
elif [ "$os" == "macos" ]; then
log "info" "Building macos target..."
check_macos_rustup_target_installed
build_macos_target
elif [ "$os" == "windows" ]; then
log "info" "Building windows target..."
check_windows_rustup_target_installed
build_windows_target
else
log "error" "Unsupported os: ${os}"
exit 1
fi
189 changes: 189 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
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@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

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 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@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: ["build"]
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3

- 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@v2
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@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
5 changes: 1 addition & 4 deletions src/server/tracker/inspector/tls/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,7 @@ impl ClientHello {
.extensions
.push(ClientHelloExtension::EcPointFormats {
value: extension_id,
data: formats
.iter()
.map(|f| ECPointFormat::from(*f))
.collect(),
data: formats.iter().map(|f| ECPointFormat::from(*f)).collect(),
});
}
TlsExtension::ALPN(protocols) => {
Expand Down
Loading