Skip to content

Commit e8b404f

Browse files
committed
trigger pipeline execution
1 parent ea7e370 commit e8b404f

File tree

6 files changed

+137
-39
lines changed

6 files changed

+137
-39
lines changed

crates/cli/cli.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use commands::aws::PullRequestStatus;
66
// #[command(propagate_version = true)]
77
pub struct Args {
88
#[command(subcommand)]
9-
pub command: Commands,
9+
pub command: Option<Commands>,
1010

1111
/// do not perform any action
1212
#[arg(long, global = true)]
@@ -34,10 +34,27 @@ pub enum ReleasePushTarget {
3434

3535
#[derive(Subcommand, strum::Display, Debug, Clone)]
3636
pub enum ReleaseCommands {
37-
Start,
37+
Start {
38+
#[arg(long)]
39+
patch: bool,
40+
41+
#[arg(long, default_value = "true")]
42+
minor: bool,
43+
44+
#[arg(long)]
45+
major: bool,
46+
},
3847
Push {
3948
#[arg(long, short, default_value = "All")]
4049
target: ReleasePushTarget,
50+
51+
/// pipeline to trigger
52+
#[arg(long, short = 'n')]
53+
pipeline_name: Option<String>,
54+
55+
/// aws profile
56+
#[arg(long, default_value = "default")]
57+
profile: String,
4158
},
4259
Finish,
4360
}
@@ -78,23 +95,16 @@ pub enum TicketCommands {
7895
project: Option<String>,
7996
},
8097
/// Run `git flow finish`
81-
Finish {
82-
id_or_url: Option<String>,
83-
},
98+
Finish { id_or_url: Option<String> },
8499

85100
/// Print userStory link
86-
Link {
87-
id_or_url: Option<String>,
88-
},
101+
Link { id_or_url: Option<String> },
89102

90103
/// Print userStory link
91-
GetBranch {
92-
id_or_url: String,
93-
},
104+
GetBranch { id_or_url: String },
94105

95-
GetId {
96-
url: Option<String>,
97-
},
106+
/// Print userStory ID
107+
GetId { url: Option<String> },
98108

99109
/// Print project details
100110
GetProject {
@@ -108,6 +118,8 @@ pub enum TicketCommands {
108118
json: bool,
109119
},
110120

121+
/// Generate a changelog from a targetprocess release
122+
#[clap(alias = "changelog")]
111123
GenerateChangelog {
112124
from: usize,
113125

crates/cli/main.rs

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ use commands::{
1111
spawn_command,
1212
};
1313
use config::{util::get_user_id, Config, ProjectConfig};
14+
use global_utils::print_dbg;
1415
use human_panic::setup_panic;
1516
use mdka::from_html;
1617
use target_process::{models::EntityStates, SearchOperator};
1718

18-
use crate::{cli::Args, context::GlobalContext, manifests::node::PackageJson};
19+
use crate::{
20+
cli::Args, context::GlobalContext, manifests::node::PackageJson,
21+
subcommands::release::ReleaseKind,
22+
};
1923

2024
mod cli;
2125
mod context;
@@ -24,9 +28,11 @@ mod manifests;
2428
mod subcommands;
2529
mod utils;
2630

27-
fn print_help() {
31+
fn print_help() -> Result<()> {
2832
let mut cmd = Args::command();
29-
cmd.print_help();
33+
cmd.print_help()?;
34+
35+
Ok(())
3036
}
3137

3238
fn is_slack_enabled(slack_flag: bool) -> bool {
@@ -61,6 +67,21 @@ async fn main() -> Result<()> {
6167
#[cfg(debug_assertions)]
6268
color_eyre::install()?;
6369

70+
let args = cli::Args::parse();
71+
72+
if args.version {
73+
println!("{}", env!("CARGO_PKG_VERSION"));
74+
return Ok(());
75+
}
76+
77+
if args.debug {
78+
std::env::set_var("TPAWS_DEBUG", args.debug.to_string());
79+
}
80+
81+
if args.command.is_none() {
82+
return print_help();
83+
}
84+
6485
if !commands::is_installed!("aws") {
6586
println!("Useful links:");
6687
println!(
@@ -73,8 +94,6 @@ async fn main() -> Result<()> {
7394
return Ok(());
7495
}
7596

76-
let args = cli::Args::parse();
77-
7897
if Config::is_first_run()? {
7998
println!("Please configure the CLI before continue");
8099
println!();
@@ -92,17 +111,13 @@ async fn main() -> Result<()> {
92111

93112
let create_pr_args = args.clone();
94113

95-
if args.debug {
96-
std::env::set_var("TPAWS_DEBUG", args.debug.to_string());
97-
}
98-
99-
match args.command {
114+
match args.command.unwrap() {
100115
cli::Commands::PullRequest {
101116
subcommands,
102117
profile,
103118
..
104119
} => {
105-
let branch = git::current_branch().await?;
120+
let branch = git::current_branch_v2().await?.0;
106121
let repository = utils::get_repository().await?;
107122

108123
let region = aws::get_region(profile.clone()).await?;
@@ -438,17 +453,34 @@ async fn main() -> Result<()> {
438453
}
439454

440455
let pkg = PackageJson::read().await?;
441-
let branch = git::current_branch().await?;
456+
let branch = git::current_branch_v2().await?;
442457

443458
match subcommands {
444-
cli::ReleaseCommands::Start => {
445-
subcommands::release::start(&pkg).await?;
459+
cli::ReleaseCommands::Start {
460+
major,
461+
patch,
462+
minor,
463+
} => {
464+
let kind: ReleaseKind = match (major, minor, patch) {
465+
(_, _, true) => ReleaseKind::Patch,
466+
(true, _, _) => ReleaseKind::Major,
467+
(_, true, _) => ReleaseKind::Minor,
468+
_ => ReleaseKind::Minor,
469+
};
470+
471+
print_dbg!(&kind, major, minor, patch);
472+
473+
subcommands::release::start(&pkg, kind).await?;
446474
}
447-
cli::ReleaseCommands::Push { target } => {
448-
subcommands::release::push(target).await?;
475+
cli::ReleaseCommands::Push {
476+
target,
477+
pipeline_name: name,
478+
profile,
479+
} => {
480+
subcommands::release::push(target, name, profile).await?;
449481
}
450482
cli::ReleaseCommands::Finish => {
451-
subcommands::release::finish(&pkg, &branch).await?;
483+
subcommands::release::finish(&pkg, &branch.0).await?;
452484
}
453485
}
454486
}

crates/cli/manifests/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ impl Version {
1717
self.patch = 0;
1818
}
1919

20-
// pub fn bump_patch(&mut self) {
21-
// self.patch += 1
22-
// }
20+
pub fn bump_patch(&mut self) {
21+
self.patch += 1
22+
}
23+
24+
pub fn bump_major(&mut self) {
25+
self.patch = 0;
26+
self.minor = 0;
27+
self.major += 1;
28+
}
2329
}
2430

2531
impl ToString for Version {

crates/cli/subcommands/release/push.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use color_eyre::{eyre::Context, Result};
2-
use commands::git;
2+
use commands::{aws, git};
33

44
use crate::cli::ReleasePushTarget;
55

6-
pub async fn push(target: ReleasePushTarget) -> Result<()> {
6+
pub async fn push(target: ReleasePushTarget, name: Option<String>, profile: String) -> Result<()> {
77
match target {
88
ReleasePushTarget::Prod => {
99
git::force_push_to_env("origin", "prod")
@@ -26,5 +26,11 @@ pub async fn push(target: ReleasePushTarget) -> Result<()> {
2626
}
2727
}
2828

29+
if let Some(name) = name {
30+
println!();
31+
aws::start_pipeline_execution(name, profile).await?;
32+
println!("Pipeline triggered.");
33+
}
34+
2935
Ok(())
3036
}

crates/cli/subcommands/release/start.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
use color_eyre::{eyre::eyre, Result};
22
use commands::{command, git};
3+
use global_utils::print_dbg;
34
use std::str::FromStr;
45

56
use crate::manifests::{node::PackageJson, Version};
67

7-
pub async fn start(pkg: &PackageJson) -> Result<()> {
8+
#[derive(strum::Display, Debug, Clone, Copy)]
9+
pub enum ReleaseKind {
10+
Patch,
11+
Minor,
12+
Major,
13+
}
14+
15+
pub async fn start(pkg: &PackageJson, release_kind: ReleaseKind) -> Result<()> {
816
let mut pkg = pkg.clone();
917
let prev_version = pkg.version.clone();
1018
let mut version = Version::from_str(&pkg.version).map_err(|_| eyre!("invalid version"))?;
1119

20+
print_dbg!(&version);
21+
1222
// bump
13-
version.bump_minor();
23+
match release_kind {
24+
ReleaseKind::Patch => version.bump_patch(),
25+
ReleaseKind::Minor => version.bump_minor(),
26+
ReleaseKind::Major => version.bump_major(),
27+
};
28+
29+
print_dbg!(&release_kind);
30+
1431
pkg.version = version.to_string();
1532

1633
git::flow::release::start(&version.to_string()).await?;
17-
command!("npm", "version", "minor").output().await?;
34+
35+
let command = &release_kind.to_string();
36+
let command = command.to_lowercase();
37+
38+
command!("npm", "version", &command).output().await?;
1839

1940
println!("version bumped from {prev_version} to: {}", pkg.version);
2041

crates/commands/src/aws.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,24 @@ pub async fn merge_pr_by_squash(
375375
let raw_stderr = String::from_utf8(output.stderr)?;
376376
Err(CommandError::IOError(raw_stderr))
377377
}
378+
379+
pub async fn start_pipeline_execution(name: String, profile: String) -> Result<()> {
380+
command!(
381+
"aws",
382+
"codepipeline",
383+
"start-pipeline-execution",
384+
"--name",
385+
&name,
386+
"--profile",
387+
&profile,
388+
"--output",
389+
"json",
390+
"--color",
391+
"off"
392+
)
393+
.output()
394+
.await
395+
.map_err(CommandError::from_io)?;
396+
397+
Ok(())
398+
}

0 commit comments

Comments
 (0)