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 +