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

fix cross compilation errors in integration tests #60

Merged
merged 18 commits into from
Jul 30, 2022
66 changes: 23 additions & 43 deletions .github/workflows/build_releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,45 @@ on:
workflow_call:

env:
CARGO_INCREMENTAL: 0
CARGO_PROFILE_DEV_DEBUG: 0
RUST_BACKTRACE: full

jobs:
build:
name: "Build binaries"
runs-on: ${{ matrix.info.os }}
build-release:
name: Build binaries
runs-on: ubuntu-latest
env:
RUST_BACKTRACE: 1
NATIVE_TARGET: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }}
strategy:
fail-fast: false
matrix:
info:
- {
os: "ubuntu-18.04",
target: "x86_64-unknown-linux-gnu",
cross: false,
}
- {
os: "ubuntu-18.04",
target: "armv7-unknown-linux-gnueabihf",
cross: true,
}
- {
os: "ubuntu-18.04",
target: "arm-unknown-linux-gnueabihf",
cross: true,
}
target: [x86_64-unknown-linux-gnu, armv7-unknown-linux-gnueabihf, arm-unknown-linux-gnueabihf]

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.info.target }}
- uses: dtolnay/rust-toolchain@stable

- name: Enable Rust cache
uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
with:
key: ${{ matrix.info.target }}
- uses: Swatinem/rust-cache@v2

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --verbose --locked --target=${{ matrix.info.target }}
use-cross: ${{ matrix.info.cross }}
- name: Set build binary
run: |
if ${NATIVE_TARGET} == true; then
echo "build_binary=cargo" >> $GITHUB_ENV
else
echo "build_binary=cross" >> $GITHUB_ENV
fi

- name: Build binary
run: ${{ env.build_binary }} build --release --verbose --locked --target ${{ matrix.target }}

- name: Build archive
shell: bash
run: |
cp target/${{ matrix.info.target }}/release/heliocron ./heliocron
tar -czvf "heliocron-${GITHUB_REF#refs/tags/}-${{ matrix.info.target }}.tar.gz" heliocron README.md LICENSE-APACHE LICENSE-MIT
echo "ASSET=heliocron-${GITHUB_REF#refs/tags/}-${{ matrix.info.target }}.tar.gz" >> $GITHUB_ENV
cp target/${{ matrix.target }}/release/heliocron ./heliocron
tar -czvf "heliocron-${GITHUB_REF#refs/tags/}-${{ matrix.target }}.tar.gz" heliocron README.md LICENSE-APACHE LICENSE-MIT
echo "ASSET=heliocron-${GITHUB_REF#refs/tags/}-${{ matrix.target }}.tar.gz" >> $GITHUB_ENV

- name: Create release directory for artifact, move file
- name: Create release directory for artifact
shell: bash
run: |
mkdir release
Expand Down
99 changes: 41 additions & 58 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,60 @@ on:
branches:
- master

# Cancel previous workflows if they are the same workflow on same ref (branch/tags)
# with the same event (push/pull_request) even they are in progress.
# This setting will help reduce the number of duplicated workflows.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

env:
CARGO_INCREMENTAL: 0
CARGO_PROFILE_DEV_DEBUG: 0
RUST_BACKTRACE: full

jobs:
# Runs rustfmt + tests + clippy
ci:
runs-on: ${{ matrix.triple.os }}
run_tests:
name: Run Rust tests
runs-on: ubuntu-latest
env:
NATIVE_TARGET: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }}
strategy:
fail-fast: false
matrix:
triple:
- {
os: "ubuntu-latest",
target: "x86_64-unknown-linux-gnu",
cross: false,
}
- {
os: "ubuntu-latest",
target: "armv7-unknown-linux-gnueabihf",
cross: true,
}
- {
os: "ubuntu-latest",
target: "arm-unknown-linux-gnueabihf",
cross: true,
}
target: [x86_64-unknown-linux-gnu, armv7-unknown-linux-gnueabihf, arm-unknown-linux-gnueabihf]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Set up Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
profile: minimal
target: ${{ matrix.triple.target }}
- uses: dtolnay/rust-toolchain@stable

- name: Enable Rust cache
uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross
if: env.NATIVE_TARGET == 'false'

- name: Check cargo fmt
run: cargo fmt --all -- --check
- uses: Swatinem/rust-cache@v2

- name: Build tests
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
uses: actions-rs/cargo@v1
with:
command: test
args: --no-run --locked
use-cross: ${{ matrix.triple.cross }}
env:
RUST_BACKTRACE: full
- name: Set test runner
run: |
if ${NATIVE_TARGET} == true; then
echo "test_runner=cargo" >> $GITHUB_ENV
else
echo "test_runner=cross" >> $GITHUB_ENV
fi

- name: Run tests
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
uses: actions-rs/cargo@v1
run: ${{ env.test_runner }} test --no-fail-fast --verbose --target ${{ matrix.target }} -- --nocapture

lint:
name: Check Rust code with rustfmt and clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: dtolnay/rust-toolchain@stable
with:
command: test
args: --no-fail-fast -- --nocapture --quiet
use-cross: ${{ matrix.triple.cross }}
env:
RUST_BACKTRACE: full
components: rustfmt, clippy

