Skip to content

Commit 4b614a9

Browse files
committed
Add support for version context variables
1 parent 701f2ab commit 4b614a9

File tree

7 files changed

+102
-35
lines changed

7 files changed

+102
-35
lines changed

docs/_docset.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ toc:
100100
- file: sidebars.md
101101
- file: stepper.md
102102
- file: substitutions.md
103+
- file: version-variables.md
103104
- file: sundries.md
104105
- file: tables.md
105106
- file: tabs.md

docs/syntax/version-variables.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Version Variables
2+
3+
Version are exposed during build using the `{{versions.VERSIONING_SCHEME}}` variable.
4+
5+
For example `stack` versioning variables are exposed as `{{versions.stack}}`.
6+
7+
## Specialized Suffixes.
8+
9+
Besides the current version, the following suffixes are available:
10+
11+
| Version substitution | result | purpose |
12+
|--------------------------------------|-----------------------------------|-----------------------------------------|
13+
| `{{versions.stack}}` | {{version.stack}} | Current version |
14+
| `{{versions.stack.major_minor}}` | {{version.stack.major_minor}} | Current `MAJOR.MINOR` |
15+
| `{{versions.stack.major_x}}` | {{version.stack.major_x}} | Current `MAJOR.X` |
16+
| `{{versions.stack.major_component}}` | {{version.stack.major_component}} | Current major component |
17+
| `{{versions.stack.next_major}}` | {{version.stack.next_major}} | The next major version |
18+
| `{{versions.stack.next_minor}}` | {{version.stack.next_minor}} | The next minor version |
19+
| `{{versions.stack.base}}` | {{version.stack.base}} | The first version on the new doc system |
20+
21+
22+
## Available versioning schemes.
23+
24+
This is dictated by the [version.yml](https://github.com/elastic/docs-builder/blob/main/src/Elastic.Documentation.Configuration/versions.yml) configuration file
25+
26+
* `stack`
27+
* `ece`
28+
* `ech`
29+
* `eck`
30+
* `ess`
31+
* `self`
32+
* `ecctl`
33+
* `curator`
34+
* `security`
35+
* `apm_agent_android`
36+
* `apm_agent_ios`
37+
* `apm_agent_dotnet`
38+
* `apm_agent_go`
39+
* `apm_agent_java`
40+
* `apm_agent_node`
41+
* `apm_agent_php`
42+
* `apm_agent_python`
43+
* `apm_agent_ruby`
44+
* `apm_agent_rum`
45+
* `edot_ios`
46+
* `edot_android`
47+
* `edot_dotnet`
48+
* `edot_java`
49+
* `edot_node`
50+
* `edot_php`
51+
* `edot_python`
52+
* `edot_cf_aws`
53+
* `edot_collector`
54+
55+
The following are available but should not be used. These map to serverless projects and have a fixed high version number.
56+
57+
* `all`
58+
* `serverless`
59+
* `elasticsearch`
60+
* `observability`

src/Elastic.Documentation.Configuration/BuildContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public BuildContext(
100100
DocumentationSourceDirectory = ConfigurationPath.Directory!;
101101

102102
Git = gitCheckoutInformation ?? GitCheckoutInformation.Create(DocumentationCheckoutDirectory, ReadFileSystem);
103-
Configuration = new ConfigurationFile(this);
103+
Configuration = new ConfigurationFile(this, VersionsConfig);
104104
GoogleTagManager = new GoogleTagManagerConfiguration
105105
{
106106
Enabled = false

src/Elastic.Documentation.Configuration/Builder/ConfigurationFile.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using DotNet.Globbing;
77
using Elastic.Documentation.Configuration.Suggestions;
88
using Elastic.Documentation.Configuration.TableOfContents;
9+
using Elastic.Documentation.Configuration.Versions;
910
using Elastic.Documentation.Links;
1011
using Elastic.Documentation.Navigation;
1112
using YamlDotNet.RepresentationModel;
@@ -61,7 +62,7 @@ public record ConfigurationFile : ITableOfContentsScope
6162
Project is not null
6263
&& Project.Equals("Elastic documentation", StringComparison.OrdinalIgnoreCase);
6364

64-
public ConfigurationFile(IDocumentationContext context)
65+
public ConfigurationFile(IDocumentationContext context, VersionsConfiguration versionsConfig)
6566
{
6667
_context = context;
6768
ScopeDirectory = context.ConfigurationPath.Directory!;
@@ -159,6 +160,32 @@ public ConfigurationFile(IDocumentationContext context)
159160
}
160161
}
161162

163+
foreach (var (id, system) in versionsConfig.VersioningSystems)
164+
{
165+
var name = id.ToStringFast(true);
166+
var current = system.Current;
167+
var key = $"version.{name}";
168+
_substitutions[key] = system.Current;
169+
170+
key = $"version.{name}.base";
171+
_substitutions[key] = system.Base;
172+
173+
key = $"version.{name}.major_minor";
174+
_substitutions[key] = $"{current.Major:N0}.{current.Minor:N0}";
175+
176+
key = $"version.{name}.major_x";
177+
_substitutions[key] = $"{current.Major:N0}.x";
178+
179+
key = $"version.{name}.major_component";
180+
_substitutions[key] = $"{current.Major:N0}";
181+
182+
key = $"version.{name}.next_minor";
183+
_substitutions[key] = new SemVersion(current.Major, current.Minor + 1, current.Patch, current.Prerelease, current.Metadata);
184+
185+
key = $"version.{name}.next_major";
186+
_substitutions[key] = new SemVersion(current.Major + 1, current.Minor, current.Patch, current.Prerelease, current.Metadata);
187+
}
188+
162189
var toc = new TableOfContentsConfiguration(this, sourceFile, ScopeDirectory, _context, 0, "");
163190
TableOfContents = toc.TableOfContents;
164191
Files = toc.Files;

src/Elastic.Documentation.Configuration/Versions/Version.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public enum VersioningSystemId
4444
[Display(Name = "serverless")]
4545
Serverless,
4646
[Display(Name = "elasticsearch")]
47-
Elasticsearch,
47+
ElasticsearchProject,
4848
[Display(Name = "observability")]
49-
Observability,
49+
ObservabilityProject,
5050
[Display(Name = "security")]
51-
Security,
51+
SecurityProject,
5252
[Display(Name = "apm_agent_android")]
5353
ApmAgentAndroid,
5454
[Display(Name = "apm_agent_ios")]

src/Elastic.Markdown/Myst/Components/ApplicableToComponent.cshtml

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
@RenderProduct(
7777
"Serverless Elasticsearch",
7878
"Serverless Elasticsearch projects",
79-
VersioningSystemId.Elasticsearch,
79+
VersioningSystemId.ElasticsearchProject,
8080
appliesTo.Serverless.Elasticsearch
8181
)
8282
}
@@ -86,7 +86,7 @@
8686
@RenderProduct(
8787
"Serverless Observability",
8888
"Serverless Observability projects",
89-
VersioningSystemId.Observability,
89+
VersioningSystemId.ObservabilityProject,
9090
appliesTo.Serverless.Observability
9191
)
9292
}
@@ -96,7 +96,7 @@
9696
@RenderProduct(
9797
"Serverless Security",
9898
"Serverless Security projects",
99-
VersioningSystemId.Security,
99+
VersioningSystemId.SecurityProject,
100100
appliesTo.Serverless.Security
101101
)
102102
}
@@ -112,127 +112,106 @@
112112
if (pa.Ecctl is not null)
113113
{
114114
@RenderProduct("ECCTL", "Elastic Cloud Control", VersioningSystemId.Ecctl, pa.Ecctl)
115-
;
116115
}
117116

