Skip to content

Commit

Permalink
chore: Update Rust workflow to build and test in release mode, create…
Browse files Browse the repository at this point in the history
… release, and upload release asset
  • Loading branch information
edgarburgues committed May 15, 2024
1 parent d7dbed6 commit 819f4a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
27 changes: 25 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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| {
Expand Down Expand Up @@ -66,7 +64,6 @@ fn transform_module_url(url: &str) -> Option<String> {
})
}

// Funciones relacionadas con la obtención de datos de los cursos y unidades
async fn fetch_course_data(url: &str) -> Result<Value, Box<dyn Error>> {
let response = reqwest::get(url).await?.text().await?;
let json: Value = serde_json::from_str(&response)?;
Expand Down Expand Up @@ -95,13 +92,11 @@ fn extract_units(json: &Value, locale: &str) -> Vec<(String, String)> {
.collect::<Vec<_>>()
}

// Función para obtener contenido HTML
async fn fetch_html(url: &str) -> Result<String, Box<dyn Error>> {
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<dyn Error>> {
let args: Vec<String> = env::args().collect();
Expand Down

0 comments on commit 819f4a3

Please sign in to comment.