|
1 | 1 | use std::fs;
|
2 | 2 | use std::path::{Path, PathBuf};
|
3 | 3 |
|
4 |
| -use anyhow::{anyhow, Context as AnyhowContext, Error}; |
| 4 | +use anyhow::{anyhow, Error}; |
| 5 | +use curl::easy::Easy; |
5 | 6 | use serde::Deserialize;
|
6 | 7 |
|
7 | 8 | use crate::config::Channel;
|
| 9 | +use crate::curl_helper::BodyExt; |
8 | 10 | use crate::{run, Context};
|
9 | 11 |
|
10 | 12 | impl Context {
|
@@ -79,31 +81,57 @@ impl Context {
|
79 | 81 | }
|
80 | 82 |
|
81 | 83 | fn get_head_sha_for_rustup(&self) -> anyhow::Result<String> {
|
82 |
| - self.config |
83 |
| - .github() |
84 |
| - .context("failed to get HEAD SHA from GitHub - credentials not configured")? |
85 |
| - .token("rust-lang/rustup")? |
86 |
| - .get_ref("heads/stable") |
| 84 | + #[derive(Deserialize)] |
| 85 | + struct Commit { |
| 86 | + sha: String, |
| 87 | + } |
| 88 | + |
| 89 | + let url = format!( |
| 90 | + "https://api.github.com/repos/rust-lang/rustup/commits/{}", |
| 91 | + self.config.channel |
| 92 | + ); |
| 93 | + |
| 94 | + let mut client = Easy::new(); |
| 95 | + client.url(&url)?; |
| 96 | + client.useragent("rust-lang/promote-release")?; |
| 97 | + |
| 98 | + let commit: Commit = client.without_body().send_with_response()?; |
| 99 | + |
| 100 | + Ok(commit.sha) |
87 | 101 | }
|
88 | 102 |
|
89 | 103 | fn get_next_rustup_version(&self, sha: &str) -> anyhow::Result<String> {
|
90 | 104 | println!("Getting next Rustup version from Cargo.toml...");
|
91 | 105 |
|
92 |
| - #[derive(Debug, Deserialize)] |
| 106 | + #[derive(Deserialize)] |
| 107 | + struct Content { |
| 108 | + content: String, |
| 109 | + } |
| 110 | + |
| 111 | + #[derive(Deserialize)] |
93 | 112 | struct CargoToml {
|
| 113 | + package: Package, |
| 114 | + } |
| 115 | + |
| 116 | + #[derive(Deserialize)] |
| 117 | + struct Package { |
94 | 118 | version: String,
|
95 | 119 | }
|
96 | 120 |
|
97 |
| - let cargo_toml = self |
98 |
| - .config |
99 |
| - .github() |
100 |
| - .context("failed to get new rustup version from GitHub - credentials not configured")? |
101 |
| - .token("rust-lang/rustup")? |
102 |
| - .read_file(Some(sha), "Cargo.toml")?; |
| 121 | + let url = |
| 122 | + format!("https://api.github.com/repos/rust-lang/rustup/contents/Cargo.toml?ref={sha}"); |
| 123 | + |
| 124 | + let mut client = Easy::new(); |
| 125 | + client.url(&url)?; |
| 126 | + client.useragent("rust-lang/promote-release")?; |
| 127 | + |
| 128 | + let content: Content = client.without_body().send_with_response()?; |
| 129 | + let decoded_content = base64::decode(&content.content.replace('\n', ""))?; |
| 130 | + let cargo_toml = String::from_utf8(decoded_content)?; |
103 | 131 |
|
104 |
| - let toml: CargoToml = toml::from_str(&cargo_toml.content()?)?; |
| 132 | + let toml: CargoToml = toml::from_str(&cargo_toml)?; |
105 | 133 |
|
106 |
| - Ok(toml.version) |
| 134 | + Ok(toml.package.version) |
107 | 135 | }
|
108 | 136 |
|
109 | 137 | fn download_rustup_artifacts(&mut self, sha: &str) -> Result<PathBuf, Error> {
|
|
0 commit comments