-
Notifications
You must be signed in to change notification settings - Fork 10
Add nightly generator for reports website #9
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
base: main
Are you sure you want to change the base?
Changes from all commits
92f07ef
dff6186
7384304
11c32bd
62ecfea
e4f2963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Nightly Build of Reports Website | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 0 * * *' # Every night at midnight | ||
|
||
jobs: | ||
run: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Run generator | ||
env: | ||
REPORTS: https://github.com/Rust-GCC/reporting | ||
WEBSITE: .. | ||
run: | | ||
cd generator | ||
cargo run | ||
- name: Commit changes | ||
uses: EndBug/add-and-commit@v9 | ||
with: | ||
default_author: nightly_build_gha | ||
message: Nightly reports generation | ||
add: './_posts/*.md' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "generator" | ||
version = "0.1.0" | ||
edition = "2021" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing an |
||
|
||
[dependencies] | ||
clap = { version = "4.0.26", features = [ "derive", "env"] } | ||
git2 = "0.15.0" | ||
mktemp = "0.5.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
CloneFail(git2::Error), | ||
IO(std::io::Error), | ||
InvalidDatePrefix(PathBuf, String), | ||
NoDateInOrgReport(PathBuf), | ||
} | ||
|
||
impl From<git2::Error> for Error { | ||
fn from(error: git2::Error) -> Error { | ||
Error::CloneFail(error) | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for Error { | ||
fn from(error: std::io::Error) -> Error { | ||
Error::IO(error) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::Parser; | ||
|
||
mod error; | ||
mod reports; | ||
|
||
use error::Error; | ||
|
||
#[derive(Parser)] | ||
struct Cli { | ||
#[arg(short, long, env = "WEBSITE")] | ||
website: PathBuf, | ||
#[arg(short, long, env = "REPORTS")] | ||
reports: String, | ||
} | ||
|
||
fn main() -> Result<(), Error> { | ||
let cli = Cli::parse(); | ||
let reports_org_path = reports::clone(cli.reports)?; | ||
let reports_org_list = reports::find(reports_org_path)?; | ||
for report in reports_org_list { | ||
match reports::convert(report, &cli.website) { | ||
Ok(report_md) => {}, | ||
Err(e) => eprintln!("{:?}", e), | ||
}; | ||
} | ||
Comment on lines
+22
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should just display the monthly and yearly reports on the website. Otherwise, this would create too much noise. We can probably do a |
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::path::{Path, PathBuf}; | ||
use std::process::Command; | ||
|
||
use std::fs; | ||
|
||
use git2::Repository; | ||
use mktemp::Temp; | ||
|
||
use crate::error::Error; | ||
|
||
pub fn clone(reports_repo: String) -> Result<PathBuf, Error> { | ||
let path_to_repo = Temp::new_dir()?.to_path_buf(); | ||
Repository::clone(&reports_repo, &path_to_repo)?; | ||
Ok(path_to_repo) | ||
} | ||
|
||
pub fn find(reports_org_path: PathBuf) -> Result<Vec<PathBuf>, Error> { | ||
let mut results = Vec::new(); | ||
for entry in fs::read_dir(reports_org_path)? { | ||
let entry = entry?; | ||
let path = entry.path(); | ||
if let Some(Some("org")) = path.extension().map(|osstr| osstr.to_str()) { | ||
results.push(path); | ||
} | ||
} | ||
Ok(results) | ||
} | ||
|
||
fn get_date(report_org_path: &Path) -> Result<String, Error> { | ||
let content = fs::read_to_string(report_org_path)?; | ||
for line in content.lines() { | ||
if line.starts_with("#+date:") { | ||
let date = line | ||
.split(':') | ||
.nth(1) | ||
.ok_or(Error::InvalidDatePrefix(report_org_path.to_path_buf(), line.to_string()))? | ||
.trim() | ||
.to_string(); | ||
return Ok(date); | ||
} | ||
} | ||
Err(Error::NoDateInOrgReport(report_org_path.to_path_buf())) | ||
} | ||
|
||
pub fn convert(report_org_path: PathBuf, website: &Path) -> Result<PathBuf, Error> { | ||
let mut report_md_filename = get_date(&report_org_path)?; | ||
report_md_filename.push_str("-"); | ||
report_md_filename.push_str(report_org_path.file_name().unwrap().to_str().unwrap()); | ||
let mut report_md_path = website | ||
.join("_posts") | ||
.join(PathBuf::from(report_md_filename)); | ||
report_md_path.set_extension("md"); | ||
Command::new("pandoc") | ||
.arg("--from=org") | ||
.arg("--to=gfm") | ||
.arg(report_org_path) | ||
.arg("-o") | ||
.arg(&report_md_path) | ||
.spawn()?; | ||
dbg!(&report_md_path); | ||
Ok(report_md_path) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking, but if we're adding a Rust project we should also add Rust checks to the CI. So something that builds
generator
on PRs and checks for clippy warnings.i.e: https://github.com/Rust-GCC/bottleboard/blob/main/.github/workflows/check.yml or https://github.com/Rust-GCC/testing/blob/main/.github/workflows/build_check.yml