-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(release): 添加发布二进制文件和 Docker 镜像的 GitHub Actions 工作流- 创建 Release
- 构建多平台二进制文件 - 上传二进制文件到 GitHub Release - 构建 Docker镜像
- Loading branch information
1 parent
2426147
commit a3a04d6
Showing
1 changed file
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|