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 31bf65d
Showing 1 changed file with 82 additions and 44 deletions.
126 changes: 82 additions & 44 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,94 @@ 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 artifacts
uses: actions/upload-artifact@v4
with:
name: meroctl_${{ matrix.target }}.tar.gz
path: meroctl_${{ matrix.target }}.tar.gz
name: artifacts-${{ matrix.target }}.tar.gz
path: artifacts/*
retention-days: 2

upload_branch_artifact:
release:
runs-on: ubuntu-latest
needs: build
needs: [define-matrix, build]
strategy:
matrix:
target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu]
if: ${{ github.ref != 'refs/heads/master' }}

binary: ${{ fromJSON(needs.define-matrix.outputs.binaries) }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: meroctl_${{ matrix.target }}.tar.gz
path: artifacts/
merge-multiple: true

- name: Sanitize ref name
id: sanitize
- name: Get version info
id: version_info
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
if [ "${GITHUB_REF}" == "refs/heads/master" ]; then
version=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "${{ matrix.binary }}") | .version')
if gh release view "v$VERSION" >/dev/null 2>&1; then
echo "Master release for this version already exists"
echo "release_required=false" >> $GITHUB_OUTPUT
else
echo "New master release required"
echo "release_required=true" >> $GITHUB_OUTPUT
fi
echo "prerelease=false" >> $GITHUB_ENV
echo "overwrite=false">> $GITHUB_ENV
echo "version=$version" >> $GITHUB_ENV
else
sanitized_ref="${GITHUB_REF#refs/heads/}"
echo "release_required=true" >> $GITHUB_ENV
echo "prerelease=true" >> $GITHUB_ENV
echo "overwrite=true">> $GITHUB_ENV
echo "version=${{ matrix.binary }}-$sanitized_ref" >> $GITHUB_ENV
fi
shell: bash

- name: Remove other binaries from artifacts
if: steps.version_info.outputs.release_required == 'true'
run: |
ls -al artifacts/
find artifacts/ -type f ! -name '${{ matrix.binary }}*' -exec rm {} +
ls -al artifacts/
- name: Upload binaries to release
if: steps.version_info.outputs.release_required == 'true'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: artifacts/*
file_glob: true
tag: ${{ steps.version_info.outputs.version }}
prerelease: ${{ steps.version_info.outputs.prerelease }}
overwrite: ${{ steps.version_info.outputs.overwrite }}

create_release:
runs-on: ubuntu-latest
Expand Down

0 comments on commit 31bf65d

Please sign in to comment.