Skip to content

Commit 42646df

Browse files
committed
add support for perfile checksum files
1 parent c40f797 commit 42646df

7 files changed

Lines changed: 52 additions & 3 deletions

File tree

generator/src/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub struct Config {
2020
pub triples: IndexMap<Glob, Cat>,
2121
pub formats: IndexMap<Glob, Format>,
2222
pub checksums: HashMap<SumAlgo, ChecksumDetail>,
23+
#[serde(default)]
24+
pub perfile_checksums: IndexMap<Glob, SumAlgo>,
2325
pub maintainers: Vec<Maintainer>,
2426
}
2527

@@ -358,6 +360,13 @@ impl Config {
358360
Ok(app)
359361
}
360362

363+
pub fn match_perfile_checksum(&self, filename: &str) -> Option<(SumAlgo, &str)> {
364+
self.perfile_checksums
365+
.iter()
366+
.find(|(glob, _)| glob.compile_matcher().is_match(filename))
367+
.map(|(glob, algo)| (*algo, glob.glob().trim_start_matches('*')))
368+
}
369+
361370
pub fn match_format(&self, filename: &str) -> Result<&Format> {
362371
self.formats
363372
.iter()

generator/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ async fn main() -> Result<()> {
156156
context.try_insert("genver", &env!("CARGO_PKG_VERSION"))?;
157157
context.try_insert("meta", &meta)?;
158158
context.try_insert("tag", &app.tag(&meta.version)?)?;
159+
context.try_insert("has_checksum_files", &meta.downloads.iter().any(|d| !d.checksum_files.is_empty()))?;
159160
let page = tera.render("release.md", &context)?;
160161

161162
let dirpath = app.dir(&meta.version);

generator/src/meta.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ pub struct Download {
5656
pub format: Format,
5757
pub sums: Vec<DownloadSum>,
5858
pub cats: (String, String, Option<String>),
59+
#[serde(default)]
60+
pub checksum_files: Vec<DownloadChecksumFile>,
61+
}
62+
63+
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
64+
pub struct DownloadChecksumFile {
65+
pub algo: SumAlgo,
66+
pub url: Url,
5967
}
6068

6169
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -95,6 +103,7 @@ impl Download {
95103
format: config.match_format(&filename)?.clone(),
96104
sums: Vec::new(),
97105
cats: (os, arch, variant),
106+
checksum_files: Vec::new(),
98107
})
99108
}
100109
}

generator/src/release.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use semver::Version;
1111
use url::Url;
1212

1313
use crate::config::{App, Config, SumAlgo};
14-
use crate::meta::{Download, DownloadSum, Meta, Sign, SignedSum};
14+
use crate::meta::{Download, DownloadChecksumFile, DownloadSum, Meta, Sign, SignedSum};
1515

1616
pub async fn get_meta(config: Config, app: App, version: Version) -> Result<Meta> {
1717
let release = octocrab::instance()
@@ -22,6 +22,7 @@ pub async fn get_meta(config: Config, app: App, version: Version) -> Result<Meta
2222

2323
let mut downloads = Vec::new();
2424
let mut sums = Vec::new();
25+
let mut perfile_checksum_assets: Vec<(_, url::Url, String)> = Vec::new();
2526
'assets: for asset in &release.assets {
2627
let url = &asset.browser_download_url;
2728
let filename = url
@@ -36,6 +37,13 @@ pub async fn get_meta(config: Config, app: App, version: Version) -> Result<Meta
3637
}
3738
}
3839

40+
if let Some((algo, suffix)) = config.match_perfile_checksum(filename) {
41+
if let Some(base) = filename.strip_suffix(suffix) {
42+
perfile_checksum_assets.push((algo, url.clone(), base.to_string()));
43+
}
44+
continue 'assets;
45+
}
46+
3947
match Download::new(&config, url, filename, asset.size.try_into()?) {
4048
Ok(dl) => downloads.push(dl),
4149
Err(err) => eprintln!("warning: {}", err),
@@ -75,6 +83,17 @@ pub async fn get_meta(config: Config, app: App, version: Version) -> Result<Meta
7583
})
7684
.finish();
7785

86+
for (algo, url, base) in perfile_checksum_assets {
87+
for dl in &mut downloads {
88+
if dl.filename == base {
89+
dl.checksum_files.push(DownloadChecksumFile { algo, url: url.clone() });
90+
}
91+
}
92+
}
93+
for dl in &mut downloads {
94+
dl.checksum_files.sort();
95+
}
96+
7897
let http = HttpClientBuilder::new()
7998
.redirect_policy(RedirectPolicy::Follow)
8099
.build()?;

generator/templates/release.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Packages
88

9-
{{ tables::downloads(downloads=meta.downloads, sums=[]) }}
9+
{{ tables::downloads(downloads=meta.downloads, sums=[], has_checksum_files=has_checksum_files) }}
1010

1111
View release [on GitHub](https://github.com/{{ app.repo.owner }}/{{ app.repo.repo }}/releases/{{ tag }}).
1212

generator/templates/tables.md.j2

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{%- endif -%}
77
{% endmacro notes %}
88

9-
{% macro downloads(downloads, sums) %}
9+
{% macro downloads(downloads, sums, has_checksum_files=false) %}
1010
{%- set has_sums = 0 < sums | length -%}
1111
<table class="downloads">
1212
<thead>
@@ -16,6 +16,7 @@
1616
<th>Variant</th>
1717
<th>Download</th>
1818
{% if has_sums %}<th>BLAKE3 checksum</th>{% endif %}
19+
{% if has_checksum_files %}<th>Checksums</th>{% endif %}
1920
</tr>
2021
</thead>
2122
<tbody>
@@ -44,6 +45,11 @@
4445
{%- else -%}
4546
<em class="missing-checksum">missing checksum</em>
4647
{%- endif -%}
48+
</td>{% endif %}
49+
{% if has_checksum_files %}<td>
50+
{%- for cf in dl.checksum_files -%}
51+
<small><a href="{{ cf.url }}">{{ cf.algo }}</a></small>{% if not loop.last %} {% endif %}
52+
{%- endfor -%}
4753
</td>{% endif %}
4854
</tr>
4955
{% endfor %}

generators.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ checksums:
101101
tool: sha512sum
102102
url: https://en.wikipedia.org/wiki/SHA-2
103103

104+
perfile_checksums:
105+
"*.b3": BLAKE3
106+
"*.sha256": SHA256
107+
"*.sha512": SHA512
108+
104109
maintainers:
105110
- username: passcod
106111
name: Félix

0 commit comments

Comments
 (0)