Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implemented Workflow File #10

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
aa6b130
feat: workflow file
alenmestrov Oct 15, 2024
33ec4c8
fix: updated rules for triggering process
alenmestrov Oct 15, 2024
9189682
fix: bumped github action to v3
alenmestrov Oct 15, 2024
ff338e4
fix: switched to official workflow from Tauri documentation
alenmestrov Oct 16, 2024
cb820f7
fix: added installation for pnpm
alenmestrov Oct 16, 2024
8b5b782
fix: added missing dependecy for aarch64 linux
alenmestrov Oct 16, 2024
611c7d5
fix: changed setting up of autolaunch for linux platforms
alenmestrov Oct 16, 2024
3d085f8
fix: added missing dependecies for aarch64 linux build
alenmestrov Oct 16, 2024
60b6950
fix: added packages for cross-compilation
alenmestrov Oct 16, 2024
cda45b2
fix: implemented cross-compilation toolchain for aarch64 linux
alenmestrov Oct 16, 2024
1c14193
fix: added openssl config for linux deployment
alenmestrov Oct 16, 2024
230d26b
fix: removed unused packages
alenmestrov Oct 16, 2024
31ca2a0
fix: add openssl only for aarch64 linux build
alenmestrov Oct 16, 2024
f713637
fix: updated openssl configuration for aarch64
alenmestrov Oct 16, 2024
36c1afb
fix: removed non existing package
alenmestrov Oct 16, 2024
588c34e
fix: openssl config
alenmestrov Oct 16, 2024
2d5e025
fix: updated openssl config
alenmestrov Oct 16, 2024
c6c8597
fix: trying to configure correctly openssl
alenmestrov Oct 16, 2024
3db6969
fix: implemented zig for cross-compilation to aarch linux build
alenmestrov Oct 16, 2024
9ecb361
fix: added openssl-dev package for linux distribution
alenmestrov Oct 17, 2024
3e8e8da
fix: removed extra env vars
alenmestrov Oct 17, 2024
d74ad7f
fix: manually set openssl config variables for aarch64
alenmestrov Oct 17, 2024
c488ea7
fix: added missing dependecies for aarch64 linux
alenmestrov Oct 17, 2024
3465097
fix: removed aarch64 build from initial file, changed logic and creat…
alenmestrov Oct 19, 2024
59fb18b
fix: added correct triggers
alenmestrov Oct 19, 2024
093b6ff
fix: removed condition for node-ui
alenmestrov Oct 19, 2024
d7cf863
fix: updated workflow file for aarch64 linux build
alenmestrov Oct 22, 2024
50f7245
fix: enabled prod release
alenmestrov Oct 27, 2024
e9fdd1b
fix: fixed CI script and downloading of binaries
alenmestrov Dec 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: 'publish'

on:
workflow_dispatch:
push:
branches:
- master
pull_request:
types:
- closed

jobs:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- platform: 'macos-latest'
args: '--target aarch64-apple-darwin'
- platform: 'macos-latest'
args: '--target x86_64-apple-darwin'
- platform: 'ubuntu-22.04'
args: '--target x86_64-unknown-linux-gnu'

runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}

- name: Install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf

- name: Install frontend dependencies
run: pnpm install

- name: Get version
id: get_version
run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV

- name: Build Tauri app
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: app-v${{ env.VERSION }}
releaseName: 'App v${{ env.VERSION }}'
releaseBody: 'See the assets to download this version and install.'
releaseDraft: false # Change to true if you want to keep it as a draft
prerelease: false
args: ${{ matrix.args }}
73 changes: 73 additions & 0 deletions .github/workflows/build_aarch64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: AArch64 compile and build
on:
workflow_dispatch:
push:
branches:
- master # Explicitly set to master
pull_request:
types:
- closed

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pguyot/[email protected]
with:
base_image: https://dietpi.com/downloads/images/DietPi_RPi-ARMv8-Bullseye.img.xz
cpu: cortex-a53
bind_mount_repository: true
image_additional_mb: 10240
optimize_image: false
commands: |
# Rust complains (rightly) that $HOME doesn't match eid home
export HOME=/root
# Workaround to CI worker being stuck on Updating crates.io index
export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
# Install setup prerequisites
apt-get update -y --allow-releaseinfo-change
apt-get upgrade -y
apt-get autoremove -y
apt-get install curl
curl https://sh.rustup.rs -sSf | sh -s -- -y
. "$HOME/.cargo/env"
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash
# Install framework specific packages
apt-get install -y nodejs
# Use pnpm instead of npm
npm install -g pnpm
pnpm install next@latest react@latest react-dom@latest eslint-config-next@latest
# Install build tools and tauri-cli requirements
apt-get install -y libwebkit2gtk-4.0-dev build-essential wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev patchelf
cargo install tauri-cli --version 1.6.2
# Install frontend dependencies
pnpm install
# Build the application
cargo tauri build --target aarch64-unknown-linux-gnu --bundles deb,rpm