118117
if (pa.Curator is not null)
119118
{
120119
@RenderProduct("Curator", "Curator", VersioningSystemId.Curator, pa.Curator)
121-
;
122120
}
123121

124122
if (pa.ApmAgentAndroid is not null)
125123
{
126124
@RenderProduct("APM Agent Android", "Application Performance Monitoring Agent for Android", VersioningSystemId.ApmAgentAndroid, pa.ApmAgentAndroid)
127-
;
128125
}
129126

130127
if (pa.ApmAgentDotnet is not null)
131128
{
132129
@RenderProduct("APM Agent .NET", "Application Performance Monitoring Agent for .NET", VersioningSystemId.ApmAgentDotnet, pa.ApmAgentDotnet)
133-
;
134130
}
135131

136132
if (pa.ApmAgentGo is not null)
137133
{
138134
@RenderProduct("APM Agent Go", "Application Performance Monitoring Agent for Go", VersioningSystemId.ApmAgentGo, pa.ApmAgentGo)
139-
;
140135
}
141136

142137
if (pa.ApmAgentIos is not null)
143138
{
144139
@RenderProduct("APM Agent iOS", "Application Performance Monitoring Agent for iOS", VersioningSystemId.ApmAgentIos, pa.ApmAgentIos)
145-
;
146140
}
147141

148142
if (pa.ApmAgentJava is not null)
149143
{
150144
@RenderProduct("APM Agent Java", "Application Performance Monitoring Agent for Java", VersioningSystemId.ApmAgentJava, pa.ApmAgentJava)
151-
;
152145
}
153146

154147
if (pa.ApmAgentNode is not null)
155148
{
156149
@RenderProduct("APM Agent Node.js", "Application Performance Monitoring Agent for Node.js", VersioningSystemId.ApmAgentNode, pa.ApmAgentNode)
157-
;
158150
}
159151

160152
if (pa.ApmAgentPhp is not null)
161153
{
162154
@RenderProduct("APM Agent PHP", "Application Performance Monitoring Agent for PHP", VersioningSystemId.ApmAgentPhp, pa.ApmAgentPhp)
163-
;
164155
}
165156

