Skip to content

Commit

Permalink
refactor: update file names
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Nov 11, 2024
1 parent b4a06ee commit 2bdb6e2
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 114 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,3 @@ jobs:
uses: actions/checkout@v4
- name: Release Plz
uses: MarcoIeni/[email protected]
with:
command: release-pr
permissions:
contents: write
pull-requests: write
packages: write
5 changes: 2 additions & 3 deletions workspace/gh-workflow-gen/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use gh_workflow::*;
use gh_workflow_release_plz::{Command, ReleasePlz};
use gh_workflow_release_plz::ReleasePlz;
use toolchain::Toolchain;

fn main() {
Expand Down Expand Up @@ -49,9 +49,8 @@ fn main() {

let release = Job::new("Release")
.needs("build")
.permissions(permissions.clone())
.add_step(Step::checkout())
.add_step(ReleasePlz::default().command(Command::ReleasePR));
.add_step(ReleasePlz::default());

Workflow::new("Build and Test")
.add_env(flags)
Expand Down
107 changes: 2 additions & 105 deletions workspace/gh-workflow-release-plz/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,105 +1,2 @@
use derive_setters::Setters;
use gh_workflow::{Step, Use};

#[derive(Clone, Default, Setters)]
#[setters(strip_option, into)]
pub struct ReleasePlz {
/// The release-plz command to run. Accepted values: release-pr, release.
/// (By default it runs both commands).
pub command: Option<Command>,

/// Registry where the packages are stored. The registry name needs to be
/// present in the Cargo config. If unspecified, the publish field of the
/// package manifest is used. If the publish field is empty, crates.io is
/// used.
pub registry: Option<String>,

/// Path to the Cargo.toml of the project you want to update. Both Cargo
/// workspaces and single packages are supported. (Defaults to the root
/// directory).
pub manifest_path: Option<String>,

/// Release-plz version to use. E.g. 0.3.70. (Default: latest version).
pub version: Option<String>,

/// Release-plz config file location. (Defaults to release-plz.toml or
/// .release-plz.toml).
pub config: Option<String>,

/// Token used to publish to the cargo registry.
pub token: Option<String>,

/// Forge backend. Valid values: github, gitea. (Defaults to github).
pub backend: Option<Backend>,
}

#[derive(Clone)]
pub enum Command {
/// Create a release PR.
/// See: <https://release-plz.ieni.dev/docs/usage/release-pr>
ReleasePR,

/// Release the package.
/// See: <https://release-plz.ieni.dev/docs/usage/release>
Release,
}

impl std::fmt::Display for Command {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Command::ReleasePR => write!(f, "release-pr"),
Command::Release => write!(f, "release"),
}
}
}

#[derive(Clone)]
pub enum Backend {
GitHub,
Gitea,
}

impl std::fmt::Display for Backend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Backend::GitHub => write!(f, "github"),
Backend::Gitea => write!(f, "gitea"),
}
}
}

impl From<ReleasePlz> for Step<Use> {
fn from(value: ReleasePlz) -> Self {
let mut step = Step::uses("MarcoIeni", "release-plz-action", 0.5).name("Release Plz");

if let Some(command) = value.command {
step = step.add_with(("command", command.to_string()));
}

if let Some(registry) = value.registry {
step = step.add_with(("registry", registry));
}

if let Some(manifest_path) = value.manifest_path {
step = step.add_with(("manifest_path", manifest_path));
}

if let Some(version) = value.version {
step = step.add_with(("version", version));
}

if let Some(config) = value.config {
step = step.add_with(("config", config));
}

if let Some(token) = value.token {
step = step.add_with(("token", token));
}

if let Some(backend) = value.backend {
step = step.add_with(("backend", backend.to_string()));
}

step
}
}
mod release;
pub use release::*;
105 changes: 105 additions & 0 deletions workspace/gh-workflow-release-plz/src/release.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
use derive_setters::Setters;
use gh_workflow::{Step, Use};

#[derive(Clone, Default, Setters)]
#[setters(strip_option, into)]
pub struct ReleasePlz {
/// The release-plz command to run. Accepted values: release-pr, release.
/// (By default it runs both commands).
pub command: Option<Command>,

/// Registry where the packages are stored. The registry name needs to be
/// present in the Cargo config. If unspecified, the publish field of the
/// package manifest is used. If the publish field is empty, crates.io is
/// used.
pub registry: Option<String>,

/// Path to the Cargo.toml of the project you want to update. Both Cargo
/// workspaces and single packages are supported. (Defaults to the root
/// directory).
pub manifest_path: Option<String>,

/// Release-plz version to use. E.g. 0.3.70. (Default: latest version).
pub version: Option<String>,

/// Release-plz config file location. (Defaults to release-plz.toml or
/// .release-plz.toml).
pub config: Option<String>,

/// Token used to publish to the cargo registry.
pub token: Option<String>,

/// Forge backend. Valid values: github, gitea. (Defaults to github).
pub backend: Option<Backend>,
}

#[derive(Clone)]
pub enum Command {
/// Create a release PR.
/// See: <https://release-plz.ieni.dev/docs/usage/release-pr>
ReleasePR,

/// Release the package.
/// See: <https://release-plz.ieni.dev/docs/usage/release>
Release,
}

impl std::fmt::Display for Command {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Command::ReleasePR => write!(f, "release-pr"),
Command::Release => write!(f, "release"),
}
}
}

#[derive(Clone)]
pub enum Backend {
GitHub,
Gitea,
}

impl std::fmt::Display for Backend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Backend::GitHub => write!(f, "github"),
Backend::Gitea => write!(f, "gitea"),
}
}
}

impl From<ReleasePlz> for Step<Use> {
fn from(value: ReleasePlz) -> Self {
let mut step = Step::uses("MarcoIeni", "release-plz-action", 0.5).name("Release Plz");

if let Some(command) = value.command {
step = step.add_with(("command", command.to_string()));
}

if let Some(registry) = value.registry {
step = step.add_with(("registry", registry));
}

if let Some(manifest_path) = value.manifest_path {
step = step.add_with(("manifest_path", manifest_path));
}

if let Some(version) = value.version {
step = step.add_with(("version", version));
}

if let Some(config) = value.config {
step = step.add_with(("config", config));
}

if let Some(token) = value.token {
step = step.add_with(("token", token));
}

if let Some(backend) = value.backend {
step = step.add_with(("backend", backend.to_string()));
}

step
}
}

0 comments on commit 2bdb6e2

Please sign in to comment.