- name: Run rustfmt
run: cargo fmt --all -- --check

- name: Run clippy
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets -- -D warnings
use-cross: ${{ matrix.triple.cross }}
env:
RUST_BACKTRACE: full
run: cargo clippy --all-targets -- -D warnings
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal

- uses: dtolnay/rust-toolchain@stable

- name: Log in to crates.io
run: cargo login ${{ env.CRATES_IO_TOKEN }}
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [v0.8.0] - 2022-xx-xx
### Fixed
- More time zone errors... more tests added to prove correctness ([#53](https://github.com/mfreeborn/heliocron/issues/53)).
- Errors when running integration tests using `rust-cross` ([#58](https://github.com/mfreeborn/heliocron/issues/58))

### Changed
- Switched from pseudo-decimal degrees (e.g. "5.1N") to actual decimal degrees (e.g. 5.1) for coordinates ([#56](https://github.com/mfreeborn/heliocron/issues/56)).
- Refactored Github Actions workflows

## [v0.7.0] - 2022-06-12
### Fixed
Expand Down
51 changes: 37 additions & 14 deletions tests/test_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,42 @@ use assert_cmd::assert::Assert;
use assert_cmd::prelude::*;
use pretty_assertions::assert_eq;

fn find_runner() -> Option<String> {
for (key, value) in std::env::vars() {
if key.starts_with("CARGO_TARGET_") && key.ends_with("_RUNNER") && !value.is_empty() {
return Some(value);
}
}
None
}

fn get_base_command() -> Command {
let mut cmd;
let path = assert_cmd::cargo::cargo_bin("heliocron");
if let Some(runner) = find_runner() {
let mut runner = runner.split_whitespace();
cmd = Command::new(runner.next().unwrap());
for arg in runner {
cmd.arg(arg);
}
cmd.arg(path);
} else {
cmd = Command::new(path);
}
cmd
}

#[test]
fn test_plain_bin() {
// assert that running the binary with no flags doesn't simply fail
let mut cmd = Command::cargo_bin("heliocron").unwrap();
let mut cmd = get_base_command();
cmd.assert().code(2);
}

#[test]
fn test_help() {
// assert that a useful help message is given with the --help flag
let mut cmd = Command::cargo_bin("heliocron").unwrap();
let mut cmd = get_base_command();
let help = cmd.arg("--help").assert();

help.success()
Expand All @@ -27,7 +52,7 @@ fn test_help() {
#[test]
fn test_report_default_args() {
// assert that a report is successfully generated when no options are set
let mut cmd = Command::cargo_bin("heliocron").unwrap();
let mut cmd = get_base_command();
let report = cmd.arg("report").assert();

assert_report(report);
Expand All @@ -36,14 +61,14 @@ fn test_report_default_args() {
#[test]
fn test_report_custom_location() {
// assert that a report is successfully generated when an arbitrary location is given
let mut cmd = Command::cargo_bin("heliocron").unwrap();
let mut cmd = get_base_command();
let report_long = cmd
.args(&["--latitude", "51.0", "--longitude", "4.36", "report"])
.assert();

assert_report(report_long);

let mut cmd = Command::cargo_bin("heliocron").unwrap();
let mut cmd = get_base_command();
let report_short = cmd.args(&["-l", "51.0", "-o", "4.36", "report"]).assert();

assert_report(report_short)
Expand All @@ -52,7 +77,7 @@ fn test_report_custom_location() {
#[test]
fn test_report_custom_timezone() {
// assert that a report is successfully generated when an arbitrary time zone is given
let mut cmd = Command::cargo_bin("heliocron").unwrap();
let mut cmd = get_base_command();
let report_long = cmd
.args(&[
"--latitude",
Expand All @@ -67,7 +92,7 @@ fn test_report_custom_timezone() {

assert_report(report_long);

let mut cmd = Command::cargo_bin("heliocron").unwrap();
let mut cmd = get_base_command();
let report_short = cmd
.args(&[
"--latitude",
Expand All @@ -85,7 +110,7 @@ fn test_report_custom_timezone() {

#[test]
fn test_report_json_output() {
let mut cmd = Command::cargo_bin("heliocron").unwrap();
let mut cmd = get_base_command();

// parse the output into a Json Value
let json: serde_json::Value = serde_json::from_slice(
Expand Down Expand Up @@ -124,9 +149,8 @@ fn test_report_json_output() {
}

#[test]
fn test_correct_output() {
let output = Command::cargo_bin("heliocron")
.unwrap()
fn test_correct_output_small_offset() {
let output = get_base_command()
.args(&[
"--date",
"2022-07-29",
Expand Down Expand Up @@ -162,9 +186,8 @@ fn test_correct_output() {
}

#[test]
fn test_correct_output_nz() {
let output = Command::cargo_bin("heliocron")
.unwrap()
fn test_correct_output_large_pos_offset() {
let output = get_base_command()
.args(&[
"--date",
"2022-07-29",
Expand Down