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

chore: test release-plz release #892

Merged
merged 48 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3b54922
chore: test release-plz release
MarcoIeni Aug 5, 2023
fe6d820
add cargo feature
MarcoIeni Aug 7, 2023
827c8e2
fix
MarcoIeni Aug 7, 2023
2698bb1
fix
MarcoIeni Aug 7, 2023
814ee41
wip
MarcoIeni Aug 10, 2023
f9ff474
Merge branch 'main' into test-release
MarcoIeni Aug 16, 2023
5b363ec
Merge branch 'main' into test-release
MarcoIeni Aug 16, 2023
2998f84
remove gix
MarcoIeni Aug 16, 2023
522287e
wip
MarcoIeni Aug 16, 2023
e1ec575
clippy
MarcoIeni Aug 16, 2023
e96d4de
context
MarcoIeni Aug 16, 2023
72a1e95
wip
MarcoIeni Aug 16, 2023
0340db4
verbose
MarcoIeni Aug 16, 2023
ee453ac
wip
MarcoIeni Aug 16, 2023
43eba9d
add context
MarcoIeni Aug 16, 2023
48c4210
context
MarcoIeni Aug 16, 2023
b5032f1
context
MarcoIeni Aug 16, 2023
83fb341
context
MarcoIeni Aug 16, 2023
07566e5
context
MarcoIeni Aug 16, 2023
a2f91b3
switch to gitea cargo registry
MarcoIeni Aug 17, 2023
ed1fe50
wip
MarcoIeni Aug 17, 2023
f8522d5
create repository index
MarcoIeni Aug 17, 2023
3c32058
post
MarcoIeni Aug 17, 2023
fe54bf7
username
MarcoIeni Aug 17, 2023
836c022
fix encode
MarcoIeni Aug 17, 2023
d365c78
wip
MarcoIeni Aug 17, 2023
848af24
wip
MarcoIeni Aug 17, 2023
89c9e3e
lower timeout
MarcoIeni Aug 17, 2023
94dcacb
wip
MarcoIeni Aug 17, 2023
c4de358
wip
MarcoIeni Aug 17, 2023
4f67886
wip
MarcoIeni Aug 17, 2023
015c834
wip
MarcoIeni Aug 17, 2023
dacd96f
wip
MarcoIeni Aug 17, 2023
7871250
wip
MarcoIeni Aug 17, 2023
6a9d308
wip
MarcoIeni Aug 17, 2023
fe9af90
wip
MarcoIeni Aug 17, 2023
4502c92
wip
MarcoIeni Aug 17, 2023
bbe17a8
wip
MarcoIeni Aug 17, 2023
8d5b693
wip
MarcoIeni Aug 17, 2023
a6da7d3
wip
MarcoIeni Aug 17, 2023
1defd78
wip
MarcoIeni Aug 17, 2023
5b4efac
wip
MarcoIeni Aug 17, 2023
8f3ccd2
wip
MarcoIeni Aug 17, 2023
88ae690
wip
MarcoIeni Aug 17, 2023
6ed86de
wip
MarcoIeni Aug 17, 2023
1a24ecf
wip
MarcoIeni Aug 17, 2023
7b6df3f
fmt
MarcoIeni Aug 17, 2023
3caa17e
wip
MarcoIeni Aug 17, 2023
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = ["crates/*"]
anyhow = "1.0.74"
assert_cmd = "2.0.12"
async-trait = "0.1.73"
base64 = "0.21.2"
cargo_metadata = "0.17.0"
cargo = "0.72.2"
chrono = { version = "0.4.26", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions crates/cargo_utils/src/local_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl LocalManifest {
if !path.is_absolute() {
anyhow::bail!("can only edit absolute paths, got {}", path.display());
}
let data =
std::fs::read_to_string(path).with_context(|| "Failed to read manifest contents")?;
let data = std::fs::read_to_string(path)
.with_context(|| format!("Failed to read manifest contents. Path: {:?}", path))?;
let manifest = data.parse().context("Unable to parse Cargo.toml")?;
Ok(LocalManifest {
manifest,
Expand Down
3 changes: 3 additions & 0 deletions crates/release_plz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ git_cmd = { path = "../git_cmd", version = "0.4.8" }
release_plz_core = { path = "../release_plz_core", version = "0.13.1" }

anyhow.workspace = true
base64.workspace = true
chrono = { workspace = true, features = ["clock"] }
clap = { workspace = true, features = ["derive", "env"] }
clap_complete.workspace = true
Expand All @@ -36,6 +37,7 @@ tracing.workspace = true
url.workspace = true

[dev-dependencies]
cargo_utils = { path = "../cargo_utils" }
test_logs = { path = "../test_logs" }

assert_cmd.workspace = true
Expand All @@ -44,3 +46,4 @@ fake.workspace = true
expect-test.workspace = true
serde_json.workspace = true
tempfile.workspace = true
toml_edit.workspace = true
2 changes: 1 addition & 1 deletion crates/release_plz/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct CliArgs {
pub command: Command,
/// Print source location and additional information in logs.
/// To change the log level, use the `RUST_FLAG` environment variable.
#[arg(short, long)]
#[arg(short, long, global = true)]
pub verbose: bool,
/// Path to the release-plz config file.
/// Default: `./release-plz.toml`.
Expand Down
28 changes: 26 additions & 2 deletions crates/release_plz/tests/all/changelog.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::helpers::test_context::TestContext;
use crate::helpers::{test_context::TestContext, TEST_REGISTRY};

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn release_plz_adds_changelog_on_new_project() {
let context = TestContext::new().await;

context.run_release_plz().success();
context.run_release_pr().success();

let opened_prs = context.opened_release_prs().await;
assert_eq!(opened_prs.len(), 1);
Expand All @@ -17,3 +17,27 @@ async fn release_plz_adds_changelog_on_new_project() {
assert_eq!(changed_files.len(), 1,);
assert_eq!(changed_files[0].filename, "CHANGELOG.md");
}

#[tokio::test]
#[cfg_attr(not(feature = "docker-tests"), ignore)]
async fn release_plz_releases_a_new_project() {
let context = TestContext::new().await;

let crate_name = &context.gitea.repo;
let dest_dir = tempfile::tempdir().unwrap();
let dest_dir_str = dest_dir.path().to_str().unwrap();

let packages = || {
release_plz_core::PackageDownloader::new([crate_name], dest_dir_str)
.with_registry(TEST_REGISTRY.to_string())
.with_cargo_cwd(context.repo_dir())
.download()
.unwrap()
};
// Before running release-plz, no packages should be present.
assert!(packages().is_empty());

context.run_release().success();

assert_eq!(packages().len(), 1);
}
8 changes: 4 additions & 4 deletions crates/release_plz/tests/all/completion_test.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use assert_cmd::Command;
use clap::ValueEnum;
use clap_complete::Shell;

use crate::helpers;

#[test]
fn test_generate_completions() -> anyhow::Result<()> {
fn test_generate_completions() {
for &shell in Shell::value_variants() {
Command::cargo_bin(env!("CARGO_PKG_NAME"))?
helpers::cmd::release_plz_cmd()
.arg("generate-completions")
.arg(shell.to_string())
.assert()
.success();
}
Ok(())
}
5 changes: 5 additions & 0 deletions crates/release_plz/tests/all/helpers/cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use assert_cmd::Command;

pub fn release_plz_cmd() -> Command {
Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap()
}
2 changes: 1 addition & 1 deletion crates/release_plz/tests/all/helpers/fake_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fake::{Fake, StringFaker};

pub fn fake_id() -> String {
const LETTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const LETTERS: &str = "abcdefghijklmnopqrstuvwxyz";
let f = StringFaker::with(Vec::from(LETTERS), 8);
f.fake()
}
37 changes: 32 additions & 5 deletions crates/release_plz/tests/all/helpers/gitea/gitea_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde_json::json;

use crate::helpers::{fake_utils, reqwest_utils::ReqwestUtils};

use super::{GiteaContext, GiteaUser};
use super::{GiteaContext, GiteaUser, CARGO_INDEX_REPO};

impl GiteaContext {
pub async fn new(repo: String) -> Self {
Expand All @@ -15,6 +15,8 @@ impl GiteaContext {
let token = create_token(&user, &client).await;

create_repository(&token, &repo, &client).await;
create_repository(&token, CARGO_INDEX_REPO, &client).await;
upload_registry_config(&token, &user.username, &client).await;

Self {
user,
Expand All @@ -33,14 +35,15 @@ pub async fn create_token(user: &GiteaUser, client: &reqwest::Client) -> String

let token: Token = client
.post(super::gitea_endpoint(&format!(
"/users/{}/tokens",
"users/{}/tokens",
user.username()
)))
.basic_auth(user.username(), Some(&user.password()))
.json(&json!({
"name": user.username(),
// edit repositories
"scopes": ["read:repository", "write:repository", "write:user"]
// write:repository, write:user - edit repositories
// write:package - publish packages (for cargo publish)
"scopes": ["read:repository", "write:repository", "write:user", "write:package"]
}))
.send()
.await
Expand All @@ -56,7 +59,7 @@ pub async fn create_token(user: &GiteaUser, client: &reqwest::Client) -> String

async fn create_repository(user_token: &str, repo_name: &str, client: &reqwest::Client) {
client
.post(super::gitea_endpoint("/user/repos"))
.post(super::gitea_endpoint("user/repos"))
.query(&[("token", user_token)])
.json(&json!({
"name": repo_name,
Expand All @@ -71,6 +74,30 @@ async fn create_repository(user_token: &str, repo_name: &str, client: &reqwest::
.unwrap();
}

async fn upload_registry_config(user_token: &str, username: &str, client: &reqwest::Client) {
use base64::Engine as _;
let content = {
let cargo_url = format!("http://localhost:3000/api/packages/{username}/cargo");
format!("{{\"dl\":\"{cargo_url}/api/v1/crates\",\"api\":\"{cargo_url}\"}}")
};

client
.post(super::gitea_endpoint(&format!(
"repos/{username}/{CARGO_INDEX_REPO}/contents/config.json"
)))
.query(&[("token", user_token)])
.json(&json!({
"message": "Add config.json",
"content": base64::engine::general_purpose::STANDARD.encode(content.as_bytes()),
}))
.send()
.await
.expect("Failed to upload content")
.ok_if_2xx()
.await
.unwrap();
}

fn run_create_user_command(user: &GiteaUser) {
let email = format!("{}@example.com", user.username());
Command::new("docker")
Expand Down
5 changes: 4 additions & 1 deletion crates/release_plz/tests/all/helpers/gitea/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ pub struct GiteaContext {
client: reqwest::Client,
}

/// Repository name where gitea stores the registry index.
pub const CARGO_INDEX_REPO: &str = "_cargo-index";

fn gitea_endpoint(endpoint: &str) -> String {
let api_url = format!("http://{}/api/v1", gitea_address());
format!("{}/{}", api_url, endpoint)
}

fn gitea_address() -> &'static str {
pub fn gitea_address() -> &'static str {
"localhost:3000"
}
3 changes: 3 additions & 0 deletions crates/release_plz/tests/all/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
pub mod cmd;
mod fake_utils;
pub mod gitea;
mod reqwest_utils;
pub mod test_context;

pub const TEST_REGISTRY: &str = "test-registry";
Loading
Loading