-
Notifications
You must be signed in to change notification settings - Fork 1.9k
chore(vdev): add vdev release command #24061
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
Open
pront
wants to merge
5
commits into
master
Choose a base branch
from
pront-release-vdev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+272
−56
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ crate::cli_subcommands! { | |
| mod prepare, | ||
| mod push, | ||
| s3, | ||
| mod vdev, | ||
| } | ||
|
|
||
| crate::script_wrapper! { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| use anyhow::{Result, bail, Context as _}; | ||
| use clap::{Args, ValueEnum}; | ||
| use semver::Version; | ||
| use std::fs; | ||
| use std::path::PathBuf; | ||
|
|
||
| use crate::{git, util}; | ||
|
|
||
| const PUBLISH_URL: &str = "https://github.com/vectordotdev/vector/actions/workflows/vdev_publish.yml"; | ||
| const MAIN_BRANCH: &str = "master"; | ||
|
|
||
| /// Release a new version of vdev | ||
| /// | ||
| /// This command automates the vdev release process: | ||
| /// 1. Validates the new version | ||
| /// 2. Updates vdev/Cargo.toml | ||
| /// 3. Commits the change | ||
| /// 4. Creates and pushes the release tag | ||
| #[derive(Args, Debug)] | ||
| #[command()] | ||
| pub struct Cli { | ||
| /// The release type: major, minor, or patch | ||
| #[arg(value_enum)] | ||
| release_type: ReleaseType, | ||
|
|
||
| /// Skip confirmation prompts | ||
| #[arg(long)] | ||
| yes: bool, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Copy, ValueEnum)] | ||
| enum ReleaseType { | ||
| Major, | ||
| Minor, | ||
| Patch, | ||
| } | ||
|
|
||
| impl Cli { | ||
| pub fn exec(self) -> Result<()> { | ||
| // Check that we're on the master branch | ||
| let current_branch = git::current_branch()?; | ||
| if current_branch != MAIN_BRANCH { | ||
| bail!("Release cancelled. You must be on the '{MAIN_BRANCH}' branch to release (currently on: {current_branch})"); | ||
| } | ||
|
|
||
| // Check git status | ||
| if !git::check_git_repository_clean()? { | ||
| bail!("Release cancelled. You have uncommitted changes in your repository."); | ||
| } | ||
|
|
||
| let repo_root = util::get_repo_root(); | ||
| let vdev_dir = repo_root.join("vdev"); | ||
| let vdev_cargo_toml = vdev_dir.join("Cargo.toml"); | ||
| if !vdev_cargo_toml.exists() { | ||
| bail!("Could not find Cargo.toml at {}", vdev_cargo_toml.display()); | ||
| } | ||
| let current_version = read_vdev_version(&vdev_cargo_toml)?; | ||
| info!("Current vdev version: {current_version}"); | ||
|
|
||
| let new_version = match self.release_type { | ||
| ReleaseType::Major => Version::new(current_version.major + 1, 0, 0), | ||
| ReleaseType::Minor => Version::new(current_version.major, current_version.minor + 1, 0), | ||
| ReleaseType::Patch => Version::new(current_version.major, current_version.minor, current_version.patch + 1), | ||
| }; | ||
|
|
||
| let new_version_str = new_version.to_string(); | ||
| info!("Release version: {new_version_str} ({:?})", self.release_type); | ||
|
|
||
| let tag_name = format!("vdev-v{new_version_str}"); | ||
| // Confirm before proceeding | ||
| if !self.yes { | ||
| let summary = format_release_plan(&new_version_str, &tag_name); | ||
| info!("{summary}"); | ||
| if !util::confirm("Proceed with release?")? { | ||
| bail!("Release cancelled"); | ||
| } | ||
| } | ||
|
|
||
| // Update Cargo.toml | ||
| info!("Updating Cargo.toml to version {new_version_str}"); | ||
| update_vdev_version(&vdev_cargo_toml, ¤t_version, &new_version)?; | ||
|
|
||
| let vdev_cargo_toml_relative = vdev_cargo_toml.strip_prefix(&repo_root) | ||
| .unwrap_or(&vdev_cargo_toml); | ||
| git::run_and_check_output(&["add", &vdev_cargo_toml_relative.display().to_string()])?; | ||
| let commit_message = format!("chore(vdev): bump version to {new_version_str}"); | ||
| git::commit(&commit_message)?; | ||
| debug!("Created commit: {commit_message}"); | ||
|
|
||
| info!("Creating tag {tag_name}"); | ||
| git::tag_version(&tag_name)?; | ||
|
|
||
| info!("Pushing to origin"); | ||
| git::push_branch(MAIN_BRANCH)?; | ||
| debug!("Pushed to {MAIN_BRANCH} branch."); | ||
|
|
||
| git::push_branch(&tag_name)?; | ||
| debug!("Pushed tag: {tag_name}"); | ||
|
|
||
| info!("Monitor release workflow: {PUBLISH_URL}"); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| fn read_vdev_version(cargo_toml_path: &PathBuf) -> Result<Version> { | ||
| let contents = fs::read_to_string(cargo_toml_path) | ||
| .with_context(|| format!("Failed to read {}", cargo_toml_path.display()))?; | ||
|
|
||
| let cargo_toml: util::CargoToml = toml::from_str(&contents) | ||
| .with_context(|| format!("Failed to parse {}", cargo_toml_path.display()))?; | ||
|
|
||
| Version::parse(&cargo_toml.package.version) | ||
| .context("Failed to parse version number") | ||
| } | ||
|
|
||
| fn update_vdev_version( | ||
| cargo_toml_path: &PathBuf, | ||
| old_version: &Version, | ||
| new_version: &Version, | ||
| ) -> Result<()> { | ||
| let contents = fs::read_to_string(cargo_toml_path) | ||
| .with_context(|| format!("Failed to read {}", cargo_toml_path.display()))?; | ||
|
|
||
| let old_line = format!("version = \"{old_version}\""); | ||
| let new_line = format!("version = \"{new_version}\""); | ||
|
|
||
| if !contents.contains(&old_line) { | ||
| bail!("Could not find exact version line '{old_line}' in {}", cargo_toml_path.display()); | ||
| } | ||
|
|
||
| let updated_contents = contents.replace(&old_line, &new_line); | ||
pront marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| fs::write(cargo_toml_path, updated_contents) | ||
| .with_context(|| format!("Failed to write {}", cargo_toml_path.display()))?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn format_release_plan(version: &str, tag_name: &str) -> String { | ||
| format!( | ||
| "\nThis will:\n\ | ||
| 1. Update Cargo.toml to version {version}\n\ | ||
| 2. Commit the change\n\ | ||
| 3. Create tag {tag_name}\n\ | ||
| 4. Push the commit and tag to origin\n" | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this push a commit directly to master? I don't think this is a good idea and I also don't think it will work since we have branch protection rules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the simplest way. Only repo maintainers will ever use this script and they can push to master. I considered bumping locally, publishing, and making a workflow commit the new version. But I don't see why the latter is better really.
Alternative is to make a PR, update the version and then run this script to update the tag. You can think about it a bit more if you want.