From e0bebda70bc4dcb95d20e784b9ac460a817f9b6d Mon Sep 17 00:00:00 2001 From: Jorge Date: Thu, 29 Feb 2024 05:18:21 +0000 Subject: [PATCH] Added build --- .github/workflows/test.yaml | 34 +++++++++++++++++++++++++++++++++- src/bin/country.rs | 6 +++--- src/bin/period.rs | 9 ++++++--- src/bin/single_day.rs | 8 +++++--- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2ab76e1..5921cfc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,6 +1,10 @@ name: Test -on: [push, pull_request] +on: + release: + types: [created] + push: + pull_request: jobs: test: @@ -31,3 +35,31 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Run etl run: cargo run --features="build-binary" --bin etl_private_jets + + build-and-publish-binaries: + permissions: write-all + name: Publish binaries (${{ matrix.target }}) + needs: [run] + if: github.event_name == 'release' + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: x86_64-pc-windows-gnu + archive: zip + - target: x86_64-unknown-linux-musl + archive: tar.gz tar.xz tar.zst + - target: x86_64-apple-darwin + archive: zip + steps: + - uses: actions/checkout@v3 + - name: Compile and release + uses: rust-build/rust-build.action@v1.4.5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + RUSTTARGET: ${{ matrix.target }} + ARCHIVE_TYPES: ${{ matrix.archive }} + EXTRA_COMMAND_FLAGS: --features=build-binary + \ No newline at end of file diff --git a/src/bin/country.rs b/src/bin/country.rs index e05bd76..1e8baac 100644 --- a/src/bin/country.rs +++ b/src/bin/country.rs @@ -11,14 +11,14 @@ use flights::{ }; use time::Date; +static TEMPLATE: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/bin/country.md")); + fn render(context: &Context) -> Result<(), Box> { let path = format!("{}_story.md", context.country.name.to_lowercase()); - let template = std::fs::read_to_string("src/bin/country.md")?; - let mut tt = tinytemplate::TinyTemplate::new(); tt.set_default_formatter(&tinytemplate::format_unescaped); - tt.add_template("t", &template)?; + tt.add_template("t", TEMPLATE)?; let rendered = tt.render("t", context)?; diff --git a/src/bin/period.rs b/src/bin/period.rs index 4f41e4f..92786ad 100644 --- a/src/bin/period.rs +++ b/src/bin/period.rs @@ -21,14 +21,17 @@ pub struct Context { pub ratio_commercial_300km: String, } +static TEMPLATE: &str = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/src/bin/period_template.md" +)); + fn render(context: &Context) -> Result<(), Box> { let path = "story.md"; - let template = std::fs::read_to_string("src/bin/period_template.md")?; - let mut tt = tinytemplate::TinyTemplate::new(); tt.set_default_formatter(&tinytemplate::format_unescaped); - tt.add_template("t", &template)?; + tt.add_template("t", TEMPLATE)?; let rendered = tt.render("t", context)?; diff --git a/src/bin/single_day.rs b/src/bin/single_day.rs index 4930637..bc1b4bb 100644 --- a/src/bin/single_day.rs +++ b/src/bin/single_day.rs @@ -6,6 +6,10 @@ use tinytemplate::TinyTemplate; use flights::*; +static TEMPLATE: &str = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/src/bin/single_day_template.md" +)); static TEMPLATE_NAME: &'static str = "t"; #[derive(serde::Serialize, serde::Deserialize, Debug)] @@ -157,11 +161,9 @@ fn process_leg( dane_years, }; - let template = std::fs::read_to_string("src/bin/single_day_template.md")?; - let mut tt = TinyTemplate::new(); tt.set_default_formatter(&tinytemplate::format_unescaped); - tt.add_template(TEMPLATE_NAME, &template)?; + tt.add_template(TEMPLATE_NAME, TEMPLATE)?; let rendered = tt.render(TEMPLATE_NAME, &context)?;