Skip to content

Commit

Permalink
Add CI (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Dec 28, 2023
1 parent f06fe35 commit c0441bf
Show file tree
Hide file tree
Showing 21 changed files with 190 additions and 83 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Create release PR or publish GitHub release and Rust crate

permissions:
pull-requests: write
contents: write

on:
push:
branches: [main]

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: MarcoIeni/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
55 changes: 55 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI

on:
push:
branches: [main]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
build_and_test:
name: Build, check, and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: taiki-e/install-action@v2
with:
tool: cargo-hack,just
- uses: Swatinem/rust-cache@v2
- run: just build
- run: just check
#- run: just fmt --check
- run: just test
doc:
name: Build and publish docs
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/configure-pages@v3
- uses: dtolnay/rust-toolchain@nightly
- uses: taiki-e/install-action@v2
with:
tool: just
- uses: Swatinem/rust-cache@v2
- run: just doc
- uses: actions/upload-pages-artifact@v3
with:
path: target/doc
- uses: actions/deploy-pages@v4
if: github.ref_name == 'main'
id: deployment
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: detect-private-key
- id: check-merge-conflict
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"cwd": "${workspaceFolder}"
}
]
}
}
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"explorer.sortOrder": "mixed",
"restructuredtext.confPath": ""
}
"restructuredtext.confPath": "",
"rust-analyzer.check.features": "all",
"rust-analyzer.check.command": "clippy",
}
20 changes: 9 additions & 11 deletions document_tree/src/attribute_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ pub enum EnumeratedListType {
UpperRoman,
}

#[derive(Debug,PartialEq,Eq,Hash,Serialize,Clone)]
pub enum FixedSpace { Default, Preserve } // yes, default really is not “Default”
impl Default for FixedSpace { fn default() -> FixedSpace { FixedSpace::Preserve } }
#[derive(Default,Debug,PartialEq,Eq,Hash,Serialize,Clone)]
pub enum FixedSpace {
Default,
// yes, default really is not “Default”
#[default]
Preserve,
}

