From 819f4a34579472eee04e5c311b4bcb17d0a50f6d Mon Sep 17 00:00:00 2001 From: edgarburgues Date: Wed, 15 May 2024 18:12:34 +0200 Subject: [PATCH] chore: Update Rust workflow to build and test in release mode, create release, and upload release asset --- .github/workflows/rust.yml | 27 +++++++++++++++++++++++++-- src/main.rs | 5 ----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9fd45e0..31f35c0 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,7 +16,30 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable - name: Build - run: cargo build --verbose + run: cargo build --release --verbose - name: Run tests - run: cargo test --verbose + run: cargo test --release --verbose + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ github.run_number }} + release_name: Release ${{ github.run_number }} + draft: false + prerelease: false + - name: Upload Release Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./target/release/ml2pdf + asset_name: ml2pdf + asset_content_type: application/octet-stream diff --git a/src/main.rs b/src/main.rs index 835e855..849c681 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,6 @@ use std::io::Write; use std::path::Path; use std::env; -// Funciones relacionadas con el reemplazo de URLs locales en el contenido HTML fn replace_local_urls(html_content: &str) -> String { let css_re = Regex::new(r#"href="(/_themes/[^"]+)""#).unwrap(); let js_re = Regex::new(r#"src="(/_themes/[^"]+)""#).unwrap(); @@ -34,7 +33,6 @@ fn wrap_html(content: &str) -> String { ) } -// Funciones relacionadas con la conversión y extracción de URLs fn convert_course_url(url: &str) -> Option<(String, String)> { let re = Regex::new(r"https://learn\.microsoft\.com/([^/]+)/training/courses/([^/]+)").unwrap(); re.captures(url).map(|caps| { @@ -66,7 +64,6 @@ fn transform_module_url(url: &str) -> Option { }) } -// Funciones relacionadas con la obtención de datos de los cursos y unidades async fn fetch_course_data(url: &str) -> Result> { let response = reqwest::get(url).await?.text().await?; let json: Value = serde_json::from_str(&response)?; @@ -95,13 +92,11 @@ fn extract_units(json: &Value, locale: &str) -> Vec<(String, String)> { .collect::>() } -// Función para obtener contenido HTML async fn fetch_html(url: &str) -> Result> { let response = reqwest::get(url).await?.text().await?; Ok(replace_local_urls(&response)) } -// Función principal que coordina todo el proceso #[tokio::main] async fn main() -> Result<(), Box> { let args: Vec = env::args().collect();