From a3a04d67e4175181a871740ada20b0e90656af8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=A7=E6=A1=90?= <1058165620@qq.com> Date: Mon, 2 Dec 2024 09:57:52 +0800 Subject: [PATCH] =?UTF-8?q?ci(release):=20=E6=B7=BB=E5=8A=A0=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E4=BA=8C=E8=BF=9B=E5=88=B6=E6=96=87=E4=BB=B6=E5=92=8C?= =?UTF-8?q?=20Docker=20=E9=95=9C=E5=83=8F=E7=9A=84=20GitHub=20Actions=20?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81-=20=E5=88=9B=E5=BB=BA=20Release=20-?= =?UTF-8?q?=20=E6=9E=84=E5=BB=BA=E5=A4=9A=E5=B9=B3=E5=8F=B0=E4=BA=8C?= =?UTF-8?q?=E8=BF=9B=E5=88=B6=E6=96=87=E4=BB=B6=20-=20=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E4=BA=8C=E8=BF=9B=E5=88=B6=E6=96=87=E4=BB=B6=E5=88=B0=20GitHub?= =?UTF-8?q?=20Release=20-=20=E6=9E=84=E5=BB=BA=20Docker=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 126 ++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7447be7 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 +