From 0f3a84268fa389c91d1a5612b253bd33bdd55b3b Mon Sep 17 00:00:00 2001 From: Filip Bozic <70634661+fbozic@users.noreply.github.com> Date: Fri, 29 Nov 2024 11:35:58 +0100 Subject: [PATCH] ci: support multiple artifacts in node build --- .github/workflows/calimero_node_linux.yml | 122 +++++++++++++--------- 1 file changed, 73 insertions(+), 49 deletions(-) diff --git a/.github/workflows/calimero_node_linux.yml b/.github/workflows/calimero_node_linux.yml index 9b27c8238..f8f86a08c 100644 --- a/.github/workflows/calimero_node_linux.yml +++ b/.github/workflows/calimero_node_linux.yml @@ -1,48 +1,44 @@ -name: Build and Upload Meroctl for Linux +name: Binary build and release [Linux] on: push: branches: - - "**" + - '**' paths: - Cargo.toml - Cargo.lock - - "crates/**" + - 'crates/**' + - '.github/workflows/calimero_node_linux.yml' pull_request: types: [closed] jobs: + define-matrix: + runs-on: ubuntu-latest + outputs: + targets: ${{ steps.setup-matrix.outputs.targets }} + binaries: ${{ steps.setup-matrix.outputs.binaries }} + steps: + - name: Define Colors + id: setup-matrix + run: | + echo 'targets=["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu"]' >> "$GITHUB_OUTPUT" + echo 'binaries=["merod", "meroctl"]' >> "$GITHUB_OUTPUT" + build: runs-on: ubuntu-latest + needs: define-matrix strategy: matrix: - target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu] + target: ${{ fromJSON(needs.define-matrix.outputs.targets) }} outputs: - artifact_path: ${{ steps.compress.outputs.artifact_path }} - target: ${{ matrix.target }} version: ${{ steps.extract_version.outputs.version }} steps: - name: Checkout code uses: actions/checkout@v4 - # Install Node.js (version 20) and pnpm - - name: Set up Node.js - uses: actions/setup-node@v2 - with: - node-version: '20' - - - name: Install pnpm - run: npm install -g pnpm - - # Install and build node-ui - - name: Install node-ui dependencies with pnpm - run: pnpm install --prefix ./node-ui - - - name: Build node-ui - run: pnpm --filter ./node-ui run build - - name: Setup rust toolchain run: rustup toolchain install stable --profile minimal @@ -53,7 +49,7 @@ jobs: - name: Install target for ${{ matrix.target }} run: rustup target add ${{ matrix.target }} - + - name: Install dependencies for cross-compilation run: | sudo apt-get update @@ -109,12 +105,16 @@ jobs: PKG_CONFIG_ALLOW_CROSS: ${{ env.PKG_CONFIG_ALLOW_CROSS }} PKG_CONFIG_SYSROOT_DIR: ${{ env.PKG_CONFIG_SYSROOT_DIR }} OPENSSL_STATIC: ${{ env.OPENSSL_STATIC }} - RUSTFLAGS: "-C link-arg=-lstdc++ -C link-arg=-lpthread -C link-arg=-lc" - run: cargo zigbuild -p meroctl --release --target ${{ matrix.target }} - + RUSTFLAGS: '-C link-arg=-lstdc++ -C link-arg=-lpthread -C link-arg=-lc' + run: | + binaries=$(echo '${{ needs.define-matrix.outputs.binaries }}' | jq -r 'join(" ") | split(" ") | map("-p " + .) | join(" ")') + cargo zigbuild $binaries --release --target ${{ matrix.target }} + - name: Build meroctl for x86_64 if: matrix.target == 'x86_64-unknown-linux-gnu' - run: cargo build -p meroctl --release --target ${{ matrix.target }} + run: | + binaries=$(echo '${{ needs.define-matrix.outputs.binaries }}' | jq -r 'join(" ") | split(" ") | map("-p " + .) | join(" ")') + cargo build $binaries --release --target ${{ matrix.target }} - name: Extract version id: extract_version @@ -122,39 +122,63 @@ jobs: VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "meroctl") | .version') echo "version=$VERSION" >> $GITHUB_OUTPUT - - name: Compress artifact using gzip + - name: Compress artifacts using gzip id: compress run: | - tar -czf meroctl_${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release meroctl - echo "artifact_path=meroctl_${{ matrix.target }}.tar.gz" >> $GITHUB_OUTPUT - echo "target=${{ matrix.target }}" >> $GITHUB_OUTPUT + mkdir -p artifacts + tar -czf artifacts/meroctl_${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release meroctl + tar -czf artifacts/merod_${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release merod - - name: Upload Artifact + - name: Upload meroctl artifact uses: actions/upload-artifact@v4 with: name: meroctl_${{ matrix.target }}.tar.gz - path: meroctl_${{ matrix.target }}.tar.gz + path: artifacts/meroctl_${{ matrix.target }}.tar.gz retention-days: 2 - upload_branch_artifact: - runs-on: ubuntu-latest - needs: build - strategy: - matrix: - target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu] - if: ${{ github.ref != 'refs/heads/master' }} + - name: Upload merod artifact + uses: actions/upload-artifact@v4 + with: + name: merod_${{ matrix.target }}.tar.gz + path: artifacts/merod_${{ matrix.target }}.tar.gz + retention-days: 2 - steps: - - name: Download Artifact - uses: actions/download-artifact@v4 + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 with: - name: meroctl_${{ matrix.target }}.tar.gz + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: artifacts/* + file_glob: true + tag: ${{ github.ref }} + prerelease: true + overwrite: true - - name: Sanitize ref name - id: sanitize - run: | - sanitized_ref_name=$(echo "${GITHUB_REF_NAME}" | sed 's/[^a-zA-Z0-9_-]/-/g; s/^-*//; s/-*$//') - echo "sanitized_ref_name=${sanitized_ref_name}" >> $GITHUB_OUTPUT + # release: + # runs-on: ubuntu-latest + # needs: build + # strategy: + # matrix: + # binary: ${{ fromJSON(needs.define-matrix.outputs.binaries) }} + # steps: + # - name: Checkout code + # uses: actions/checkout@v4 + + # - name: Download Artifact + # uses: actions/download-artifact@v4 + # with: + # path: artifacts/ + # name: ${{ matrix.binary }}* + + # - name: Extract version + # id: extract_version + # run: | + # VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "meroctl") | .version') + # echo "version=$VERSION" >> $GITHUB_OUTPUT + + # - name: Debug + # id: debug + # run: | + # ls -al artifacts/ create_release: runs-on: ubuntu-latest