name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., v0.1.0). This will create a new tag.'
required: true
type: string
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
asset_name: anytls_linux_x86_64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
asset_name: anytls_linux_aarch64
use_cross: true
- os: windows-latest
target: x86_64-pc-windows-msvc
asset_name: anytls_windows_x86_64
- os: macos-latest
target: x86_64-apple-darwin
asset_name: anytls_macos_x86_64
- os: macos-latest
target: aarch64-apple-darwin
asset_name: anytls_macos_aarch64
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
if: matrix.use_cross
run: cargo install cross
- name: Build client
run: |
if [ "${{ matrix.use_cross }}" = "true" ]; then
cross build --release --bin anytls-client --target ${{ matrix.target }}
else
cargo build --release --bin anytls-client --target ${{ matrix.target }}
fi
shell: bash
- name: Build server
run: |
if [ "${{ matrix.use_cross }}" = "true" ]; then
cross build --release --bin anytls-server --target ${{ matrix.target }}
else
cargo build --release --bin anytls-server --target ${{ matrix.target }}
fi
shell: bash
- name: Package binaries
run: |
mkdir -p dist
if [ "${{ matrix.os }}" = "windows-latest" ]; then
cp target/${{ matrix.target }}/release/anytls-client.exe dist/anytls-client.exe
cp target/${{ matrix.target }}/release/anytls-server.exe dist/anytls-server.exe
cd dist && 7z a -tzip ../${{ matrix.asset_name }}.zip *
else
cp target/${{ matrix.target }}/release/anytls-client dist/
cp target/${{ matrix.target }}/release/anytls-server dist/
cd dist && tar czf ../${{ matrix.asset_name }}.tar.gz *
fi
shell: bash
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: |
*.zip
*.tar.gz
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git User
run: |
git config user.name "GitHub Actions Bot"
git config user.email "actions@github.com"
- name: Create and Push Tag (Manual Dispatch)
if: github.event_name == 'workflow_dispatch'
run: |
echo "Creating and pushing tag ${{ github.event.inputs.version }}"
git tag ${{ github.event.inputs.version }}
git push origin ${{ github.event.inputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Set Release Version
id: set_version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
- name: Check for existing release
id: check_release
run: |
echo "Checking if release ${{ steps.set_version.outputs.version }} exists..."
status=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.set_version.outputs.version }})
if [ "$status" = "200" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
if: steps.check_release.outputs.exists == 'false'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.set_version.outputs.version }}
release_name: Release ${{ steps.set_version.outputs.version }}
draft: false
prerelease: false
- name: Upload Release Assets
run: |
for artifact_dir in artifacts/*; do
if [ -d "$artifact_dir" ]; then
for file_in_artifact_dir in "$artifact_dir"/*; do
if [ -f "$file_in_artifact_dir" ]; then
asset_filename=$(basename "$file_in_artifact_dir")
echo "Uploading $asset_filename from $file_in_artifact_dir to release ${{ steps.set_version.outputs.version }}"
gh release upload ${{ steps.set_version.outputs.version }} "$file_in_artifact_dir" --clobber
fi
done
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}