#[derive(Debug,PartialEq,Eq,Hash,Serialize,Clone)] pub enum AlignH { Left, Center, Right}
#[derive(Debug,PartialEq,Eq,Hash,Serialize,Clone)] pub enum AlignHV { Top, Middle, Bottom, Left, Center, Right }
Expand All @@ -32,12 +36,7 @@ impl Default for FixedSpace { fn default() -> FixedSpace { FixedSpace::Preserve
// The table DTD has the cols attribute of tgroup as required, but having
// TableGroupCols not implement Default would leave no possible implementation
// for TableGroup::with_children.
#[derive(Debug,PartialEq,Eq,Hash,Serialize,Clone)] pub struct TableGroupCols(pub usize);
impl Default for TableGroupCols {
fn default() -> Self {
TableGroupCols(0)
}
}
#[derive(Default,Debug,PartialEq,Eq,Hash,Serialize,Clone)] pub struct TableGroupCols(pub usize);

// no eq for f64
#[derive(Debug,PartialEq,Serialize,Clone)]
Expand Down Expand Up @@ -104,7 +103,7 @@ impl FromStr for Measure {
#[cfg(test)]
mod parse_tests {
use super::*;

#[test]
fn measure() {
let _a: Measure = "1.5em".parse().unwrap();
Expand Down Expand Up @@ -152,4 +151,3 @@ impl CanBeEmpty for bool {
impl CanBeEmpty for FixedSpace {
fn is_empty(&self) -> bool { self == &FixedSpace::default() }
}

24 changes: 12 additions & 12 deletions document_tree/src/element_categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ macro_rules! impl_into {
$( impl_into!($subcat::$entry => $supcat); )+
};
($subcat:ident :: $entry:ident => $supcat:ident ) => {
impl Into<$supcat> for $entry {
fn into(self) -> $supcat {
$supcat::$subcat(Box::new(self.into()))
impl From<$entry> for $supcat {
fn from(inner: $entry) -> Self {
$supcat::$subcat(Box::new(inner.into()))
}
}
};
Expand All @@ -47,18 +47,18 @@ macro_rules! synonymous_enum {
pub enum $name { $(
$entry(Box<$entry>),
)* }

impl Debug for $name {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
match *self {
$( $name::$entry(ref inner) => inner.fmt(fmt), )*
}
}
}
$( impl Into<$name> for $entry {
fn into(self) -> $name {
$name::$entry(Box::new(self))

$( impl From<$entry> for $name {
fn from(inner: $entry) -> Self {
$name::$entry(Box::new(inner))
}
} )*
};
Expand Down Expand Up @@ -106,22 +106,22 @@ synonymous_enum!(SubTableGroup { TableColspec, TableHead, TableBody });
mod conversion_tests {
use std::default::Default;
use super::*;

#[test]
fn basic() {
let _: BodyElement = Paragraph::default().into();
}

#[test]
fn more() {
let _: SubStructure = Paragraph::default().into();
}

#[test]
fn even_more() {
let _: StructuralSubElement = Paragraph::default().into();
}

#[test]
fn super_() {
let be: BodyElement = Paragraph::default().into();
Expand Down
42 changes: 21 additions & 21 deletions document_tree/src/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ macro_rules! impl_element { ($name:ident) => (
macro_rules! impl_children { ($name:ident, $childtype:ident) => (
impl HasChildren<$childtype> for $name {
#[allow(clippy::needless_update)]
fn with_children(children: Vec<$childtype>) -> $name { $name { children: children, ..Default::default() } }
fn with_children(children: Vec<$childtype>) -> $name { $name { children, ..Default::default() } }
fn children (& self) -> & Vec<$childtype> { & self.children }
fn children_mut(&mut self) -> &mut Vec<$childtype> { &mut self.children }
}
Expand All @@ -68,7 +68,7 @@ macro_rules! impl_children { ($name:ident, $childtype:ident) => (
macro_rules! impl_extra { ($name:ident $($more:tt)*) => (
impl ExtraAttributes<extra_attributes::$name> for $name {
#[allow(clippy::needless_update)]
fn with_extra(extra: extra_attributes::$name) -> $name { $name { common: Default::default(), extra: extra $($more)* } }
fn with_extra(extra: extra_attributes::$name) -> $name { $name { common: Default::default(), extra $($more)* } }
fn extra (& self) -> & extra_attributes::$name { & self.extra }
fn extra_mut(&mut self) -> &mut extra_attributes::$name { &mut self.extra }
}
Expand All @@ -82,7 +82,7 @@ impl<T, C, A> HasExtraAndChildren<C, A> for T where T: HasChildren<C> + ExtraAtt
#[allow(clippy::needless_update)]
fn with_extra_and_children(extra: A, mut children: Vec<C>) -> Self {
let mut r = Self::with_extra(extra);
r.children_mut().extend(children.drain(..));
r.children_mut().append(&mut children);
r
}
}
Expand All @@ -96,11 +96,11 @@ macro_rules! impl_new {(
) => (
$(#[$attr])*
#[derive(Debug,PartialEq,Serialize,Clone)]
pub struct $name { $(
pub struct $name { $(
$(#[$fattr])* $field: $typ,
)* }
impl $name {
pub fn new( $( $field: $typ, )* ) -> $name { $name { $( $field: $field, )* } }
pub fn new( $( $field: $typ, )* ) -> $name { $name { $( $field, )* } }
}
)}

Expand Down Expand Up @@ -156,14 +156,14 @@ impl_elems!(
(Section, StructuralSubElement)
(Topic, SubTopic)
(Sidebar, SubSidebar)

//structural subelements
(Title, TextOrInlineElement)
(Subtitle, TextOrInlineElement)
(Decoration, DecorationElement)
(Docinfo, BibliographicElement)
(Transition)

//bibliographic elements
(Author, TextOrInlineElement)
(Authors, AuthorInfo)
Expand All @@ -176,11 +176,11 @@ impl_elems!(
(Date, TextOrInlineElement)
(Copyright, TextOrInlineElement)
(Field, SubField)

//decoration elements
(Header, BodyElement)
(Footer, BodyElement)

//simple body elements
(Paragraph, TextOrInlineElement)
(LiteralBlock, TextOrInlineElement; +)
Expand All @@ -193,17 +193,17 @@ impl_elems!(
(Target; +)
(Raw, String; +)
(Image; *)

//compound body elements
(Compound, BodyElement)
(Container, BodyElement)

(BulletList, ListItem; +)
(EnumeratedList, ListItem; +)
(DefinitionList, DefinitionListItem)
(FieldList, Field)
(OptionList, OptionListItem)

(LineBlock, SubLineBlock)
(BlockQuote, SubBlockQuote)
(Admonition, SubTopic)
Expand All @@ -229,32 +229,32 @@ impl_elems!(
(TableRow, TableEntry; +)
(TableEntry, BodyElement; +)
(TableColspec; +)

//body sub elements
(ListItem, BodyElement)

(DefinitionListItem, SubDLItem)
(Term, TextOrInlineElement)
(Classifier, TextOrInlineElement)
(Definition, BodyElement)

(FieldName, TextOrInlineElement)
(FieldBody, BodyElement)

(OptionListItem, SubOptionListItem)
(OptionGroup, Option_)
(Description, BodyElement)
(Option_, SubOption)
(OptionString, String)
(OptionArgument, String; +)

(Line, TextOrInlineElement)
(Attribution, TextOrInlineElement)
(Label, TextOrInlineElement)

(Caption, TextOrInlineElement)
(Legend, BodyElement)

//inline elements
(Emphasis, TextOrInlineElement)
(Literal, String)
Expand All @@ -272,12 +272,12 @@ impl_elems!(
(Problematic, TextOrInlineElement; +)
(Generated, TextOrInlineElement)
(Math, String)

//also have non-inline versions. Inline image is no figure child, inline target has content
(TargetInline, String; +)
(RawInline, String; +)
(ImageInline; *)

//text element = String
);

Expand Down
6 changes: 4 additions & 2 deletions document_tree/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![recursion_limit="256"]

///http://docutils.sourceforge.net/docs/ref/doctree.html
///serves as AST
/// See [doctree][] reference.
/// Serves as AST.
///
/// [doctree]: http://docutils.sourceforge.net/docs/ref/doctree.html

#[macro_use]
mod macro_util;
Expand Down
2 changes: 1 addition & 1 deletion document_tree/src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Url {

impl From<url::Url> for Url {
fn from(url: url::Url) -> Self {
Url(url.into_string())
Url(url.into())
}
}

Expand Down
Loading

0 comments on commit c0441bf

Please sign in to comment.