exocore 0.1.26

Distributed applications framework
Documentation
name: Release build

on:
  push:
    tags:
      - "v0.*"
      - "v1.*"

env:
  CARGO_TERM_COLOR: always

jobs:
  exo:
    strategy:
      fail-fast: true
      matrix:
        pair:
          - target: armv7-unknown-linux-gnueabihf
            os: ubuntu-latest
            bin: exo
            cross: true
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            bin: exo
            cross: true
          - target: aarch64-apple-darwin
            os: macos-14
            bin: exo
            cross: false

    runs-on: ${{ matrix.pair.os }}

    steps:
      - uses: actions/checkout@v4

      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          target: ${{ matrix.pair.target }}
          profile: minimal

      - name: Install Protoc
        uses: arduino/setup-protoc@v3
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Install master version of cross # TODO: Remove me once new cross is released
        run: |
          cargo install cross --locked --git https://github.com/cross-rs/cross

      - uses: actions-rs/cargo@v1.0.3
        with:
          use-cross: ${{ matrix.pair.cross }}
          command: build
          args: -p exo --profile production --target ${{ matrix.pair.target }}

      - name: Create binary
        run: |
          mkdir archive
          cp target/${{ matrix.pair.target }}/production/${{ matrix.pair.bin }} archive
          cd archive/
          tar -czf ../exo.${{ matrix.pair.target }}.tar.gz *

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.pair.target }}-artifact
          path: exo.${{ matrix.pair.target }}.tar.gz
          if-no-files-found: error

  web_client:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install build dependencies
        run: |
          sudo apt update
          sudo apt install -yq libssl-dev openssl protobuf-compiler

          curl -L https://github.com/rustwasm/wasm-pack/releases/download/v0.10.0/wasm-pack-v0.10.0-x86_64-unknown-linux-musl.tar.gz | tar zxf -
          mv wasm-pack*/wasm-pack .
          echo `pwd` >> $GITHUB_PATH

          sudo npm install -g yarn

      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          profile: minimal
          target: wasm32-unknown-unknown

      - name: Build client
        run: |
          yarn install
          yarn build
          yarn pack
          mv exocore-v*.tgz exocore-web.tar.gz

      - name: Upload build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: client-web-artifact
          path: exocore-web.tar.gz
          if-no-files-found: error

  ios_client:
    runs-on: macos-14 # See https://github.com/actions/virtual-environments/blob/main/images/macos for versions
    steps:
      - uses: actions/checkout@v4

      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          profile: minimal

      - name: Install dependencies
        run: |
          HOMEBREW_NO_INSTALL_CLEANUP=1 brew install swift-protobuf
          rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim # actions-rs doesn't support multiple targets: https://github.com/actions-rs/toolchain/issues/16
          cargo install cargo-lipo cbindgen --debug # make build faster, no need for speed from it

      - name: Build client & pod
        run: |
          cd $GITHUB_WORKSPACE/clients/ios
          ./tools/generate.sh
          ./tools/build.sh release

          cd $GITHUB_WORKSPACE
          mkdir archive
          mkdir -p archive/clients/
          cp -r clients/ios archive/clients/
          cp Exocore.podspec archive/
          cd archive/
          tar -czf $GITHUB_WORKSPACE/exocore-ios.tar.gz *

      - name: Upload build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: client-ios-artifact
          path: exocore-ios.tar.gz

  release:
    runs-on: ubuntu-latest
    needs: [exo, web_client, ios_client]
    steps:
      - uses: actions/checkout@v4

      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts

      - name: List artifacts
        run: |
          ls -R artifacts/**/*

      - name: Create release with artifacts
        run: |
          set -x

          assets=()
          for asset in ./artifacts/*/*.tar.gz; do
            assets+=("$asset")
          done

          TAG="${GITHUB_REF##*/}"
          echo "Creating release for tag $TAG"
          gh release create $TAG ${assets[@]}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}