Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sub-command support to the release-operator #408

Merged
merged 6 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
RUST_LOG: info
run: |
# Run release operator
cargo run
cargo run -- detect

- name: Binaries | Download
if: ${{ steps.release.outputs.release-detected == 'true' }}
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion release-operator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "release-operator"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
4 changes: 2 additions & 2 deletions release-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ As seen above, the release operator requires the maintainer to:

```shell
# release-operator/
cargo run -- --sha <commit-sha> --label <release-label>
cargo run -- detect --sha <commit-sha> --label <release-label>
```

Where `<commit-sha>` can be set using `GITHUB_SHA` (present by default in GitHub Actions), and `<release-label>` can be set using `RELEASE_LABEL` (defaults to `autorelease`).
Expand Down Expand Up @@ -94,7 +94,7 @@ To embed the operator in a workflow, include these steps _before_ anything relat
RELEASE_LABEL: autorelease
run: |
# release operator
cargo run
cargo run -- detect

# Subsequent steps can use:
# if: ${{ steps.release.outputs.release-detected == 'true' }}
Expand Down
31 changes: 24 additions & 7 deletions release-operator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ mod release;
use crate::github::{Actions, GitHub};

use crate::release::Release;
use clap::Parser;
use clap::{Args, Parser, Subcommand};

#[derive(Parser, Debug)]
#[clap(version)]
struct Cmd {
#[derive(Parser)]
#[clap(version, propagate_version = true)]
struct Cli {
#[clap(subcommand)]
command: Commands,
}

#[derive(Subcommand)]
enum Commands {
/// Detect a release and set respective Action outputs
Detect(DetectArgs),
}

#[derive(Args, Debug)]
struct DetectArgs {
/// Commit sha to work on
#[clap(short, long, env = "GITHUB_SHA")]
sha: String,
Expand All @@ -28,10 +40,15 @@ fn main() -> anyhow::Result<()> {
let start = std::time::Instant::now();
log::trace!("starting release-operator process");

let args = Cmd::parse();
log::debug!("got arguments: {args:#?}");
let cli = Cli::parse();

Release::new(args.sha, args.label).detect()?;
match &cli.command {
Commands::Detect(args) => {
log::debug!("got arguments: {args:#?}");
Release::new(args.sha.to_owned(), args.label.to_owned())
.detect()?;
}
}

log::trace!(
"finished release-operator process, took {:?}",
Expand Down