Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 23 additions & 5 deletions .samples/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
52 changes: 42 additions & 10 deletions .samples/variants.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,74 @@
"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
},
{
"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"
]
}
]
},
{
"branch": "full-dev",
"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"
]
}
]
}
]