From fcb18ade545d6de75772541733863350402fb7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 9 Oct 2024 12:13:49 +0200 Subject: [PATCH 1/7] Add a cargo-release config --- benchmarks/Cargo.toml | 3 +++ bindings/matrix-sdk-crypto-ffi/Cargo.toml | 3 +++ bindings/matrix-sdk-ffi/Cargo.toml | 3 +++ crates/matrix-sdk-sqlite/README.md | 0 crates/matrix-sdk-ui/README.md | 0 examples/autojoin/Cargo.toml | 3 +++ examples/backups/Cargo.toml | 3 +++ examples/command_bot/Cargo.toml | 3 +++ examples/cross_signing_bootstrap/Cargo.toml | 3 +++ examples/custom_events/Cargo.toml | 3 +++ examples/emoji_verification/Cargo.toml | 3 +++ examples/get_profiles/Cargo.toml | 3 +++ examples/getting_started/Cargo.toml | 3 +++ examples/image_bot/Cargo.toml | 3 +++ examples/login/Cargo.toml | 3 +++ examples/oidc_cli/Cargo.toml | 3 +++ examples/persist_session/Cargo.toml | 3 +++ examples/qr-login/Cargo.toml | 3 +++ examples/secret_storage/Cargo.toml | 3 +++ examples/timeline/Cargo.toml | 3 +++ labs/multiverse/Cargo.toml | 3 +++ release.toml | 10 ++++++++++ testing/matrix-sdk-integration-testing/Cargo.toml | 3 +++ testing/matrix-sdk-test-macros/Cargo.toml | 3 +++ testing/matrix-sdk-test/Cargo.toml | 3 +++ uniffi-bindgen/Cargo.toml | 3 +++ xtask/Cargo.toml | 3 +++ 27 files changed, 82 insertions(+) create mode 100644 crates/matrix-sdk-sqlite/README.md create mode 100644 crates/matrix-sdk-ui/README.md create mode 100644 release.toml diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index ea0ba7370f5..0fa7d70cb0d 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -36,3 +36,6 @@ harness = false [[bench]] name = "room_bench" harness = false + +[package.metadata.release] +release = false diff --git a/bindings/matrix-sdk-crypto-ffi/Cargo.toml b/bindings/matrix-sdk-crypto-ffi/Cargo.toml index 3432c965ef8..1f6bdd4db28 100644 --- a/bindings/matrix-sdk-crypto-ffi/Cargo.toml +++ b/bindings/matrix-sdk-crypto-ffi/Cargo.toml @@ -67,3 +67,6 @@ assert_matches2 = { workspace = true } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/bindings/matrix-sdk-ffi/Cargo.toml b/bindings/matrix-sdk-ffi/Cargo.toml index 02400423b17..9df6bfd4d79 100644 --- a/bindings/matrix-sdk-ffi/Cargo.toml +++ b/bindings/matrix-sdk-ffi/Cargo.toml @@ -83,3 +83,6 @@ features = [ [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/crates/matrix-sdk-sqlite/README.md b/crates/matrix-sdk-sqlite/README.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/matrix-sdk-ui/README.md b/crates/matrix-sdk-ui/README.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/examples/autojoin/Cargo.toml b/examples/autojoin/Cargo.toml index 491914db83e..599f7db8232 100644 --- a/examples/autojoin/Cargo.toml +++ b/examples/autojoin/Cargo.toml @@ -19,3 +19,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/backups/Cargo.toml b/examples/backups/Cargo.toml index c6660a70004..cf8f3f6616e 100644 --- a/examples/backups/Cargo.toml +++ b/examples/backups/Cargo.toml @@ -22,3 +22,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/command_bot/Cargo.toml b/examples/command_bot/Cargo.toml index 5b15be635f3..401b03c6473 100644 --- a/examples/command_bot/Cargo.toml +++ b/examples/command_bot/Cargo.toml @@ -19,3 +19,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/cross_signing_bootstrap/Cargo.toml b/examples/cross_signing_bootstrap/Cargo.toml index 1592ec9415b..3910bad611f 100644 --- a/examples/cross_signing_bootstrap/Cargo.toml +++ b/examples/cross_signing_bootstrap/Cargo.toml @@ -20,3 +20,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/custom_events/Cargo.toml b/examples/custom_events/Cargo.toml index 27ed2f7ebec..7ca797dfb51 100644 --- a/examples/custom_events/Cargo.toml +++ b/examples/custom_events/Cargo.toml @@ -20,3 +20,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/emoji_verification/Cargo.toml b/examples/emoji_verification/Cargo.toml index d38c62b74c0..c3dd959f272 100644 --- a/examples/emoji_verification/Cargo.toml +++ b/examples/emoji_verification/Cargo.toml @@ -22,3 +22,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/get_profiles/Cargo.toml b/examples/get_profiles/Cargo.toml index c06cda8361f..bd0a9ff3c47 100644 --- a/examples/get_profiles/Cargo.toml +++ b/examples/get_profiles/Cargo.toml @@ -20,3 +20,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/getting_started/Cargo.toml b/examples/getting_started/Cargo.toml index 1b913633080..0bbde23cfa5 100644 --- a/examples/getting_started/Cargo.toml +++ b/examples/getting_started/Cargo.toml @@ -19,3 +19,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/image_bot/Cargo.toml b/examples/image_bot/Cargo.toml index 1ae3bf43227..e9f89800d04 100644 --- a/examples/image_bot/Cargo.toml +++ b/examples/image_bot/Cargo.toml @@ -21,3 +21,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/login/Cargo.toml b/examples/login/Cargo.toml index a5cd1623dfe..7de8db9d4a5 100644 --- a/examples/login/Cargo.toml +++ b/examples/login/Cargo.toml @@ -20,3 +20,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk", features = ["sso-login"] } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/oidc_cli/Cargo.toml b/examples/oidc_cli/Cargo.toml index 30e475ca62e..a5c8617dd02 100644 --- a/examples/oidc_cli/Cargo.toml +++ b/examples/oidc_cli/Cargo.toml @@ -29,3 +29,6 @@ features = ["experimental-oidc"] [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/persist_session/Cargo.toml b/examples/persist_session/Cargo.toml index 8478f4e7420..cec117820bc 100644 --- a/examples/persist_session/Cargo.toml +++ b/examples/persist_session/Cargo.toml @@ -23,3 +23,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/qr-login/Cargo.toml b/examples/qr-login/Cargo.toml index 445e5384418..79fde05dfec 100644 --- a/examples/qr-login/Cargo.toml +++ b/examples/qr-login/Cargo.toml @@ -23,3 +23,6 @@ url = "2.3.1" # have copied the example as it was at the time of the release you use. path = "../../crates/matrix-sdk" features = ["experimental-oidc"] + +[package.metadata.release] +release = false diff --git a/examples/secret_storage/Cargo.toml b/examples/secret_storage/Cargo.toml index 0b0466721a1..a5805b35b89 100644 --- a/examples/secret_storage/Cargo.toml +++ b/examples/secret_storage/Cargo.toml @@ -21,3 +21,6 @@ matrix-sdk = { path = "../../crates/matrix-sdk" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/examples/timeline/Cargo.toml b/examples/timeline/Cargo.toml index 0150f4c7718..4db0b16e538 100644 --- a/examples/timeline/Cargo.toml +++ b/examples/timeline/Cargo.toml @@ -23,3 +23,6 @@ matrix-sdk-ui = { path = "../../crates/matrix-sdk-ui" } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/labs/multiverse/Cargo.toml b/labs/multiverse/Cargo.toml index 29098ea9193..8b367cb8f5b 100644 --- a/labs/multiverse/Cargo.toml +++ b/labs/multiverse/Cargo.toml @@ -27,3 +27,6 @@ tracing-subscriber = { workspace = true, features = ["env-filter"] } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/release.toml b/release.toml new file mode 100644 index 00000000000..8d55f8b0dca --- /dev/null +++ b/release.toml @@ -0,0 +1,10 @@ +owners = ["poljar", "github:matrix-org:rust"] + +pre-release-commit-message = "chore: Release matrix-sdk version {{version}}" +pre-release-replacements = [] +pre-release-hook = [] + +sign-tag = true +tag-message = "Release {{crate_name}} version {{version}}" +tag-name = "{{prefix}}{{version}}" +shared-version = true diff --git a/testing/matrix-sdk-integration-testing/Cargo.toml b/testing/matrix-sdk-integration-testing/Cargo.toml index 12d7fa3ce95..6620320bb3e 100644 --- a/testing/matrix-sdk-integration-testing/Cargo.toml +++ b/testing/matrix-sdk-integration-testing/Cargo.toml @@ -35,3 +35,6 @@ json-structural-diff = "0.1.0" [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/testing/matrix-sdk-test-macros/Cargo.toml b/testing/matrix-sdk-test-macros/Cargo.toml index 770ffac4cb6..efe8c261387 100644 --- a/testing/matrix-sdk-test-macros/Cargo.toml +++ b/testing/matrix-sdk-test-macros/Cargo.toml @@ -22,3 +22,6 @@ syn = { version = "2.0.43", features = ["full", "extra-traits"] } [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/testing/matrix-sdk-test/Cargo.toml b/testing/matrix-sdk-test/Cargo.toml index 5d4bb62f017..7c1aa7391dd 100644 --- a/testing/matrix-sdk-test/Cargo.toml +++ b/testing/matrix-sdk-test/Cargo.toml @@ -35,3 +35,6 @@ wasm-bindgen-test = "0.3.33" [lints] workspace = true + +[package.metadata.release] +release = false diff --git a/uniffi-bindgen/Cargo.toml b/uniffi-bindgen/Cargo.toml index a7a51a7e19d..fb92ab76d9f 100644 --- a/uniffi-bindgen/Cargo.toml +++ b/uniffi-bindgen/Cargo.toml @@ -7,3 +7,6 @@ license = "Apache-2.0" [dependencies] uniffi = { workspace = true, features = ["cli"] } + +[package.metadata.release] +release = false diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 94f1bae3055..d6c00f0e071 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -17,3 +17,6 @@ serde_json = { workspace = true } fs_extra = "1" uniffi_bindgen = { workspace = true } xshell = "0.1.17" + +[package.metadata.release] +release = false From 26a2b833809f6f0125f22cdde41b84708a846868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 9 Oct 2024 12:15:30 +0200 Subject: [PATCH 2/7] Add a git-cliff configuration file --- cliff-weekly-report.toml | 47 +++++++++++++++++++++ cliff.toml | 89 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 cliff-weekly-report.toml create mode 100644 cliff.toml diff --git a/cliff-weekly-report.toml b/cliff-weekly-report.toml new file mode 100644 index 00000000000..bfd0732c68f --- /dev/null +++ b/cliff-weekly-report.toml @@ -0,0 +1,47 @@ +# This git-cliff configuration file is used to generate weekly reports for This +# Week in Matrix amongst others. + +[changelog] +header = """ +# This Week in the Matrix Rust SDK ({{ now() | date(format="%Y-%m-%d") }}) +""" +body = """ +{% for commit in commits %} + {% set_global commit_message = commit.message -%} + {% for footer in commit.footers -%} + {% if footer.token | lower == "changelog" -%} + {% set_global commit_message = footer.value -%} + {% elif footer.token | lower == "breaking-change" -%} + {% set_global commit_message = footer.value -%} + {% endif -%} + {% endfor -%} + - {{ commit_message | upper_first }} +{% endfor %} +""" +trim = true +footer = "" + +[git] +conventional_commits = true +filter_unconventional = true +commit_preprocessors = [ + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](https://github.com/matrix-org/matrix-rust-sdk/pull/${2}))"}, +] +commit_parsers = [ + { message = "^feat", group = "Features" }, + { message = "^fix", group = "Bug Fixes" }, + { message = "^doc", group = "Documentation" }, + { message = "^perf", group = "Performance" }, + { message = "^refactor", group = "Refactor", skip = true }, + { message = "^chore\\(release\\): prepare for", skip = true }, + { message = "^chore", skip = true }, + { message = "^style", group = "Styling", skip = true }, + { message = "^test", skip = true }, + { message = "^ci", skip = true }, +] +filter_commits = true +tag_pattern = "[0-9]*" +skip_tags = "" +ignore_tags = "" +date_order = false +sort_commits = "newest" diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 00000000000..b81994cffeb --- /dev/null +++ b/cliff.toml @@ -0,0 +1,89 @@ +# This git-cliff configuration file is used to generate release reports. + +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file.\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/ +body = """ +{% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %}\ + ## [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + {% set_global commit_message = commit.message -%} + {% set_global breaking = commit.breaking -%} + {% for footer in commit.footers -%} + {% if footer.token | lower == "changelog" -%} + {% set_global commit_message = footer.value -%} + {% elif footer.token | lower == "breaking-change" -%} + {% set_global commit_message = footer.value -%} + {% elif footer.token | lower == "security-impact" -%} + {% set_global security_impact = footer.value -%} + {% elif footer.token | lower == "cve" -%} + {% set_global cve = footer.value -%} + {% elif footer.token | lower == "github-advisory" -%} + {% set_global github_advisory = footer.value -%} + {% endif -%} + {% endfor -%} + - {% if breaking %}[**breaking**] {% endif %}{{ commit_message | upper_first }} + {% if security_impact -%} + (\ + *{{ security_impact | upper_first }}*\ + {% if cve -%}, [{{ cve | upper }}](https://www.cve.org/CVERecord?id={{ cve }}){% endif -%}\ + {% if github_advisory -%}, [{{ github_advisory | upper }}](https://github.com/matrix-org/matrix-rust-sdk/security/advisories/{{ github_advisory }}){% endif -%} + ) + {% endif -%} + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# regex for preprocessing the commit messages +commit_preprocessors = [ + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](https://github.com/matrix-org/matrix-rust-sdk/pull/${2}))"}, +] +# regex for parsing and grouping commits +commit_parsers = [ + { footer = "Security-Impact:", group = "Security" }, + { footer = "CVE:", group = "Security" }, + { footer = "GitHub-Advisory:", group = "Security" }, + { message = "^feat", group = "Features" }, + { message = "^fix", group = "Bug Fixes" }, + { message = "^doc", group = "Documentation" }, + { message = "^perf", group = "Performance" }, + { message = "^refactor", group = "Refactor" }, + { message = "^chore\\(release\\): prepare for", skip = true }, + { message = "^chore", skip = true }, + { message = "^style", group = "Styling", skip = true }, + { message = "^test", skip = true }, + { message = "^ci", skip = true }, +] +# filter out the commits that are not matched by commit parsers +filter_commits = true +# glob pattern for matching git tags +tag_pattern = "[0-9]*" +# regex for skipping tags +skip_tags = "" +# regex for ignoring tags +ignore_tags = "" +# sort the tags chronologically +date_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" From f069edd910b0775019852670a717f5d2d7d52472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 9 Oct 2024 12:16:26 +0200 Subject: [PATCH 3/7] Create some missing changelog files --- crates/matrix-sdk-base/CHANGELOG.md | 4 ++++ crates/matrix-sdk-common/CHANGELOG.md | 4 ++++ crates/matrix-sdk-indexeddb/CHANGELOG.md | 4 ++++ crates/matrix-sdk-qrcode/CHANGELOG.md | 4 ++++ crates/matrix-sdk-sqlite/CHANGELOG.md | 4 ++++ crates/matrix-sdk-store-encryption/CHANGELOG.md | 4 ++++ crates/matrix-sdk-ui/CHANGELOG.md | 4 ++++ 7 files changed, 28 insertions(+) create mode 100644 crates/matrix-sdk-common/CHANGELOG.md create mode 100644 crates/matrix-sdk-qrcode/CHANGELOG.md create mode 100644 crates/matrix-sdk-sqlite/CHANGELOG.md create mode 100644 crates/matrix-sdk-store-encryption/CHANGELOG.md diff --git a/crates/matrix-sdk-base/CHANGELOG.md b/crates/matrix-sdk-base/CHANGELOG.md index dab46a947fc..aebdc82fe75 100644 --- a/crates/matrix-sdk-base/CHANGELOG.md +++ b/crates/matrix-sdk-base/CHANGELOG.md @@ -1,3 +1,7 @@ +# Changelog + +All notable changes to this project will be documented in this file. + # unreleased - Add `BaseClient::room_key_recipient_strategy` field diff --git a/crates/matrix-sdk-common/CHANGELOG.md b/crates/matrix-sdk-common/CHANGELOG.md new file mode 100644 index 00000000000..ba8118892a2 --- /dev/null +++ b/crates/matrix-sdk-common/CHANGELOG.md @@ -0,0 +1,4 @@ +# Changelog + +All notable changes to this project will be documented in this file. + diff --git a/crates/matrix-sdk-indexeddb/CHANGELOG.md b/crates/matrix-sdk-indexeddb/CHANGELOG.md index 7e5e0be9498..993b6152e47 100644 --- a/crates/matrix-sdk-indexeddb/CHANGELOG.md +++ b/crates/matrix-sdk-indexeddb/CHANGELOG.md @@ -1,3 +1,7 @@ +# Changelog + +All notable changes to this project will be documented in this file. + # UNRELEASED - Improve the efficiency of objects stored in the crypto store. diff --git a/crates/matrix-sdk-qrcode/CHANGELOG.md b/crates/matrix-sdk-qrcode/CHANGELOG.md new file mode 100644 index 00000000000..ba8118892a2 --- /dev/null +++ b/crates/matrix-sdk-qrcode/CHANGELOG.md @@ -0,0 +1,4 @@ +# Changelog + +All notable changes to this project will be documented in this file. + diff --git a/crates/matrix-sdk-sqlite/CHANGELOG.md b/crates/matrix-sdk-sqlite/CHANGELOG.md new file mode 100644 index 00000000000..ba8118892a2 --- /dev/null +++ b/crates/matrix-sdk-sqlite/CHANGELOG.md @@ -0,0 +1,4 @@ +# Changelog + +All notable changes to this project will be documented in this file. + diff --git a/crates/matrix-sdk-store-encryption/CHANGELOG.md b/crates/matrix-sdk-store-encryption/CHANGELOG.md new file mode 100644 index 00000000000..ba8118892a2 --- /dev/null +++ b/crates/matrix-sdk-store-encryption/CHANGELOG.md @@ -0,0 +1,4 @@ +# Changelog + +All notable changes to this project will be documented in this file. + diff --git a/crates/matrix-sdk-ui/CHANGELOG.md b/crates/matrix-sdk-ui/CHANGELOG.md index 55f9cb79440..1068434a5a6 100644 --- a/crates/matrix-sdk-ui/CHANGELOG.md +++ b/crates/matrix-sdk-ui/CHANGELOG.md @@ -1,3 +1,7 @@ +# Changelog + +All notable changes to this project will be documented in this file. + # unreleased Breaking changes: From 1caf697f6ebb4a1a143202b96aa51ec0c4a01a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 9 Oct 2024 12:17:30 +0200 Subject: [PATCH 4/7] Create an xtask for the release handling --- xtask/src/main.rs | 5 ++ xtask/src/release.rs | 187 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 xtask/src/release.rs diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 73da0704f10..132335cc57a 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,6 +1,7 @@ mod ci; mod fixup; mod kotlin; +mod release; mod swift; mod workspace; @@ -8,6 +9,7 @@ use ci::CiArgs; use clap::{Parser, Subcommand}; use fixup::FixupArgs; use kotlin::KotlinArgs; +use release::ReleaseArgs; use swift::SwiftArgs; use xshell::cmd; @@ -33,6 +35,8 @@ enum Command { #[clap(long)] open: bool, }, + /// Prepare and publish a release of the matrix-sdk crates + Release(ReleaseArgs), Swift(SwiftArgs), Kotlin(KotlinArgs), } @@ -44,6 +48,7 @@ fn main() -> Result<()> { Command::Doc { open } => build_docs(open.then_some("--open"), DenyWarnings::No), Command::Swift(cfg) => cfg.run(), Command::Kotlin(cfg) => cfg.run(), + Command::Release(cfg) => cfg.run(), } } diff --git a/xtask/src/release.rs b/xtask/src/release.rs new file mode 100644 index 00000000000..d31b49b8509 --- /dev/null +++ b/xtask/src/release.rs @@ -0,0 +1,187 @@ +use std::env; + +use clap::{Args, Subcommand, ValueEnum}; +use xshell::{cmd, pushd}; + +use crate::{workspace, Result}; + +#[derive(Args)] +pub struct ReleaseArgs { + #[clap(subcommand)] + cmd: ReleaseCommand, +} + +#[derive(PartialEq, Subcommand)] +enum ReleaseCommand { + /// Prepare the release of the matrix-sdk workspace. + /// + /// This command will update the `README.md`, prepend the `CHANGELOG.md` + /// file using `git cliff`, and bump the versions in the `Cargo.toml` + /// files. + Prepare { + /// What type of version bump we should perform. + version: ReleaseVersion, + /// Actually prepare a release. Dry-run mode is the default. + #[clap(long)] + execute: bool, + }, + /// Publish the release. + /// + /// This command will create signed tags, publish the release on crates.io, + /// and finally push the tags to the repo. + Publish { + /// Actually publish a release. Dry-run mode is the default + #[clap(long)] + execute: bool, + }, + /// Get a list of interesting changes that happened in the last week. + WeeklyReport, + /// Generate the changelog for a specific crate, this shouldn't be run + /// manually, cargo-release will call this. + #[clap(hide = true)] + Changelog, +} + +#[derive(Clone, Copy, Debug, Default, PartialEq, ValueEnum)] +enum ReleaseVersion { + // TODO: Add a Major variant here once we're stable. + /// Create a new minor release. + #[default] + Minor, + /// Create a new patch release. + Patch, + /// Create a new release candidate. + Rc, +} + +impl ReleaseVersion { + fn as_str(&self) -> &str { + match self { + ReleaseVersion::Minor => "minor", + ReleaseVersion::Patch => "patch", + ReleaseVersion::Rc => "rc", + } + } +} + +impl ReleaseArgs { + pub fn run(self) -> Result<()> { + check_prerequisites(); + + // The changelog needs to be generated from the directory of the crate, + // `cargo-release` changes the directory for us but we need to + // make sure to not switch back to the workspace dir. + // + // More info: https://git-cliff.org/docs/usage/monorepos + if self.cmd != ReleaseCommand::Changelog { + let _p = pushd(workspace::root_path()?)?; + } + + match self.cmd { + ReleaseCommand::Prepare { version, execute } => prepare(version, execute), + ReleaseCommand::Publish { execute } => publish(execute), + ReleaseCommand::WeeklyReport => weekly_report(), + ReleaseCommand::Changelog => changelog(), + } + } +} + +fn check_prerequisites() { + if cmd!("cargo release --version").echo_cmd(false).ignore_stdout().run().is_err() { + eprintln!("This command requires cargo-release, please install it."); + eprintln!("More info can be found at: https://github.com/crate-ci/cargo-release?tab=readme-ov-file#install"); + + std::process::exit(1); + } + + if cmd!("git cliff --version").echo_cmd(false).ignore_stdout().run().is_err() { + eprintln!("This command requires git-cliff, please install it."); + eprintln!("More info can be found at: https://git-cliff.org/docs/installation/"); + + std::process::exit(1); + } +} + +fn prepare(version: ReleaseVersion, execute: bool) -> Result<()> { + let cmd = cmd!("cargo release --no-publish --no-tag --no-push"); + + let cmd = if execute { cmd.arg("--execute") } else { cmd }; + let cmd = cmd.arg(version.as_str()); + + cmd.run()?; + + if execute { + eprintln!( + "Please double check the changelogs and edit them if necessary, \ + publish the PR, and once it's merged, switch to `main` and pull the PR \ + and run `cargo xtask release publish`" + ); + } + + Ok(()) +} + +fn publish(execute: bool) -> Result<()> { + let cmd = cmd!("cargo release tag"); + let cmd = if execute { cmd.arg("--execute") } else { cmd }; + cmd.run()?; + + let cmd = cmd!("cargo release publish"); + let cmd = if execute { cmd.arg("--execute") } else { cmd }; + cmd.run()?; + + let cmd = cmd!("cargo release push"); + let cmd = if execute { cmd.arg("--execute") } else { cmd }; + cmd.run()?; + + Ok(()) +} + +fn weekly_report() -> Result<()> { + let lines = cmd!("git log --pretty=format:%H --since='1 week ago'").read()?; + + let Some(start) = lines.split_whitespace().last() else { + panic!("Could not find a start range for the git commit range.") + }; + + cmd!("git cliff --config cliff-weekly-report.toml {start}..HEAD").run()?; + + Ok(()) +} + +/// Generate the changelog for a given crate. +/// +/// This will be called by `cargo-release` and it will set the correct +/// environment and call it from within the correct directory. +fn changelog() -> Result<()> { + let dry_run = env::var("DRY_RUN").map(|dry| str::parse::(&dry)).unwrap_or(Ok(true))?; + let crate_name = env::var("CRATE_NAME").expect("CRATE_NAME must be set"); + let new_version = env::var("NEW_VERSION").expect("NEW_VERSION must be set"); + + if dry_run { + println!( + "\nGenerating a changelog for {} (dry run), the following output will be prepended to the CHANGELOG.md file:\n", + crate_name + ); + } else { + println!("Generating a changelog for {}.", crate_name); + } + + let command = cmd!("git cliff") + .arg("cliff") + .arg("--config") + .arg("../../cliff.toml") + .arg("--include-path") + .arg(format!("crates/{}/**/*", crate_name)) + .arg("--repository") + .arg("../../") + .arg("--unreleased") + .arg("--tag") + .arg(&new_version); + + let command = if dry_run { command } else { command.arg("--prepend").arg("CHANGELOG.md") }; + + command.run()?; + + Ok(()) +} From adc121e65029baeae158e952ce8d73431de67416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 9 Oct 2024 12:26:19 +0200 Subject: [PATCH 5/7] Call git-cliff as a pre-release hook --- release.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.toml b/release.toml index 8d55f8b0dca..9de2b7e4cfc 100644 --- a/release.toml +++ b/release.toml @@ -2,7 +2,7 @@ owners = ["poljar", "github:matrix-org:rust"] pre-release-commit-message = "chore: Release matrix-sdk version {{version}}" pre-release-replacements = [] -pre-release-hook = [] +pre-release-hook = ["cargo", "xtask", "release", "changelog"] sign-tag = true tag-message = "Release {{crate_name}} version {{version}}" From 176fb318ccce66df5bfd53038dc49014c23bdbb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 9 Oct 2024 12:23:23 +0200 Subject: [PATCH 6/7] Document the new release process --- RELEASE.md | 21 --------------------- RELEASING.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 21 deletions(-) delete mode 100644 RELEASE.md create mode 100644 RELEASING.md diff --git a/RELEASE.md b/RELEASE.md deleted file mode 100644 index 25a486e9e29..00000000000 --- a/RELEASE.md +++ /dev/null @@ -1,21 +0,0 @@ -# Releasing `matrix-rust-sdk` - -- Make sure to bump all the crates to *the same version number*, and commit that (along with the - changes to the `Cargo.lock` file). -- Create a `git tag` for the current version, following the format `major.minor.patch`, e.g. `0.7.0`. -- Push the tag: `git push origin 0.7.0` -- Publish all the crates, in topological order of the dependency tree: - -``` -cargo publish -p matrix-sdk-test-macros -cargo publish -p matrix-sdk-test -cargo publish -p matrix-sdk-common -cargo publish -p matrix-sdk-qrcode -cargo publish -p matrix-sdk-store-encryption -cargo publish -p matrix-sdk-crypto -cargo publish -p matrix-sdk-base -cargo publish -p matrix-sdk-sqlite -cargo publish -p matrix-sdk-indexeddb -cargo publish -p matrix-sdk -cargo publish -p matrix-sdk-ui -``` diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 00000000000..fadd5b76aae --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,47 @@ +# Releasing and publishing the SDK + +While the release process can be handled manually, `cargo-release` has been +configured to make it more convenient. + +By default, [`cargo-release`](https://github.com/crate-ci/cargo-release) assumes +that no pull request is required to cut a release. However, since the SDK +repo is set up so that each push requires a pull request, we need to slightly +deviate from the default workflow. A `cargo-xtask` has been created to make the +process as smooth as possible. + +The procedure is as follows: + +1. Switch to a release branch: + + ```bash + git switch -c release-x.y.z +  ``` + +2. Prepare the release. This will update the `README.md`, prepend the `CHANGELOG.md` + file using `git cliff`, and bump the version in the `Cargo.toml` file. + +```bash +cargo xtask release prepare --execute minor|patch|rc +``` + +3. Double-check and edit the `CHANGELOG.md` and `README.md` if necessary. Once you are + satisfied, push the branch and open a PR. + +```bash +git push --set-upstream origin/release-x.y.z +``` + +4. Pass the review and merge the branch as you would with any other branch. + +5. Create tags for your new release, publish the release on crates.io and push + the tags: + +```bash +# Switch to main first. +git switch main +# Pull in the now-merged release commit(s). +git pull +# Create tags, publish the release on crates.io, and push the tags. +cargo xtask release publish --execute +``` +For more information on cargo-release: https://github.com/crate-ci/cargo-release From ff2323cfa0746488655cee00e4ee97386dfef98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 3 Oct 2024 14:15:05 +0200 Subject: [PATCH 7/7] Update the contributing guide with our new git-cliff setup Co-authored-by: Ivan Enderlin --- CONTRIBUTING.md | 119 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 26 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0e09da0c6f1..9e3313cd9b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,43 +29,110 @@ integration tests that need a running synapse instance. These tests reside in [README](./testing/matrix-sdk-integration-testing/README.md) to easily set up a synapse for testing purposes. -## Commit messages and PR title guidelines -Ideally, a PR should have a *proper title*, with *atomic logical commits*, and each commit -should have a *good commit message*. +## Pull requests -An *atomic logical commit* is one that is ideally small, can be compiled in isolation, and passes -tests. This is useful to make the review process easier (help your reviewer), but also when running -bisections, helping identifying which commit introduced a regression. +Ideally, a PR should have a *proper title*, with *atomic logical commits*, and +each commit should have a *good commit message*. -A *good commit message* should be composed of: +A *proper PR title* would be a one-liner summary of the changes in the PR, +following the same guidelines of a good commit message, including the +area/feature prefix. Something like `FFI: Allow logs files to be pruned.` would +be a good PR title. -- a prefix to indicate which area/feature is related by the commit -- a short description that would give sufficient context for a reviewer to guess what the commit is - about. +(An additional bad example of a bad PR title would be `mynickname/branch name`, +that is, just the branch name.) -Examples of commit messages that aren't so useful: +# Writing changelog entries -- “add new method“ -- “enhance performance“ -- “fix receipts“ +We aim to maintain clear and informative changelogs that accurately reflect the +changes in our project. This guide will help you write useful changelog entries +using git-cliff, which fetches changelog entries from commit messages. -Examples of good commit messages: +## Commit message format -- “ffi: Add new method `frobnicate_the_foos`” -- “indexeddb: Break up the request inside `get_inbound_group_sessions`” -- “read_receipts: Store receipts locally, fixing #12345” +Commit messages should be formatted as Conventional Commits. In addition, some +git trailers are supported and have special meaning (see below). -A *proper PR title* would be a one-liner summary of the changes in the PR, following the -same guidelines of a good commit message, including the area/feature prefix. Something like -`FFI: Allow logs files to be pruned.` would be a good PR title. +### Conventional commits -(An additional bad example of a bad PR title would be `mynickname/branch name`, that is, just the -branch name.) +Conventional Commits are structured as follows: -Having good commit messages and PR titles also helps with reviews, scanning the `git log` of -the project, and writing the [*This week in -Matrix*](https://matrix.org/category/this-week-in-matrix/) updates for the SDK. +``` +(): +``` + +The type of changes which will be included in changelogs is one of the following: + +* `feat`: A new feature +* `fix`: A bug fix +* `doc`: Documentation changes +* `refactor`: Code refactoring +* `perf`: Performance improvements +* `ci`: Changes to CI configuration files and scripts + +The scope is optional and can specify the area of the codebase affected (e.g., +olm, cipher). + +### Changelog trailer + +In addition to the Conventional Commit format, you can use the `Changelog` git +trailer to specify the changelog message explicitly. When that trailer is +present, its value will be used as the changelog entry instead of the commit's +leading line. The `Breaking-Change` git trailer can be used in a similar manner +if the changelog entry should be marked as a breaking change. + + +#### Example commit message + +``` +feat: Add a method to encode Ed25519 public keys to Base64 + +This patch adds the `Ed25519PublicKey::to_base64()` method, which allows us to +stringify Ed25519 and thus present them to users. It's also commonly used when +Ed25519 keys need to be inserted into JSON. + +Changelog: Added the `Ed25519PublicKey::to_base64()` method which can be used to +stringify the Ed25519 public key. +``` + +In this commit message, the content specified in the `Changelog` trailer will be +used for the changelog entry. + +### Security fixes + +Commits addressing security vulnerabilities must include specific trailers for +vulnerability metadata. These commits are required to include at least the +`Security-Impact` trailer to indicate that the commit is a security fix. + +Security issues have some additional git-trailers: + +* `Security-Impact`: The magnitude of harm that can be expected, i.e. low/moderate/high/critical. +* `CVE`: The CVE that was assigned to this issue. +* `GitHub-Advisory`: The GitHub advisory identifier. + +Example: + +``` +fix(crypto): Use a constant-time Base64 encoder for secret key material + +This patch fixes a security issue around a side-channel vulnerability[1] +when decoding secret key material using Base64. + +In some circumstances an attacker can obtain information about secret +secret key material via a controlled-channel and side-channel attack. + +This patch avoids the side-channel by switching to the base64ct crate +for the encoding, and more importantly, the decoding of secret key +material. + +Security-Impact: Low +CVE: CVE-2024-40640 +GitHub-Advisory: GHSA-j8cm-g7r6-hfpq + +Changelog: Use a constant-time Base64 encoder for secret key material +to mitigate side-channel attacks leaking secret key material. +``` ## Review process