Skip to content

update release.yml

update release.yml #6

Workflow file for this run

name: Build and Release
on:
push:
tags:
- 'v*' # 当推送的标签以 'v' 开头时触发
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, ubuntu-22.04]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y wget
wget https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0-linux-x86_64.tar.gz
tar -xvf cmake-3.20.0-linux-x86_64.tar.gz
sudo mv cmake-3.20.0-linux-x86_64 /opt/cmake-3.20.0.-linux-x86_64
sudo rm /usr/local/bin/cmake
sudo ln -s /opt/cmake-3.20.0.-linux-x86_64/bin/cmake /usr/local/bin/cmake
shell: bash
- name: Create build directory
run: mkdir -p build
shell: bash
- name: Configure CMake
run: cmake -DCMAKE_BUILD_TYPE=Release ..
working-directory: ./build
shell: bash
- name: Build project
run: cmake --build . --config Release
working-directory: ./build
shell: bash
- name: Package binaries and config
run: |
mkdir -p release/bin
cp ./config.yml release/
cp ./build/coro_socks release/bin/
tar -czvf coro_socks-${{ matrix.os }}.tar.gz -C release .
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: coro_socks-${{ matrix.os }}
path: |
socks_server-${{ matrix.os }}.tar.gz
release:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
draft: false
prerelease: false
- name: Upload release assets
run: |
# 遍历每个目录并找到打包好的文件
for dir in artifacts/*; do
if [[ -d "$dir" ]]; then
file=$(find "$dir" -type f \( -name "*.zip" -o -name "*.tar.gz" \))
if [[ -n "$file" ]]; then
name=$(basename "$file")
echo "Uploading $name..."
gh release upload ${{ github.ref_name }} "$file" --clobber
fi
fi
done
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}