From c02588dfc8d3e0c200f7c03a458b5a7214fb1fa0 Mon Sep 17 00:00:00 2001 From: Thong Nguyen Date: Fri, 17 Nov 2023 10:45:05 +0700 Subject: [PATCH] ci(fix): cross not pass env variables into build --- .github/workflows/ci.yml | 14 +------------- Cross.toml | 15 ++++++++++++++- src/test.rs | 2 +- src/util.rs | 13 ++++++------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee86cef..e54b504 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,18 +93,6 @@ jobs: - name: Build run: ${{ env.CARGO }} build --verbose ${{ env.TARGET_FLAGS }} - - name: Fix env - if: matrix.os == 'ubuntu-latest' - run: echo "FIX_HOME_DIR=/home/$USER" >> $GITHUB_ENV - - name: Run tests if: matrix.build != 'macos-arm' - shell: bash - run: | - if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then - mkdir -p $HOME/.config/shodan - echo "key" > $HOME/.config/shodan/api_key - cargo test -- --nocapture - else - ${{ env.CARGO }} test ${{ env.TARGET_FLAGS }} -- --nocapture - fi + run: ${{ env.CARGO }} test ${{ env.TARGET_FLAGS }} -- --nocapture diff --git a/Cross.toml b/Cross.toml index 0ed89c5..0631f34 100644 --- a/Cross.toml +++ b/Cross.toml @@ -2,4 +2,17 @@ image = "ghcr.io/thoongnv/aarch64-apple-darwin-cross:latest" [target.aarch64-pc-windows-msvc] -image = "ghcr.io/thoongnv/aarch64-pc-windows-msvc-cross:latest" \ No newline at end of file +image = "ghcr.io/thoongnv/aarch64-pc-windows-msvc-cross:latest" + +# Workaround for cross not passsing environment variables in CI ubuntu-latest image +[target.x86_64-unknown-linux-gnu.env] +passthrough = [ + "HOME", + "GITHUB_RUN_ID", +] + +[target.aarch64-unknown-linux-gnu.env] +passthrough = [ + "HOME", + "GITHUB_RUN_ID", +] \ No newline at end of file diff --git a/src/test.rs b/src/test.rs index b547a91..8f92d02 100644 --- a/src/test.rs +++ b/src/test.rs @@ -30,7 +30,7 @@ fn launch_app_and_make_few_searches() -> AppResult<()> { } // Only mock tests if running in Github CI - if env::var("GITHUB_RUN_ID").is_ok() || env::var("FIX_HOME_DIR").is_ok() { + if env::var("GITHUB_RUN_ID").is_ok() { // Create temp key file as we will mock API requests later if let Err(_) = util::get_api_key() { util::init_api_key("key".to_string(), false)?; diff --git a/src/util.rs b/src/util.rs index 9f0ba06..fa4cca7 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,6 +1,5 @@ use dirs; use serde_json::{json, Value}; -use std::env; use std::fs::{create_dir_all, metadata, set_permissions, File}; use std::io::prelude::*; use std::path::Path; @@ -10,10 +9,6 @@ pub fn get_config_dir() -> String { if let Some(home_dir) = dirs::home_dir() { let mut dir_str = home_dir.display().to_string(); - // Github CI on ubuntu-latest image has env variables incorrect set $HOME=/ - if env::var("FIX_HOME_DIR").is_ok() { - dir_str = env::var("FIX_HOME_DIR").unwrap(); - } if Path::new(&format!("{}/.shodan", dir_str)).is_dir() { home_dir_str = format!("{}/.shodan", dir_str); @@ -104,8 +99,12 @@ pub fn init_api_key(mut key: String, validate: bool) -> Result<(), std::io::Erro } }; } - Err(_) => { - println!("Error: Unable to create key directory ({})", config_dir); + Err(err) => { + println!( + "Error: Unable to create key directory ({}) {}", + config_dir, + err.to_string() + ); } }; } else {