# Debug: Print current directory and list files
pwd
echo "=== Listing build artifacts ==="
find . -name "*.deb" -o -name "*.rpm"

- name: Get application name and version
id: get_info
run: |
cd src-tauri
APP_NAME=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].name')
APP_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')
echo "APP_NAME=$APP_NAME" >> $GITHUB_ENV
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV

- name: Upload deb bundle
uses: actions/upload-artifact@v3
with:
name: Debian Bundle
path: ${{ github.workspace }}/src-tauri/target/aarch64-unknown-linux-gnu/release/bundle/deb/calimero-node-manager_0.1.0_arm64.deb

- name: Upload rpm bundle
uses: actions/upload-artifact@v3
with:
name: RPM Bundle
path: ${{ github.workspace }}/src-tauri/target/aarch64-unknown-linux-gnu/release/bundle/rpm/calimero-node-manager-0.1.0-1.aarch64.rpm
10 changes: 6 additions & 4 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ tauri = { version = "1" }
flate2 = "1.0.34"
eyre = "0.6.12"
tar = "0.4.42"
reqwest = "0.12.8"
reqwest = { version = "0.12.8", features = ["json"] }
shared_utils = { path = "./shared_utils" }
serde_json = "1"
tokio = "1.42.0"

[dependencies]
auto-launch = "0.5.0"
Expand All @@ -32,6 +34,7 @@ flate2 = "1.0.34"
tar = "0.4.42"
reqwest = "0.12.8"
shared_utils = { path = "./shared_utils" }
anyhow = "1.0.94"

