From 05c168e74b9f2bb4e33f8caaa3971ba262e0f02c Mon Sep 17 00:00:00 2001 From: "v.savkin" Date: Tue, 6 Oct 2026 15:08:16 +0600 Subject: [PATCH] feat: a branch's commands hold from a version of the template, so the flags of the next release wait in variants.json - variants.json: generate is a list of entries, each with "since" and its commands; the newest entry the version being generated has reached is used - the version is the release's tag, or the version.json of a branch of the template without its label (2.8.0-rc is 2.8.0); a version below every entry, or an entry with no commands, fails the generation - full from 2.8.0: Orders takes --MongoDB and --Notify email - it sends the email and, generated with -M false, unpacks the part of Common the email needs; full-dev, generated from dev, is the same - an old entry can go whenever nothing older is generated: the choice does not depend on it --- .samples/generate.sh | 28 +++++++++++++++++++---- .samples/variants.json | 52 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/.samples/generate.sh b/.samples/generate.sh index 2e86937..4e2b69e 100644 --- a/.samples/generate.sh +++ b/.samples/generate.sh @@ -6,9 +6,12 @@ # # The template comes from the release's package when it has one, from the sources at that tag or branch # otherwise. -# What to generate for each branch is in variants.json. The branch marked "default" is the repository's -# default branch: it also carries this automation (.samples/ and the regenerate workflow), so a -# regeneration of it does not delete what regenerates it. +# What to generate for each branch is in variants.json, as entries of commands, each with the version of +# the template it holds from ("since"). The newest entry the version being generated has reached is used: +# the release's tag, or the version.json of a branch of the template without its label (2.8.0-rc is 2.8.0). +# So the flags of the next release are written down before it, and an old entry goes when nothing needs it. +# The branch marked "default" is the repository's default branch: it also carries this automation +# (.samples/ and the regenerate workflow), so a regeneration of it does not delete what regenerates it. set -euo pipefail tag="$1" branch="$2" out="$3" @@ -22,16 +25,31 @@ hive=() if gh release download "$tag" -R "$template_repo" -p '*.nupkg' -D "$work/package" 2>/dev/null; then dotnet new install "$work"/package/*.nupkg --force "${hive[@]}" + version="${tag#v}" else git clone -q --depth 1 --branch "$tag" "https://github.com/$template_repo.git" "$work/template" commit=$(git -C "$work/template" rev-parse HEAD) dotnet new install "$work/template/template" --force "${hive[@]}" + version=$(jq -r .version "$work/template/version.json") + version="${version%%-*}" fi +# The newest "since" the version has reached. +newest() { printf '%s\n%s\n' "$1" "$2" | sort -V | tail -1; } +since="" +while read -r entry; do + if [ "$(newest "$entry" "$version")" = "$version" ] && { [ -z "$since" ] || [ "$(newest "$entry" "$since")" = "$entry" ]; }; then + since="$entry" + fi +done < <(jq -r --arg b "$branch" '.[] | select(.branch == $b) | .generate[].since' "$here/variants.json" | tr -d '\r') +[ -n "$since" ] || { echo "variants.json has no commands for $branch at $version" >&2; exit 1; } +echo "$branch at $version: the commands since $since" + mkdir -p "$out" cd "$out" -jq -r --arg b "$branch" '.[] | select(.branch == $b) | .generate[]' "$here/variants.json" | tr -d '\r' > "$work/commands" -[ -s "$work/commands" ] || { echo "variants.json has no branch $branch" >&2; exit 1; } +jq -r --arg b "$branch" --arg s "$since" '.[] | select(.branch == $b) | .generate[] | select(.since == $s) | .commands[]' \ + "$here/variants.json" | tr -d '\r' > "$work/commands" +[ -s "$work/commands" ] || { echo "variants.json has no commands for $branch since $since" >&2; exit 1; } while read -r args; do # Word splitting of the arguments is intended. # shellcheck disable=SC2086 diff --git a/.samples/variants.json b/.samples/variants.json index bbb7170..ed29135 100644 --- a/.samples/variants.json +++ b/.samples/variants.json @@ -3,24 +3,46 @@ "branch": "single", "about": "One service with the defaults: PostgreSQL, Hangfire, docker compose files, and CI.", "generate": [ - "-N ST -P DotNetSolutionKit.Samples -S Orders -M false --GitHubCiCd true" + { + "since": "2.7.0", + "commands": [ + "-N ST -P DotNetSolutionKit.Samples -S Orders -M false --GitHubCiCd true" + ] + } ] }, { "branch": "gateway", "about": "Two services behind a YARP gateway that validates the token and forwards the user.", "generate": [ - "-N ST -P DotNetSolutionKit.Samples -S Orders -M false --GitHubCiCd true", - "-N ST -P DotNetSolutionKit.Samples -S Billing", - "-N ST -P DotNetSolutionKit.Samples -S Gateway --ApiGateway true" + { + "since": "2.7.0", + "commands": [ + "-N ST -P DotNetSolutionKit.Samples -S Orders -M false --GitHubCiCd true", + "-N ST -P DotNetSolutionKit.Samples -S Billing", + "-N ST -P DotNetSolutionKit.Samples -S Gateway --ApiGateway true" + ] + } ] }, { "branch": "full", "about": "Every flag: the bus with an outbox, Infisical, feature flags, the API diff, access rules over a tenant tree, object storage, ClickHouse; two services.", "generate": [ - "-N ST -P DotNetSolutionKit.Samples -S Orders -M false --GitHubCiCd true --Messaging outbox -I true --DiffApi true --FeatureFlags true --HierarchyRules true --Storage true --ClickHouse true", - "-N ST -P DotNetSolutionKit.Samples -S Billing --Messaging outbox -I true --DiffApi true --FeatureFlags true --Storage true --ClickHouse true" + { + "since": "2.7.0", + "commands": [ + "-N ST -P DotNetSolutionKit.Samples -S Orders -M false --GitHubCiCd true --Messaging outbox -I true --DiffApi true --FeatureFlags true --HierarchyRules true --Storage true --ClickHouse true", + "-N ST -P DotNetSolutionKit.Samples -S Billing --Messaging outbox -I true --DiffApi true --FeatureFlags true --Storage true --ClickHouse true" + ] + }, + { + "since": "2.8.0", + "commands": [ + "-N ST -P DotNetSolutionKit.Samples -S Orders -M false --GitHubCiCd true --Messaging outbox -I true --DiffApi true --FeatureFlags true --HierarchyRules true --Storage true --ClickHouse true --MongoDB true --Notify email", + "-N ST -P DotNetSolutionKit.Samples -S Billing --Messaging outbox -I true --DiffApi true --FeatureFlags true --Storage true --ClickHouse true" + ] + } ], "default": true }, @@ -28,8 +50,13 @@ "branch": "full-alt", "about": "SQL Server, xUnit, secrets from Vault, Kubernetes manifests and the audit journal, which rides on the bus with an outbox; two services.", "generate": [ - "-N ST -P DotNetSolutionKit.Samples -S Orders -M false --GitHubCiCd true --Database mssql --TestFramework xunit --Vault true --Deploy k8s --Messaging outbox --Audit true", - "-N ST -P DotNetSolutionKit.Samples -S Billing --Database mssql --TestFramework xunit --Vault true --Deploy k8s --Messaging outbox --Audit true" + { + "since": "2.7.0", + "commands": [ + "-N ST -P DotNetSolutionKit.Samples -S Orders -M false --GitHubCiCd true --Database mssql --TestFramework xunit --Vault true --Deploy k8s --Messaging outbox --Audit true", + "-N ST -P DotNetSolutionKit.Samples -S Billing --Database mssql --TestFramework xunit --Vault true --Deploy k8s --Messaging outbox --Audit true" + ] + } ] }, { @@ -37,8 +64,13 @@ "ref": "dev", "about": "The flags of full and the ones dev adds before a release, generated from the template's dev once a day when it has moved. A red CI here is a break in dev before a release.", "generate": [ - "-N ST -P DotNetSolutionKit.Samples -S Orders -M false --GitHubCiCd true --Messaging outbox -I true --DiffApi true --FeatureFlags true --HierarchyRules true --Storage true --ClickHouse true --MongoDB true --Notify email", - "-N ST -P DotNetSolutionKit.Samples -S Billing --Messaging outbox -I true --DiffApi true --FeatureFlags true --Storage true --ClickHouse true --MongoDB true --Notify email" + { + "since": "2.8.0", + "commands": [ + "-N ST -P DotNetSolutionKit.Samples -S Orders -M false --GitHubCiCd true --Messaging outbox -I true --DiffApi true --FeatureFlags true --HierarchyRules true --Storage true --ClickHouse true --MongoDB true --Notify email", + "-N ST -P DotNetSolutionKit.Samples -S Billing --Messaging outbox -I true --DiffApi true --FeatureFlags true --Storage true --ClickHouse true" + ] + } ] } ]