Allow running the manager without a token
This is useful for local testing.
This commit is contained in:
parent
96bb2540ba
commit
d4b8241808
|
@ -20,7 +20,7 @@ pub struct Context {
|
||||||
/// URL of the repository page
|
/// URL of the repository page
|
||||||
pub repo_url: url::Url,
|
pub repo_url: url::Url,
|
||||||
/// URL of the repository with authentication information attached
|
/// URL of the repository with authentication information attached
|
||||||
pub repo_auth_url: url::Url,
|
pub repo_auth_url: Option<url::Url>,
|
||||||
/// Human readable timestamp of this manager run
|
/// Human readable timestamp of this manager run
|
||||||
pub timestamp: String,
|
pub timestamp: String,
|
||||||
}
|
}
|
||||||
|
@ -42,13 +42,15 @@ async fn run() -> anyhow::Result<()> {
|
||||||
let timestamp = chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string();
|
let timestamp = chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string();
|
||||||
log::info!("Timestamp of this run is {timestamp}");
|
log::info!("Timestamp of this run is {timestamp}");
|
||||||
|
|
||||||
let token =
|
let token = std::env::var("GITHUB_TOKEN").ok();
|
||||||
std::env::var("GITHUB_TOKEN").context("Failed accessing GITHUB_TOKEN auth token")?;
|
if token.is_none() {
|
||||||
|
log::warn!("No GITHUB_TOKEN, only performing read-only operations!");
|
||||||
|
}
|
||||||
|
|
||||||
let server_url = url::Url::parse(
|
let server_url = url::Url::parse(&std::env::var("GITHUB_SERVER_URL").unwrap_or_else(|_e| {
|
||||||
&std::env::var("GITHUB_SERVER_URL")
|
log::warn!("Using FAFO URL as a default GITHUB_SERVER_URL!");
|
||||||
.context("Failed reading GITHUB_SERVER_URL server url")?,
|
"https://git.fa-fo.de".to_string()
|
||||||
)
|
}))
|
||||||
.context("Failed parsing GITHUB_SERVER_URL as a url")?;
|
.context("Failed parsing GITHUB_SERVER_URL as a url")?;
|
||||||
|
|
||||||
let repo_url = server_url
|
let repo_url = server_url
|
||||||
|
@ -57,11 +59,19 @@ async fn run() -> anyhow::Result<()> {
|
||||||
meta.issue.repository.owner, meta.issue.repository.name
|
meta.issue.repository.owner, meta.issue.repository.name
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut repo_auth_url = repo_url.clone();
|
|
||||||
repo_auth_url.set_username("forgejo-actions").unwrap();
|
|
||||||
repo_auth_url.set_password(Some(&token)).unwrap();
|
|
||||||
|
|
||||||
let auth = forgejo_api::Auth::Token(&token);
|
let repo_auth_url = token.as_ref().map(|token| {
|
||||||
|
let mut repo_auth_url = repo_url.clone();
|
||||||
|
repo_auth_url.set_username("forgejo-actions").unwrap();
|
||||||
|
repo_auth_url.set_password(Some(&token)).unwrap();
|
||||||
|
repo_auth_url
|
||||||
|
});
|
||||||
|
|
||||||
|
let auth = if let Some(token) = token.as_ref() {
|
||||||
|
forgejo_api::Auth::Token(token)
|
||||||
|
} else {
|
||||||
|
forgejo_api::Auth::None
|
||||||
|
};
|
||||||
let forgejo =
|
let forgejo =
|
||||||
Forgejo::new(auth, server_url).context("Could not create Forgejo API access object")?;
|
Forgejo::new(auth, server_url).context("Could not create Forgejo API access object")?;
|
||||||
|
|
||||||
|
@ -103,9 +113,14 @@ async fn run() -> anyhow::Result<()> {
|
||||||
let rendered_tree = render::render(&ctx, &tree)
|
let rendered_tree = render::render(&ctx, &tree)
|
||||||
.await
|
.await
|
||||||
.context("Failed to render the techtree")?;
|
.context("Failed to render the techtree")?;
|
||||||
render::publish(&ctx, &rendered_tree)
|
|
||||||
.await
|
if token.is_some() {
|
||||||
.context("Failed to publish rendered tree to git")?;
|
render::publish(&ctx, &rendered_tree)
|
||||||
|
.await
|
||||||
|
.context("Failed to publish rendered tree to git")?;
|
||||||
|
} else {
|
||||||
|
log::warn!("Skipped publishing the rendered tree.");
|
||||||
|
}
|
||||||
|
|
||||||
// Wiki is disabled because the tree is too big for mermaid to handle
|
// Wiki is disabled because the tree is too big for mermaid to handle
|
||||||
if false {
|
if false {
|
||||||
|
@ -115,6 +130,11 @@ async fn run() -> anyhow::Result<()> {
|
||||||
.context("Failed to update the techtree wiki page")?;
|
.context("Failed to update the techtree wiki page")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if token.is_none() {
|
||||||
|
log::warn!("Not running issue updates without token.");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
'issues: for issue in tree.iter_issues() {
|
'issues: for issue in tree.iter_issues() {
|
||||||
let subtree = tree.subtree_for_issue(issue).unwrap();
|
let subtree = tree.subtree_for_issue(issue).unwrap();
|
||||||
let hash = subtree.stable_hash();
|
let hash = subtree.stable_hash();
|
||||||
|
|
|
@ -103,7 +103,12 @@ pub async fn publish(ctx: &crate::Context, rendered: &RenderedTree) -> anyhow::R
|
||||||
.arg("push")
|
.arg("push")
|
||||||
.arg("--force")
|
.arg("--force")
|
||||||
.arg("--quiet")
|
.arg("--quiet")
|
||||||
.arg(ctx.repo_auth_url.to_string())
|
.arg(
|
||||||
|
ctx.repo_auth_url
|
||||||
|
.as_ref()
|
||||||
|
.expect("cannot publish without authentication token")
|
||||||
|
.to_string(),
|
||||||
|
)
|
||||||
.arg("HEAD:refs/heads/render")
|
.arg("HEAD:refs/heads/render")
|
||||||
.status()
|
.status()
|
||||||
.context("Failed to push rendered graph to forgejo repository")?;
|
.context("Failed to push rendered graph to forgejo repository")?;
|
||||||
|
|
Loading…
Reference in a new issue