Skip to content

remove todo

remove todo #64

name: Build and Upload Binary
on:
push:
branches:
- '**'
pull_request:
types: [closed]
jobs:
build:
runs-on: macos-latest
strategy:
matrix:
target: [x86_64-apple-darwin, aarch64-apple-darwin]
outputs:
artifact_path: ${{ steps.compress.outputs.artifact_path }}
target: ${{ matrix.target }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup rust toolchain
run: rustup toolchain install stable --profile minimal
- name: Setup rust cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-calimero-node-${{ matrix.target }}
- name: Install target for ${{ matrix.target }}
run: rustup target add ${{ matrix.target }}
- name: Build the crate
run: cargo build -p calimero-node --release --target ${{ matrix.target }}
- name: Compress artifact using gzip
id: compress
run: |
tar -czf calimero-node_${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release calimero-node
echo "artifact_path=calimero-node_${{ matrix.target }}.tar.gz" >> $GITHUB_OUTPUT
echo "target=${{ matrix.target }}" >> $GITHUB_OUTPUT
- name: Cache build artifact
uses: actions/cache@v4
with:
path: calimero-node_${{ matrix.target }}.tar.gz
key: build-artifact-${{ matrix.target }}-${{ github.sha }}
restore-keys: |
build-artifact-${{ matrix.target }}
upload_branch_artifact:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
target: [x86_64-apple-darwin, aarch64-apple-darwin]
if: ${{ github.ref != 'refs/heads/master' }}
steps:
- name: Restore build artifact
uses: actions/cache@v4
with:
path: calimero-node_${{ matrix.target }}.tar.gz
key: build-artifact-${{ matrix.target }}-${{ github.sha }}
restore-keys: |
build-artifact-${{ matrix.target }}
- name: Upload binary as artifact
uses: actions/upload-artifact@v4
with:
name: calimero-node_${{ github.ref_name }}_${{ matrix.target }}.tar.gz
path: calimero-node_${{ matrix.target }}.tar.gz
retention-days: 2
release:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
target: [x86_64-apple-darwin, aarch64-apple-darwin]
if: ${{ github.ref == 'refs/heads/master' || (github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'master') }}
steps:
- name: Restore build artifact
uses: actions/cache@v4
with:
path: calimero-node_${{ matrix.target }}.tar.gz
key: build-artifact-${{ matrix.target }}-${{ github.sha }}
restore-keys: |
build-artifact-${{ matrix.target }}
- name: Check if release exists
id: check_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | awk -F\" '{print $2}')
RELEASE_URL=$(curl --silent "https://api.github.com/repos/${{ github.repository }}/releases/tags/v$VERSION" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" | jq -r '.url')
if [[ "$RELEASE_URL" != "null" ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create Release
if: steps.check_release.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | awk -F\" '{print $2}')
gh release create "v${{ steps.check_release.outputs.version }}" --title "Release v${{ steps.check_release.outputs.version }}" --notes "Release for version ${{ steps.check_release.outputs.version }}"
- name: Upload artifact to release
if: steps.check_release.outputs.exists == 'false'
run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | awk -F\" '{print $2}')
gh release upload "v$VERSION" calimero-node_${{ matrix.target }}.tar.gz