File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ //! Check the CITATION.cff file
2+ use anyhow:: { Context , Result } ;
3+ use std:: fs;
4+ use yaml_rust2:: { Yaml , YamlLoader } ;
5+
6+ fn get_version_from_citation_cff ( ) -> Result < String > {
7+ let citation = fs:: read_to_string ( "CITATION.cff" ) ?;
8+ let yaml = YamlLoader :: load_from_str ( & citation) ?;
9+ let yaml = yaml
10+ . iter ( )
11+ . next ( )
12+ . context ( "Empty YAML file" ) ?
13+ . as_hash ( )
14+ . context ( "Not YAML object" ) ?;
15+ let version = yaml
16+ . get ( & Yaml :: from_str ( "version" ) )
17+ . context ( "version key not found" ) ?
18+ . as_str ( )
19+ . context ( "version should be string" ) ?;
20+
21+ Ok ( version. to_string ( ) )
22+ }
23+
24+ #[ test]
25+ fn test_citation_cff_version ( ) {
26+ assert_eq ! (
27+ env!( "CARGO_PKG_VERSION" ) ,
28+ get_version_from_citation_cff( ) . unwrap( ) ,
29+ "Software version in Cargo.toml and CITATION.cff must match. If you are making a new \
30+ release, please also update the CITATION.cff file."
31+ )
32+ }
You can’t perform that action at this time.
0 commit comments