Skip to content

Commit 804d0fb

Browse files
committed
Revert "codegen: Update ureq from 2 to 3"
This reverts commit bee06ee. See #831 (comment).
1 parent c92f25f commit 804d0fb

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ updates:
66
interval: daily
77
commit-message:
88
prefix: ''
9+
ignore:
10+
# https://github.com/taiki-e/install-action/pull/831#issuecomment-2650284580
11+
- dependency-name: ureq
912
labels: []
1013
- package-ecosystem: github-actions
1114
directory: /

tools/codegen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spdx = "0.10"
1818
tar = "0.4"
1919
toml_edit = { version = "0.22", default-features = false, features = ["parse", "serde"] }
2020
# TODO: call curl command instead of using ureq?
21-
ureq = { version = "3", features = ["json"] }
21+
ureq = { version = "2", features = ["json"] }
2222

2323
[lints]
2424
workspace = true

tools/codegen/src/main.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use install_action_internal_codegen::{
1919
};
2020
use sha2::{Digest as _, Sha256};
2121
use spdx::expression::{ExprNode, ExpressionReq, Operator};
22-
use ureq::http::header;
2322

2423
fn main() -> Result<()> {
2524
let args: Vec<_> = env::args().skip(1).collect();
@@ -53,7 +52,7 @@ fn main() -> Result<()> {
5352

5453
eprintln!("downloading metadata from https://api.github.com/repos/{repo}");
5554
let repo_info: github::RepoMetadata =
56-
download(&format!("https://api.github.com/repos/{repo}"))?.body_mut().read_json()?;
55+
download(&format!("https://api.github.com/repos/{repo}"))?.into_json()?;
5756

5857
eprintln!("downloading releases from https://api.github.com/repos/{repo}/releases");
5958
let mut releases: github::Releases = vec![];
@@ -64,8 +63,7 @@ fn main() -> Result<()> {
6463
let mut r: github::Releases = download(&format!(
6564
"https://api.github.com/repos/{repo}/releases?per_page={per_page}&page={page}"
6665
))?
67-
.body_mut()
68-
.read_json()?;
66+
.into_json()?;
6967
// If version_req is latest, it is usually sufficient to look at the latest 100 releases.
7068
if r.len() < per_page || version_req.is_some_and(|req| req == "latest") {
7169
releases.append(&mut r);
@@ -100,13 +98,11 @@ fn main() -> Result<()> {
10098
if let Some(crate_name) = &base_info.rust_crate {
10199
eprintln!("downloading crate info from https://crates.io/api/v1/crates/{crate_name}");
102100
let info = download(&format!("https://crates.io/api/v1/crates/{crate_name}"))?
103-
.body_mut()
104-
.read_json::<crates_io::Crate>()?;
101+
.into_json::<crates_io::Crate>()?;
105102
let latest_version = &info.versions[0].num;
106103
crates_io_version_detail = Some(
107104
download(&format!("https://crates.io/api/v1/crates/{crate_name}/{latest_version}"))?
108-
.body_mut()
109-
.read_json::<crates_io::VersionMetadata>()?
105+
.into_json::<crates_io::VersionMetadata>()?
110106
.version,
111107
);
112108

@@ -296,13 +292,8 @@ fn main() -> Result<()> {
296292
Path::new(&url).file_name().unwrap().to_str().unwrap()
297293
));
298294
let response = download(&url)?;
299-
let etag = response
300-
.headers()
301-
.get("etag")
302-
.expect("binary should have an etag")
303-
.to_str()
304-
.unwrap()
305-
.replace('\"', "");
295+
let etag =
296+
response.header("etag").expect("binary should have an etag").replace('\"', "");
306297

307298
if let Some(ManifestRef::Real(ref manifest)) = existing_manifest {
308299
if let Some(entry) = manifest.download_info.get(&platform) {
@@ -321,7 +312,7 @@ fn main() -> Result<()> {
321312
eprintln!("already downloaded");
322313
fs::File::open(download_cache)?.read_to_end(&mut buf)?; // Not buffered because it is read at once.
323314
} else {
324-
response.into_body().into_reader().read_to_end(&mut buf)?;
315+
response.into_reader().read_to_end(&mut buf)?;
325316
eprintln!("download complete");
326317
fs::write(download_cache, &buf)?;
327318
}
@@ -344,7 +335,7 @@ fn main() -> Result<()> {
344335
eprintln!("already downloaded");
345336
minisign_verify::Signature::from_file(sig_download_cache)?
346337
} else {
347-
let buf = download(&url)?.body_mut().read_to_string()?;
338+
let buf = download(&url)?.into_string()?;
348339
eprintln!("download complete");
349340
fs::write(sig_download_cache, &buf)?;
350341
minisign_verify::Signature::decode(&buf)?
@@ -362,7 +353,7 @@ fn main() -> Result<()> {
362353
if crate_download_cache.is_file() {
363354
eprintln!("already downloaded");
364355
} else {
365-
download(&url)?.into_body().into_reader().read_to_end(&mut buf2)?;
356+
download(&url)?.into_reader().read_to_end(&mut buf2)?;
366357
let hash = Sha256::digest(&buf2);
367358
if format!("{hash:x}") != v.checksum {
368359
bail!("checksum mismatch for {url}");
@@ -699,7 +690,7 @@ static GITHUB_TOKENS: LazyLock<GitHubTokens> = LazyLock::new(|| {
699690
}
700691
});
701692

702-
fn download(url: &str) -> Result<ureq::http::Response<ureq::Body>> {
693+
fn download(url: &str) -> Result<ureq::Response> {
703694
let mut token = GITHUB_TOKENS.get(url);
704695
let mut retry = 0;
705696
let mut retry_time = 0;
@@ -711,7 +702,7 @@ fn download(url: &str) -> Result<ureq::http::Response<ureq::Body>> {
711702
loop {
712703
let mut req = ureq::get(url);
713704
if let Some(token) = &token {
714-
req = req.header(header::AUTHORIZATION, &format!("Bearer {token}"));
705+
req = req.set("Authorization", &format!("Bearer {token}"));
715706
}
716707
match req.call() {
717708
Ok(res) => return Ok(res),
@@ -747,12 +738,12 @@ fn github_head(url: &str) -> Result<()> {
747738
loop {
748739
let mut req = ureq::head(url);
749740
if let Some(token) = &token {
750-
req = req.header(header::AUTHORIZATION, &format!("Bearer {token}"));
741+
req = req.set("Authorization", &format!("Bearer {token}"));
751742
}
752743
match req.call() {
753744
Ok(_) => return Ok(()),
754745
// rate limit
755-
Err(e @ ureq::Error::StatusCode(403)) => last_error = Some(e),
746+
Err(e @ ureq::Error::Status(403, _)) => last_error = Some(e),
756747
Err(e) => return Err(e.into()),
757748
}
758749
retry_time += 1;

0 commit comments

Comments
 (0)