166157
if (pa.ApmAgentPython is not null)
167158
{
168159
@RenderProduct("APM Agent Python", "Application Performance Monitoring Agent for Python", VersioningSystemId.ApmAgentPython, pa.ApmAgentPython)
169-
;
170160
}
171161

172162
if (pa.ApmAgentRuby is not null)
173163
{
174164
@RenderProduct("APM Agent Ruby", "Application Performance Monitoring Agent for Ruby", VersioningSystemId.ApmAgentRuby, pa.ApmAgentRuby)
175-
;
176165
}
177166

178167
if (pa.ApmAgentRum is not null)
179168
{
180169
@RenderProduct("APM Agent RUM", "Application Performance Monitoring Agent for Real User Monitoring", VersioningSystemId.ApmAgentRum, pa.ApmAgentRum)
181-
;
182170
}
183171

184172
if (pa.EdotIos is not null)
185173
{
186174
@RenderProduct("EDOT iOS", "Elastic Distribution of OpenTelemetry iOS", VersioningSystemId.EdotIos, pa.EdotIos)
187-
;
188175
}
189176

190177
if (pa.EdotAndroid is not null)
191178
{
192179
@RenderProduct("EDOT Android", "Elastic Distribution of OpenTelemetry Android", VersioningSystemId.EdotAndroid, pa.EdotAndroid)
193-
;
194180
}
195181

196182
if (pa.EdotDotnet is not null)
197183
{
198184
@RenderProduct("EDOT .NET", "Elastic Distribution of OpenTelemetry .NET", VersioningSystemId.EdotDotnet, pa.EdotDotnet)
199-
;
200185
}
201186

202187
if (pa.EdotJava is not null)
203188
{
204189
@RenderProduct("EDOT Java", "Elastic Distribution of OpenTelemetry Java", VersioningSystemId.EdotJava, pa.EdotJava)
205-
;
206190
}
207191

208192
if (pa.EdotNode is not null)
209193
{
210194
@RenderProduct("EDOT Node.js", "Elastic Distribution of OpenTelemetry Node.js", VersioningSystemId.EdotNode, pa.EdotNode)
211-
;
212195
}
213196

214197
if (pa.EdotPhp is not null)
215198
{
216199
@RenderProduct("EDOT PHP", "Elastic Distribution of OpenTelemetry PHP", VersioningSystemId.ApmAgentPhp, pa.EdotPhp)
217-
;
218200
}
219201

220202
if (pa.EdotPython is not null)
221203
{
222204
@RenderProduct("EDOT Python", "Elastic Distribution of OpenTelemetry Python", VersioningSystemId.EdotPython, pa.EdotPython)
223-
;
224205
}
225206

226207
if (pa.EdotCfAws is not null)
227208
{
228209
@RenderProduct("EDOT CF AWS", "Elastic Distribution of OpenTelemetry Cloud Forwarder for AWS", VersioningSystemId.EdotCfAws, pa.EdotCfAws)
229-
;
230210
}
231211

232212
if (pa.EdotCollector is not null)
233213
{
234214
@RenderProduct("EDOT Collector", "Elastic Distribution of OpenTelemetry Collector", VersioningSystemId.EdotCollector, pa.EdotCollector)
235-
;
236215
}
237216
}
238217

tests/authoring/Framework/Setup.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ type Setup =
167167
Base = SemVersion(8, 0, 0)
168168
)
169169
)
170-
versioningSystems.Add(VersioningSystemId.Elasticsearch,
170+
versioningSystems.Add(VersioningSystemId.ElasticsearchProject,
171171
VersioningSystem(
172-
Id = VersioningSystemId.Elasticsearch,
172+
Id = VersioningSystemId.ElasticsearchProject,
173173
Current = SemVersion(8, 0, 0),
174174
Base = SemVersion(8, 0, 0)
175175
)
@@ -188,16 +188,16 @@ type Setup =
188188
Base = SemVersion(8, 0, 0)
189189
)
190190
)
191-
versioningSystems.Add(VersioningSystemId.Observability,
191+
versioningSystems.Add(VersioningSystemId.ObservabilityProject,
192192
VersioningSystem(
193-
Id = VersioningSystemId.Observability,
193+
Id = VersioningSystemId.ObservabilityProject,
194194
Current = SemVersion(8, 0, 0),
195195
Base = SemVersion(8, 0, 0)
196196
)
197197
)
198-
versioningSystems.Add(VersioningSystemId.Security,
198+
versioningSystems.Add(VersioningSystemId.SecurityProject,
199199
VersioningSystem(
200-
Id = VersioningSystemId.Security,
200+
Id = VersioningSystemId.SecurityProject,
201201
Current = SemVersion(8, 0, 0),
202202
Base = SemVersion(8, 0, 0)
203203
)

0 commit comments

Comments
 (0)