Skip to content

Commit

Permalink
Support version/release types with CLI arg
Browse files Browse the repository at this point in the history
  • Loading branch information
jadelily18 committed Nov 12, 2023
1 parent ee98c32 commit 2d4ce67
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::models::{
version::VersionInfo,
GithubConfig,
};
use crate::models::modrinth::version::VersionType;

pub async fn generate_changelog(config: &GithubConfig) -> Result<String, anyhow::Error> {
println!("Generating changelog...");
Expand Down Expand Up @@ -63,6 +64,7 @@ pub async fn create_modpack_release(
output_file_info: &OutputFileInfo,
version_info: &VersionInfo,
changelog: &str,
version_type: VersionType
) -> Result<(), anyhow::Error> {
println!("Creating GitHub release...");

Expand All @@ -75,6 +77,10 @@ pub async fn create_modpack_release(
tag_name: pack_file.version.clone(),
name: Some(version_info.version_name.clone()),
body: Some(changelog.to_owned()),
prerelease: match version_type {
VersionType::Release => false,
_ => true
}
};

let new_release_response =
Expand Down Expand Up @@ -118,6 +124,7 @@ pub async fn create_mod_release(
mod_jars: &ModJars,
changelog: &str,
version_name: &String,
version_type: VersionType
) -> Result<(), anyhow::Error> {
println!("Creating GitHub release...");

Expand All @@ -130,6 +137,10 @@ pub async fn create_mod_release(
tag_name: mod_info.version.clone(),
name: Some(version_name.into()),
body: Some(changelog.to_owned()),
prerelease: match version_type {
VersionType::Release => false,
_ => true
}
};

let new_release_response =
Expand Down
28 changes: 25 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{
util::*,
version::*,
};
use crate::models::modrinth::version::VersionType;

mod discord;
mod github;
Expand All @@ -39,19 +40,23 @@ struct CliArgs {

#[derive(Debug, Subcommand)]
enum Commands {
#[command(about = "Export and upload Packwiz modpack")]
#[command(about = "Export and upload a Packwiz modpack")]
Modpack {
#[clap(long, short, help = "Whether or not to send Discord webhook")]
discord: bool,
#[clap(long, short, help = "Custom version number")]
version: Option<String>,
#[clap(long, short = 'V', help = "Version type (used for Modrinth & GitHub releases)")]
version_type: Option<VersionType>
},
#[command(about = "Build and upload Fabric/Quilt mc_mod")]
#[command(about = "Build and upload a Fabric/Quilt mod")]
Mod {
#[clap(long, short, help = "Whether or not to send Discord webhook")]
discord: bool,
#[clap(long, short, help = "Args to pass to Gradle", default_value = "build")]
gradle_args: String,
#[clap(long, short = 'V', help = "Version type (used for Modrinth & GitHub releases)")]
version_type: Option<VersionType>
},
}

Expand All @@ -62,7 +67,7 @@ async fn main() -> Result<(), anyhow::Error> {
let args = CliArgs::parse();

match args.commands {
Commands::Modpack { discord, version } => {
Commands::Modpack { discord, version, version_type } => {
match which::which("packwiz") {
Ok(_) => (),
Err(err) => return Err(anyhow!("Failed to find packwiz executable: {}", err)),
Expand Down Expand Up @@ -144,6 +149,10 @@ async fn main() -> Result<(), anyhow::Error> {
&output_file_info,
&version_info,
&changelog_markdown,
match version_type.clone() {
Some(ver_type) => ver_type,
None => VersionType::Release
}
)
.await
{
Expand All @@ -168,6 +177,10 @@ async fn main() -> Result<(), anyhow::Error> {
&changelog_markdown,
modrinth_token.clone(),
&modrinth_url,
match version_type {
Some(ver_type) => ver_type,
None => VersionType::Release
}
)
.await
{
Expand Down Expand Up @@ -205,6 +218,7 @@ async fn main() -> Result<(), anyhow::Error> {
Commands::Mod {
discord,
gradle_args,
version_type
} => {
match which::which("java") {
Ok(_) => (),
Expand Down Expand Up @@ -405,6 +419,10 @@ async fn main() -> Result<(), anyhow::Error> {
&mod_jars,
&changelog_markdown,
&version_info.name,
match version_type.clone() {
Some(ver_type) => ver_type,
None => VersionType::Release
}
)
.await
{
Expand All @@ -422,6 +440,10 @@ async fn main() -> Result<(), anyhow::Error> {
&changelog_markdown,
&modrinth_url,
&version_info.name,
match version_type {
Some(ver_type) => ver_type,
None => VersionType::Release
}
)
.await
{
Expand Down
1 change: 1 addition & 0 deletions src/models/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct CreateReleaseRequest {
pub tag_name: String,
pub name: Option<String>,
pub body: Option<String>,
pub prerelease: bool
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
4 changes: 3 additions & 1 deletion src/models/modrinth/version.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use clap::ValueEnum;
use crate::models::{
modrinth::{DependencyType, Loader},
project_type::mc_mod::config::modrinth::ModrinthDependency,
};
use serde::{Deserialize, Serialize};


// Based on the `Create Version` schema here:
// https://docs.modrinth.com/api-spec#tag/versions/operation/createVersion
#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -30,7 +32,7 @@ pub struct VersionDependency {
pub dependency_type: DependencyType,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Clone, ValueEnum)]
#[serde(rename_all = "lowercase")]
pub enum VersionType {
Release,
Expand Down
6 changes: 4 additions & 2 deletions src/modrinth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub async fn create_modpack_release(
changelog: &String,
modrinth_token: String,
modrinth_url: &ModrinthUrl,
version_type: VersionType
) -> Result<(), anyhow::Error> {
let modrinth_config = config.modrinth.clone();

Expand All @@ -62,7 +63,7 @@ pub async fn create_modpack_release(
changelog: Some(changelog.to_string()),
dependencies: vec![],
game_versions: vec![pack_file.versions.minecraft.clone()],
version_type: VersionType::Release,
version_type,
loaders: vec![version_info.loader],
featured: false,
requested_status: VersionStatus::Listed,
Expand Down Expand Up @@ -110,6 +111,7 @@ pub async fn create_mod_release(
changelog: &String,
modrinth_url: &ModrinthUrl,
version_name: &String,
version_type: VersionType
) -> Result<(), anyhow::Error> {
let modrinth_config = config.modrinth.clone();
let modrinth_token = match env::var("MODRINTH_TOKEN") {
Expand Down Expand Up @@ -144,7 +146,7 @@ pub async fn create_mod_release(
changelog: Some(changelog.to_string()),
dependencies,
game_versions: config.mc_versions.to_owned(),
version_type: VersionType::Release,
version_type,
loaders: config.loaders.to_owned(),
featured: false,
requested_status: VersionStatus::Listed,
Expand Down

0 comments on commit 2d4ce67

Please sign in to comment.