From 6329e497c38e4451be5837a3c238fe47745edb78 Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Fri, 12 Jul 2024 17:43:28 +0800 Subject: [PATCH] Create release and executables on pushing tags --- .github/workflows/ci.yml | 9 ++- .github/workflows/release.yml | 124 ++++++++++++++++++++++++++++++++++ Cross.toml | 5 ++ 3 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 Cross.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d2852b9..b0f4b886 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,9 +42,8 @@ jobs: targets: wasm32-unknown-unknown components: rust-src, clippy - - name: Install dependencies - run: | - sudo apt-get install protobuf-compiler + - name: Install Protoc + uses: arduino/setup-protoc@v3 - name: Run clippy run: | @@ -70,8 +69,8 @@ jobs: # key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} # restore-keys: ${{ runner.os }}-cargo- - - name: Install dependencies - run: sudo apt-get install protobuf-compiler + - name: Install Protoc + uses: arduino/setup-protoc@v3 # Buy some more disk space as we encountered the error `No space left on device`. - name: Free Disk Space (Ubuntu) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..4d263a0f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,124 @@ +name: Build Executables + +on: + push: + tags: + - '*' + +jobs: + + release: + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get version + id: get_version + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + + - name: Create Release + id: create_release + uses: softprops/action-gh-release@v2 + # Create release when pushing a tag. + if: startsWith(github.ref, 'refs/tags/') + with: + name: Release ${{ github.ref }} + tag_name: ${{ github.ref }} + # TODO: proper release content, now it's manually updated. + body: Release ${{ steps.get_version.outputs.VERSION }} + draft: true + prerelease: true + + publish: + name: Build ${{ matrix.build.target }} on ${{ matrix.build.os }} + runs-on: ${{ matrix.build.os }} + strategy: + matrix: + build: + - os: ubuntu-latest + os_prefix: ubuntu + target: aarch64-unknown-linux-gnu + artifact_name: subcoin + command: cross + + - os: ubuntu-latest + os_prefix: ubuntu + target: x86_64-unknown-linux-gnu + artifact_name: subcoin + command: cargo + + - os: macos-latest + os_prefix: macos + target: x86_64-apple-darwin + artifact_name: subcoin + command: cargo + + - os: macos-14 + os_prefix: macos + target: aarch64-apple-darwin + artifact_name: subcoin + command: cargo + + - os: windows-latest + os_prefix: windows + target: x86_64-pc-windows-msvc + artifact_name: subcoin.exe + command: cargo + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + targets: wasm32-unknown-unknown + components: rust-src, clippy + + - name: Install Protoc + uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + # The default clang on macOS does not have wasm32 support, install it on our own. + - name: Install LLVM and Clang (macOS) + uses: KyleMayes/install-llvm-action@v2 + with: + version: "15.0" + if: ${{ matrix.build.os == 'macos-latest' || matrix.build.os == 'macos-14' }} + + - name: Install target + run: | + rustup target add ${{ matrix.build.target }} + + - name: Install cross + run: | + cargo install cross --git https://github.com/cross-rs/cross + if: ${{ matrix.build.command == 'cross' }} + + - name: Configure cache + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-${{ matrix.build.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Build binary + run: | + ${{ matrix.build.command }} build --profile production --bin subcoin --locked --target ${{ matrix.build.target }} + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v1-release + if: startsWith(github.ref, 'refs/tags/') + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: target/${{ matrix.build.target }}/production/${{ matrix.build.artifact_name }} + asset_name: subcoin-${{ github.ref }}-${{ matrix.build.os_prefix }}-${{ matrix.build.target }} + tag: ${{ github.ref }} + overwrite: true diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 00000000..3d345a35 --- /dev/null +++ b/Cross.toml @@ -0,0 +1,5 @@ +[target.aarch64-unknown-linux-gnu] +# Required when cross building executables on ubuntu-latest. +pre-build = [ + "apt-get update && apt-get --assume-yes install protobuf-compiler clang" +]