mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Run PDF and SVG export in CI (#4097)
This commit is contained in:
parent
a7102f88dd
commit
3cc6e58eab
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -4,6 +4,7 @@ on: [push, pull_request, merge_group]
|
|||||||
env:
|
env:
|
||||||
RUSTFLAGS: "-Dwarnings"
|
RUSTFLAGS: "-Dwarnings"
|
||||||
RUSTDOCFLAGS: "-Dwarnings"
|
RUSTDOCFLAGS: "-Dwarnings"
|
||||||
|
TYPST_TESTS_EXTENDED: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# This allows us to have one branch protection rule for the full test matrix.
|
# This allows us to have one branch protection rule for the full test matrix.
|
||||||
|
@ -20,10 +20,16 @@ pub struct CliArguments {
|
|||||||
/// Does not affect the comparison or the reference image.
|
/// Does not affect the comparison or the reference image.
|
||||||
#[arg(short, long, default_value_t = 1.0)]
|
#[arg(short, long, default_value_t = 1.0)]
|
||||||
pub scale: f32,
|
pub scale: f32,
|
||||||
/// Exports PDF outputs into the artifact store.
|
/// Whether to run the tests in extended mode, including PDF and SVG
|
||||||
|
/// export.
|
||||||
|
///
|
||||||
|
/// This is used in CI.
|
||||||
|
#[arg(long, env = "TYPST_TESTS_EXTENDED")]
|
||||||
|
pub extended: bool,
|
||||||
|
/// Runs PDF export.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub pdf: bool,
|
pub pdf: bool,
|
||||||
/// Exports SVG outputs into the artifact store.
|
/// Runs SVG export.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub svg: bool,
|
pub svg: bool,
|
||||||
/// Whether to display the syntax tree.
|
/// Whether to display the syntax tree.
|
||||||
@ -37,6 +43,18 @@ pub struct CliArguments {
|
|||||||
pub num_threads: Option<usize>,
|
pub num_threads: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl CliArguments {
|
||||||
|
/// Whether to run PDF export.
|
||||||
|
pub fn pdf(&self) -> bool {
|
||||||
|
self.pdf || self.extended
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether to run SVG export.
|
||||||
|
pub fn svg(&self) -> bool {
|
||||||
|
self.svg || self.extended
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// What to do.
|
/// What to do.
|
||||||
#[derive(Debug, Clone, Subcommand)]
|
#[derive(Debug, Clone, Subcommand)]
|
||||||
#[command()]
|
#[command()]
|
||||||
|
@ -174,14 +174,14 @@ impl<'a> Runner<'a> {
|
|||||||
std::fs::write(&live_path, data).unwrap();
|
std::fs::write(&live_path, data).unwrap();
|
||||||
|
|
||||||
// Write PDF if requested.
|
// Write PDF if requested.
|
||||||
if crate::ARGS.pdf {
|
if crate::ARGS.pdf() {
|
||||||
let pdf_path = format!("{}/pdf/{}.pdf", crate::STORE_PATH, self.test.name);
|
let pdf_path = format!("{}/pdf/{}.pdf", crate::STORE_PATH, self.test.name);
|
||||||
let pdf = typst_pdf::pdf(document, Smart::Auto, None);
|
let pdf = typst_pdf::pdf(document, Smart::Auto, None);
|
||||||
std::fs::write(pdf_path, pdf).unwrap();
|
std::fs::write(pdf_path, pdf).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write SVG if requested.
|
// Write SVG if requested.
|
||||||
if crate::ARGS.svg {
|
if crate::ARGS.svg() {
|
||||||
let svg_path = format!("{}/svg/{}.svg", crate::STORE_PATH, self.test.name);
|
let svg_path = format!("{}/svg/{}.svg", crate::STORE_PATH, self.test.name);
|
||||||
let svg = typst_svg::svg_merged(document, Abs::pt(5.0));
|
let svg = typst_svg::svg_merged(document, Abs::pt(5.0));
|
||||||
std::fs::write(svg_path, svg).unwrap();
|
std::fs::write(svg_path, svg).unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user