Skip to content

Commit

Permalink
ci: support multiple artifacts in node build
Browse files Browse the repository at this point in the history
  • Loading branch information
fbozic committed Nov 29, 2024
1 parent 93d8425 commit 0f3a842
Showing 1 changed file with 73 additions and 49 deletions.
122 changes: 73 additions & 49 deletions .github/workflows/calimero_node_linux.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down Expand Up @@ -109,52 +105,80 @@ 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
run: |
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
Expand Down

0 comments on commit 0f3a842

Please sign in to comment.