From 4561e7ee9c654db9423ad5e56ca7861b4a4b4cc6 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 27 Oct 2024 15:32:24 +0000 Subject: [PATCH 1/3] Make `overwritable` experimental behind a cargo feature --- .github/workflows/ISSUE_TEMPLATE/main.md | 9 ++++++ .github/workflows/ci.yml | 8 ++--- bon-macros/Cargo.toml | 3 ++ .../builder/builder_gen/member/config/mod.rs | 14 ++++++++ .../builder_gen/top_level_config/on.rs | 14 ++++++++ bon/Cargo.toml | 16 ++++++++++ e2e-tests/Cargo.toml | 2 +- website/changelog.md | 1 + website/infra/README.md | 32 ++++++++++++++++++- 9 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/ISSUE_TEMPLATE/main.md diff --git a/.github/workflows/ISSUE_TEMPLATE/main.md b/.github/workflows/ISSUE_TEMPLATE/main.md new file mode 100644 index 00000000..932af789 --- /dev/null +++ b/.github/workflows/ISSUE_TEMPLATE/main.md @@ -0,0 +1,9 @@ + + + + + + +### A note for the community from the maintainers + +Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to help the maintainers with prioritizing it. You may add a comment describing your real use case related to this issue for us to better understand the problem domain. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0f87940..03ecb476 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,10 +95,10 @@ jobs: - run: cargo test --locked --all-features --all-targets - run: cargo test --locked --all-features --doc - - run: cd bon && cargo test --locked --no-default-features --features= - - run: cd bon && cargo test --locked --no-default-features --features=alloc - - run: cd bon && cargo test --locked --no-default-features --features=implied-bounds - - run: cd bon && cargo test --locked --no-default-features --features=alloc,implied-bounds + - run: cd bon && cargo test --locked --no-default-features --features=experimental-overwritable + - run: cd bon && cargo test --locked --no-default-features --features=experimental-overwritable,alloc + - run: cd bon && cargo test --locked --no-default-features --features=experimental-overwritable,implied-bounds + - run: cd bon && cargo test --locked --no-default-features --features=experimental-overwritable,alloc,implied-bounds test-msrv: runs-on: ${{ matrix.os }}-latest diff --git a/bon-macros/Cargo.toml b/bon-macros/Cargo.toml index 5f8e88da..bb54fa34 100644 --- a/bon-macros/Cargo.toml +++ b/bon-macros/Cargo.toml @@ -63,6 +63,9 @@ rustversion = "1.0" [features] default = [] +# See the docs on this feature in the `bon`'s crate `Cargo.toml` +experimental-overwritable = [] + # See the docs on this feature in the `bon`'s crate `Cargo.toml` implied-bounds = [] diff --git a/bon-macros/src/builder/builder_gen/member/config/mod.rs b/bon-macros/src/builder/builder_gen/member/config/mod.rs index f212ce85..033774da 100644 --- a/bon-macros/src/builder/builder_gen/member/config/mod.rs +++ b/bon-macros/src/builder/builder_gen/member/config/mod.rs @@ -178,6 +178,20 @@ impl MemberConfig { } pub(crate) fn validate(&self, origin: MemberOrigin) -> Result { + if !cfg!(feature = "experimental-overwritable") && self.overwritable.is_present() { + bail!( + &self.overwritable.span(), + "🔬 `overwritable` attribute is experimental and requires \ + \"experimental-overwritable\" cargo feature to be enabled; \ + we would be glad to make this attribute stable if you find it useful; \ + please leave a 👍 reaction under the issue https://github.com/elastio/bon/issues/149 \ + to help us measure the demand for this feature; it would be \ + double-awesome if you could also describe your use case in \ + a comment under the issue for us to understand how it's used \ + in practice", + ); + } + if self.start_fn.is_present() { self.validate_mutually_allowed( ParamName::StartFn, diff --git a/bon-macros/src/builder/builder_gen/top_level_config/on.rs b/bon-macros/src/builder/builder_gen/top_level_config/on.rs index f3e624a8..23118e50 100644 --- a/bon-macros/src/builder/builder_gen/top_level_config/on.rs +++ b/bon-macros/src/builder/builder_gen/top_level_config/on.rs @@ -28,6 +28,20 @@ impl Parse for OnConfig { let parsed = Parsed::from_meta(&syn::parse_quote!(on(#rest)))?; + if !cfg!(feature = "experimental-overwritable") && parsed.overwritable.is_present() { + return Err(syn::Error::new( + parsed.overwritable.span(), + "🔬 `overwritable` attribute is experimental and requires \ + \"experimental-overwritable\" cargo feature to be enabled; \ + we would be glad to make this attribute stable if you find it useful; \ + please leave a 👍 reaction under the issue https://github.com/elastio/bon/issues/149 \ + to help us measure the demand for this feature; it would be \ + double-awesome if you could also describe your use case in \ + a comment under the issue for us to understand how it's used \ + in practice", + )); + } + { // Validate that at least some option was enabled. // This lives in a separate block to make sure that if a new diff --git a/bon/Cargo.toml b/bon/Cargo.toml index e124004a..84a88077 100644 --- a/bon/Cargo.toml +++ b/bon/Cargo.toml @@ -102,3 +102,19 @@ std = ["alloc"] # # Huge thanks to @harudagondi for suggesting the name of this cargo feature! implied-bounds = ["bon-macros/implied-bounds"] + +# 🔬 Experimental! There may be breaking changes to this feature between *minor* releases, +# however, compatibility within patch releases is guaranteed though. +# +# This feature enables the #[builder(overwritable)] attribute that can be used to +# allow overwriting already set fields in the builder. Without this attribute it's +# not possible to set the same member twice in the builder, a compile error would be +# generated. +# +# See more info at https://bon-rs.com/reference/builder/top-level/overwritable. +# +# We are considering stabilizing this attribute if you have a use for it. Please leave +# a 👍 reaction under the issue https://github.com/elastio/bon/issues/149 if you need +# this attribute. It would also be cool if you could leave a comment under that issue +# describing your use case for it. +experimental-overwritable = ["bon-macros/experimental-overwritable"] diff --git a/e2e-tests/Cargo.toml b/e2e-tests/Cargo.toml index d6f097d2..9b19bde9 100644 --- a/e2e-tests/Cargo.toml +++ b/e2e-tests/Cargo.toml @@ -18,7 +18,7 @@ edition = "2021" workspace = true [dependencies] -bon = { path = "../bon" } +bon = { path = "../bon", features = ["experimental-overwritable"] } [dev-dependencies] anyhow = "1.0" diff --git a/website/changelog.md b/website/changelog.md index 27894415..5e867af2 100644 --- a/website/changelog.md +++ b/website/changelog.md @@ -45,6 +45,7 @@ All the breaking changes are very unlikely to actually break your code that was - Add graceful internal panic handling. If some `bon` macro panics due to an internal bug, the macro will try to still generate a fallback for IDEs to still provide intellisense ([#145](https://github.com/elastio/bon/pull/145)) - Switch from `elastio.github.io/bon` to a custom domain `bon-rs.com` ([#158](https://github.com/elastio/bon/pull/158)) +- Add anonymous stats with [`umami`](https://umami.is/) for the docs website ([#158](https://github.com/elastio/bon/pull/158)) ## [2.3.0](https://github.com/elastio/bon/compare/v2.2.1...v2.3.0) - 2024-09-14 diff --git a/website/infra/README.md b/website/infra/README.md index e919ebd6..d1ada6db 100644 --- a/website/infra/README.md +++ b/website/infra/README.md @@ -1,5 +1,35 @@ # umami backend -This directory contains the deployment code for our [umami](https://umami.is/) backend used for collecting anonymous statics about the usage of our documentation website. The code for this lives here in the open for the sake of transparency and sharing (in case if you want to self-host your own umami instance on Hetzner). +This directory contains the deployment code for our [umami](https://umami.is/) backend used for collecting anonymous statics about the usage of our documentation website. This code lives here in the open for the sake of transparency and sharing (in case if you want to self-host your own umami instance on Hetzner). It is a simple Hetzner VPS that runs a docker-compose cluster with the umami service and Postgres. The data is stored on a separate volume. The server is allocated a static IPv4. + +## Deployment + +Prerequisites: +- [Terraform CLI](https://developer.hashicorp.com/terraform/install) +- [Account at hetzner.com/cloud](https://hetzner.com/cloud) + +Create a `terraform.tfvars` file in this directory. Here is an example below, make sure to replace all `{...}` placeholders with your values. + +```tf +hcloud_token = "{token_value}" + +allowed_ssh_ips = ["{your_ip_here}/32"] + +pg_password = "{pg_password_value}" + +umami_app_secret = "{umami_app_secret_value}" +``` + +Initialize terraform plugin directory and modules: + +```bash +terraform init +``` + +Run the deployment: + +```bash +terraform apply +``` From b66f8c452f61259040c960d8b215e0712c00d97c Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 27 Oct 2024 15:39:56 +0000 Subject: [PATCH 2/3] Fix --- benchmarks/compilation/Cargo.toml | 2 +- scripts/test-msrv.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/benchmarks/compilation/Cargo.toml b/benchmarks/compilation/Cargo.toml index 63579d58..b0cd9680 100644 --- a/benchmarks/compilation/Cargo.toml +++ b/benchmarks/compilation/Cargo.toml @@ -12,7 +12,7 @@ edition = "2021" version = "0.1.0" [dependencies] -bon = { path = "../../bon", optional = true } +bon = { path = "../../bon", optional = true, features = ["experimental-overwritable"] } cfg-if = "1.0" derive_builder = { version = "0.20", optional = true } typed-builder = { version = "0.20", optional = true } diff --git a/scripts/test-msrv.sh b/scripts/test-msrv.sh index 04d7297f..b6332f8d 100755 --- a/scripts/test-msrv.sh +++ b/scripts/test-msrv.sh @@ -39,7 +39,7 @@ step cargo update -p windows-sys --precise 0.52.0 export RUSTFLAGS="${RUSTFLAGS:-} --allow unknown-lints" -step cargo clippy --all-targets --locked +step cargo clippy --all-targets --locked --features=experimental-overwritable test_args=( --locked @@ -57,4 +57,4 @@ test_args=( --skip ui::ui ) -step cargo test "${test_args[@]}" +step cargo test --features=experimental-overwritable "${test_args[@]}" From 991a6ea3b7c1f654f3c6011ae6bc882c46909d10 Mon Sep 17 00:00:00 2001 From: Vitalii Kryvenko Date: Sun, 27 Oct 2024 17:40:53 +0200 Subject: [PATCH 3/3] Fix wording Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- website/infra/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/infra/README.md b/website/infra/README.md index d1ada6db..bbb78291 100644 --- a/website/infra/README.md +++ b/website/infra/README.md @@ -1,6 +1,6 @@ # umami backend -This directory contains the deployment code for our [umami](https://umami.is/) backend used for collecting anonymous statics about the usage of our documentation website. This code lives here in the open for the sake of transparency and sharing (in case if you want to self-host your own umami instance on Hetzner). +This directory contains the deployment code for our [umami](https://umami.is/) backend, used for collecting anonymous statistics about the usage of our documentation website. This code lives here in the open for the sake of transparency and sharing (in case if you want to self-host your own umami instance on Hetzner). It is a simple Hetzner VPS that runs a docker-compose cluster with the umami service and Postgres. The data is stored on a separate volume. The server is allocated a static IPv4.