[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
Expand Down
65 changes: 63 additions & 2 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::io::BufReader;
use std::io::Read;
use std::path::Path;
use tar::Archive;
use std::time::Duration;

fn main() {
tauri::async_runtime::block_on(setup_binary()).unwrap();
Expand All @@ -17,14 +18,20 @@ fn main() {

async fn setup_binary() -> Result<()> {
let (os, arch, target) = determine_bin_data();
let binary_name = "meroctl";
let binary_name = "merod";
let cache_dir = std::env::temp_dir().join(binary_name);
std::fs::create_dir_all(&cache_dir).expect("Failed to create cache directory");

// Get the latest merod release tag
let latest_release = get_latest_merod_release().await?;

let url = format!(
"https://github.com/calimero-network/core/releases/latest/download/{}.tar.gz",
"https://github.com/calimero-network/core/releases/download/{}/{}.tar.gz",
latest_release,
target
);
println!("Downloading from URL: {}", url);

let cache_bin_path = cache_dir.join(format!("{}.tar.gz", binary_name));
let bin_dir = std::env::current_dir()?.join("bin").join(os).join(arch);
let resource_path = bin_dir.join(binary_name);
Expand Down Expand Up @@ -63,3 +70,57 @@ async fn download_and_extract(url: &str, cache_bin_path: &Path, bin_dir: &Path)

Ok(())
}

async fn get_latest_merod_release() -> Result<String> {
let client = reqwest::Client::new();
let github_token = std::env::var("GITHUB_TOKEN").ok();

// Maximum number of retries
let max_retries = 3;
let mut retry_count = 0;

loop {
let mut request = client
.get("https://api.github.com/repos/calimero-network/core/releases")
.header("User-Agent", "calimero-node-manager-build");

if let Some(token) = &github_token {
request = request.header("Authorization", format!("token {}", token));
}

let response = request.send().await?;

match response.status() {
status if status.is_success() => {
let releases: Vec<serde_json::Value> = response.json().await?;

if let Some(latest_merod) = releases.iter().find(|release| {
release["tag_name"]
.as_str()
.map_or(false, |tag| tag.starts_with("merod"))
}) {
if let Some(tag_name) = latest_merod["tag_name"].as_str() {
return Ok(tag_name.to_string());
}
}
bail!("No merod release found in the response");
},
status if status.as_u16() == 403 => {
if retry_count >= max_retries {
let error_text = response.text().await?;
bail!("GitHub API rate limit exceeded after {} retries: {}", max_retries, error_text);
}

// Exponential backoff: wait longer between each retry
let wait_time = Duration::from_secs(2u64.pow(retry_count as u32));
tokio::time::sleep(wait_time).await;
retry_count += 1;
continue;
},
status => {
let error_text = response.text().await?;
bail!("GitHub API error: {} - {}", status, error_text);
}
}
}
}
10 changes: 5 additions & 5 deletions src-tauri/shared_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn determine_bin_data() -> (String, String, String) {
let parts: Vec<&str> = target.split('-').collect();
let os = parts[2];
let arch = parts[0];
let binary_name = format!("meroctl_{}", target);
let binary_name = format!("merod_{}", target);
(os.to_string(), arch.to_string(), binary_name)
} else {
let os = match OS {
Expand All @@ -21,10 +21,10 @@ pub fn determine_bin_data() -> (String, String, String) {

pub fn map_os_arch_to_binary_name(os: &str, arch: &str) -> String {
match (os, arch) {
("windows", "x86_64") => "meroctl-x86_64-pc-windows-msvc",
("darwin", "x86_64") => "meroctl_x86_64-apple-darwin",
("darwin", "aarch64") => "meroctl_aarch64-apple-darwin",
("linux", "x86_64") => "meroctl_x86_64-unknown-linux-gnu",
("windows", "x86_64") => "merod-x86_64-pc-windows-msvc",
("darwin", "x86_64") => "merod_x86_64-apple-darwin",
("darwin", "aarch64") => "merod_aarch64-apple-darwin",
("linux", "x86_64") => "merod_x86_64-unknown-linux-gnu",
// Add more combinations as needed
_ => panic!("Unsupported OS/architecture combination: {}/{}", os, arch),
}
Expand Down
8 changes: 4 additions & 4 deletions src-tauri/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ pub fn get_binary_path(app_handle: &AppHandle) -> Result<PathBuf> {
.join("bin")
.join(os)
.join(arch)
.join("meroctl"))
.join("merod"))
} else {
let relative_path = format!("bin/{}/{}/meroctl", os, arch);
let relative_path = format!("bin/{}/{}/merod", os, arch);
app_handle
.path_resolver()
.resolve_resource(&relative_path)
Expand All @@ -60,7 +60,7 @@ pub fn is_node_process_running(app_handle: &AppHandle, node_name: &str) -> Resul
);

let pattern = format!(
r"meroctl.*--node-name\s+\b{}\b.*run",
r"merod.*--node-name\s+\b{}\b.*run",
regex_escape(node_name)
);
let re = Regex::new(&pattern).map_err(|e| eyre!("Failed to create regex: {}", e))?;
Expand Down Expand Up @@ -170,7 +170,7 @@ pub fn check_ports_availability(config: &NodeConfig) -> Result<()> {
// Kill the node process
pub fn kill_node_process(node_name: &str) -> std::io::Result<()> {
let output = Command::new("pkill")
.args(&["-f", &format!("meroctl.*--node-name {}.*run", node_name)])
.args(&["-f", &format!("merod.*--node-name {}.*run", node_name)])
.output()?;

if !output.status.success() {
Expand Down
10 changes: 9 additions & 1 deletion src-tauri/src/utils/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,15 @@ fn get_auto_launch(app: &AppHandle) -> Result<AutoLaunch, Box<dyn std::error::Er
.to_str()
.ok_or("Failed to convert executable path to string")?;

*auto_launch = Some(AutoLaunch::new(&app_name, app_path, true, &[] as &[&str]));
#[cfg(target_os = "linux")]
{
*auto_launch = Some(AutoLaunch::new(&app_name, app_path, &[] as &[&str]));
}

#[cfg(not(target_os = "linux"))]
{
*auto_launch = Some(AutoLaunch::new(&app_name, app_path, true, &[] as &[&str]));
}
}

Ok(auto_launch.as_ref().unwrap().clone())
Expand Down