Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
ci(fix): cross not pass env variables into build
Browse files Browse the repository at this point in the history
  • Loading branch information
thoongnv committed Nov 17, 2023
1 parent 577e8c8 commit c02588d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 14 additions & 1 deletion Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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",
]
2 changes: 1 addition & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
13 changes: 6 additions & 7 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c02588d

Please sign in to comment.