sastri 0.1.0

Scaffold multi-ecosystem packaging and CI/CD for Rust CLIs (Homebrew, Scoop, PyPI, npm, Hex, mise, asdf, …)
Documentation
use anyhow::Result;

use super::{GeneratedFile, Mechanism, MechanismContext, StepResult};

pub struct Scoop;

impl Mechanism for Scoop {
    fn id(&self) -> &'static str {
        "scoop"
    }

    fn description(&self) -> &'static str {
        "packaging/scoop Windows manifest"
    }

    fn generate(&self, ctx: &MechanismContext<'_>) -> Result<StepResult> {
        let p = &ctx.config.project;
        let bin = &p.binary_name;
        let version = &p.version;
        let homepage = ctx.config.homepage();
        let bucket = ctx
            .config
            .org
            .scoop_bucket
            .clone()
            .unwrap_or_else(|| format!("{}/scoop-bucket", p.github_owner));

        let manifest = format!(
            r#"{{
  "version": "{version}",
  "description": {desc},
  "homepage": "{homepage}",
  "license": "{license}",
  "architecture": {{
    "64bit": {{
      "url": "https://github.com/{owner}/{repo}/releases/download/v{version}/{bin}-v{version}-windows-x86_64.zip",
      "hash": "REPLACE_AFTER_RELEASE"
    }}
  }},
  "bin": "{bin}.exe",
  "checkver": {{
    "github": "https://github.com/{owner}/{repo}"
  }},
  "autoupdate": {{
    "architecture": {{
      "64bit": {{
        "url": "https://github.com/{owner}/{repo}/releases/download/v$version/{bin}-v$version-windows-x86_64.zip",
        "hash": {{
          "url": "https://github.com/{owner}/{repo}/releases/download/v$version/SHA256SUMS"
        }}
      }}
    }}
  }}
}}
"#,
            desc = serde_json::to_string(&p.description)?,
            owner = p.github_owner,
            repo = p.github_repo,
            license = p.license,
        );

        let readme = format!(
            "# Scoop manifest\n\nPublish `{bin}.json` to [`{bucket}`](https://github.com/{bucket}).\n\n```powershell\nscoop bucket add {owner} https://github.com/{bucket}\nscoop install {bin}\n```\n",
            owner = p.github_owner,
        );

        let base = format!(
            "{}/scoop",
            ctx.config.paths.packaging_dir.trim_end_matches('/')
        );
        Ok(StepResult {
            files: vec![
                GeneratedFile {
                    relative_path: format!("{base}/{bin}.json"),
                    contents: manifest,
                    executable: false,
                },
                GeneratedFile {
                    relative_path: format!("{base}/README.md"),
                    contents: readme,
                    executable: false,
                },
            ],
            notes: vec![format!(
                "After release, set hash from SHA256SUMS and push to {bucket}"
            )],
        })
    }
}