Skip to content

Commit

Permalink
ci(release): 添加发布二进制文件和 Docker 镜像的 GitHub Actions 工作流- 创建 Release
Browse files Browse the repository at this point in the history
- 构建多平台二进制文件
- 上传二进制文件到 GitHub Release
- 构建 Docker镜像
  • Loading branch information
aide-cloud committed Dec 2, 2024
1 parent 2426147 commit a3a04d6
Showing 1 changed file with 126 additions and 0 deletions.
126 changes: 126 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Release

on:
push:
tags:
- 'v*'

env:
CARGO_TERM_COLOR: always
BINARY_NAME: moon-agent

jobs:
create-release:
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

build-release:
needs: create-release
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
# Windows
- os: windows-latest
target: x86_64-pc-windows-msvc
suffix: .exe
name: windows-amd64
- os: windows-latest
target: i686-pc-windows-msvc
suffix: .exe
name: windows-x86

# macOS
- os: macos-latest
target: x86_64-apple-darwin
suffix: ''
name: darwin-amd64
- os: macos-latest
target: aarch64-apple-darwin
suffix: ''
name: darwin-arm64

# Linux
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
suffix: ''
name: linux-amd64
- os: ubuntu-latest
target: i686-unknown-linux-gnu
suffix: ''
name: linux-x86
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
suffix: ''
name: linux-arm64

steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
override: true

- name: Install dependencies (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev gcc-multilib
- name: Build binary
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}

- name: Prepare asset
shell: bash
run: |
cd target/${{ matrix.target }}/release
asset_name="${{ env.BINARY_NAME }}-${{ matrix.name }}${{ matrix.suffix }}"
mv ${{ env.BINARY_NAME }}${{ matrix.suffix }} ${asset_name}
if [[ "${{ runner.os }}" == "Windows" ]]; then
7z a "${asset_name}.zip" "${asset_name}"
echo "ASSET=${asset_name}.zip" >> $GITHUB_ENV
else
tar czf "${asset_name}.tar.gz" "${asset_name}"
echo "ASSET=${asset_name}.tar.gz" >> $GITHUB_ENV
fi
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: target/${{ matrix.target }}/release/${{ env.ASSET }}
asset_name: ${{ env.ASSET }}
asset_content_type: application/octet-stream

build-docker:
needs: create-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

0 comments on commit a3a04d6

Please sign in to comment.