From b9a2385db49254a0a96c1e6092c6d9604deae8d9 Mon Sep 17 00:00:00 2001
From: Ryan Brue <ryanbrue.dev@gmail.com>
Date: Sep 29 2024 02:10:03 +0000
Subject: cosmic-packaging-tool: script to publish builds


Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>

---

diff --git a/cosmic-packaging-tool/src/main.rs b/cosmic-packaging-tool/src/main.rs
index 633bc9b..134cd70 100644
--- a/cosmic-packaging-tool/src/main.rs
+++ b/cosmic-packaging-tool/src/main.rs
@@ -1,7 +1,7 @@
 use std::{
     collections::HashSet,
     env,
-    fs::{self, File},
+    fs::{self, create_dir, File},
     io::{self, BufRead, Write},
     path::{Path, PathBuf},
     process::Command,
@@ -35,12 +35,24 @@ enum Commands {
         #[arg(long)]
         exclude_gpl_3: bool,
     },
+    /// Autobump releases
     AutobumpReleases {
         /// Packaging directory to rewrite cosmic spec files
         packaging_dir: PathBuf,
         /// Release to set (i.e. '%autorelease')
         release: String,
     },
+    /// Sets up a fedpkg build (run fkinit to start)
+    SetupBuild {
+        /// Working directory
+        workdir: PathBuf,
+        /// Package name (cosmic-comp for example)
+        package_name: String,
+        /// Srpm url (check the copr)
+        srpm_url: String,
+        /// Version (i.e. 1.0.0~alpha.2)
+        version: String,
+    },
 }
 
 const PACKAGES_ITER: [Packages; 22] = [
@@ -170,7 +182,93 @@ fn main() -> anyhow::Result<()> {
             packaging_dir,
             release,
         } => autobump_releases_command(&packaging_dir, &release),
+        Commands::SetupBuild {
+            workdir,
+            package_name,
+            srpm_url,
+            version,
+        } => setup_build_command(&workdir, &package_name, &srpm_url, &version),
+    }
+}
+
+fn setup_build_command(
+    workdir: &Path,
+    package_name: &str,
+    srpm_url: &str,
+    version: &str,
+) -> anyhow::Result<()> {
+    let _ = create_dir(workdir);
+    let rpm_path = workdir.join(&format!("{}.rpm", package_name));
+    let package_folder = workdir.join(package_name);
+    println!("fedpkg clone {}", package_name);
+    if !Command::new("fedpkg")
+        .current_dir(workdir)
+        .arg("clone")
+        .arg(package_name)
+        .status()
+        .unwrap()
+        .success()
+    {
+        panic!("Failed: fedpkg clone {}", package_name);
+    }
+    println!("wget -O {:?} {}", &rpm_path, srpm_url);
+    if !Command::new("wget")
+        .current_dir(workdir)
+        .arg("-O")
+        .arg(&rpm_path)
+        .arg(srpm_url)
+        .status()
+        .unwrap()
+        .success()
+    {
+        panic!("Failed: wget -O {:?} {}", &rpm_path, srpm_url);
+    }
+    println!("fedpkg import --skip-diffs {:?}", &rpm_path);
+    if !Command::new("fedpkg")
+        .current_dir(&package_folder)
+        .arg("import")
+        .arg("--skip-diffs")
+        .arg(&rpm_path)
+        .status()
+        .unwrap()
+        .success()
+    {
+        panic!("Failed: fedpkg import --skip-diffs {:?}", &rpm_path);
+    }
+    let commit_msg = format!("\"Update to {}\"", version);
+    println!("fedpkg commit -m {}", &commit_msg);
+    if !Command::new("fedpkg")
+        .current_dir(&package_folder)
+        .arg("commit")
+        .arg("-m")
+        .arg(&commit_msg)
+        .status()
+        .unwrap()
+        .success()
+    {
+        panic!("Failed: fedpkg commit -m {}", &commit_msg);
     }
+    println!("fedpkg push");
+    if !Command::new("fedpkg")
+        .current_dir(&package_folder)
+        .arg("push")
+        .status()
+        .unwrap()
+        .success()
+    {
+        panic!("Failed: fedpkg push");
+    }
+    println!("fedpkg build");
+    if !Command::new("fedpkg")
+        .current_dir(&package_folder)
+        .arg("build")
+        .status()
+        .unwrap()
+        .success()
+    {
+        panic!("Failed: fedpkg build");
+    }
+    Ok(())
 }
 
 fn autobump_releases_command(packaging_dir: &Path, release: &str) -> anyhow::Result<()> {
diff --git a/docs/src/building-for-rawhide.md b/docs/src/building-for-rawhide.md
index 08caf77..81fa91e 100644
--- a/docs/src/building-for-rawhide.md
+++ b/docs/src/building-for-rawhide.md
@@ -1,7 +1,7 @@
 # Building for Rawhide
 
 ```sh
-fedpkg request-repo ...
+fedpkg request-repo <name> <bug>
 fedpkg clone <package> && cd <package>
 fedpkg import /path/to/package.src.rpm
 fedpkg commit -m "Initial import to Fedora (rhbz#XXXXXXXX)"
@@ -10,4 +10,56 @@ fedpkg push && fedpkg build
 
 ```
 fkinit
-```
\ No newline at end of file
+```
+
+
+To build (1.0.0~alpha.2 2024-09-28):
+
+> **TODO:** Build these, but first I have to wait on the ssh key to refresh 
+
+- ~~cosmic-comp~~
+- ~~cosmic-icon-theme~~
+- ~~cosmic-app-library~~
+- ~~xdg-desktop-portal-cosmic~~
+- ~~cosmic-edit~~
+- ~~cosmic-files~~
+- ~~cosmic-randr~~
+- ~~cosmic-settings~~
+- ~~cosmic-settings-daemon~~
+- ~~cosmic-greeter~~
+- ~~cosmic-osd~~
+- ~~cosmic-store~~
+- ~~cosmic-workspaces~~
+- ~~cosmic-screenshot~~
+- ~~cosmic-panel~~
+
+
+- cosmic-app-library
+- cosmic-comp
+- cosmic-edit
+- cosmic-files
+- cosmic-greeter
+- cosmic-icon-theme
+- cosmic-osd
+- cosmic-panel
+- cosmic-randr
+- cosmic-screenshot
+- cosmic-settings
+- cosmic-settings-daemon
+- cosmic-store
+- cosmic-workspaces
+- xdg-desktop-portal-cosmic
+
+Missing:
+
+- cosmic-applets
+- cosmic-bg
+- cosmic-launcher
+- cosmic-notifications
+- cosmic-session
+- cosmic-term
+- pop-launcher
+
+```shell
+cargo run -- setup-build ~/workdir <PACKAGE_NAME> <SRPM_URL> 1.0.0~alpha.2
+``` 
\ No newline at end of file

