Skip to content

Commit f40b0aa

Browse files
author
Liudmila Molkova
committed
Automate schema-next generation in release workflow
1 parent 83b5544 commit f40b0aa

File tree

10 files changed

+122
-680
lines changed

10 files changed

+122
-680
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Note: if the PR is touching an area that is not listed in the [existing areas](h
1111
* [ ] [CONTRIBUTING.md](https://github.com/open-telemetry/semantic-conventions/blob/main/CONTRIBUTING.md) guidelines followed.
1212
* [ ] Change log entry added, according to the guidelines in [When to add a changelog entry](https://github.com/open-telemetry/semantic-conventions/blob/main/CONTRIBUTING.md#when-to-add-a-changelog-entry).
1313
* If your PR does not need a change log, start the PR title with `[chore]`
14-
* [ ] [schema-next.yaml](https://github.com/open-telemetry/semantic-conventions/blob/main/schema-next.yaml) updated with changes to existing conventions.
14+

.github/workflows/prepare-release.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ jobs:
3131
fi
3232
3333
version=${{ inputs.version }}
34-
cp schema-next.yaml "schemas/$version"
35-
36-
sed -i "s/ next:$/ next:\n $version:/" schema-next.yaml
37-
38-
sed -i "s/^schema_url: .*/schema_url: https:\/\/opentelemetry.io\/schemas\/$version/" "schemas/$version"
39-
sed -i "s/ next:$/ $version:/" "schemas/$version"
34+
make generate-schema-next SCHEMA_NEXT_VERSION=$version
4035
git add "schemas/$version"
4136
4237
- name: Update change log

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"editor.rulers": [80],
33
"yaml.schemas": {
4-
"https://raw.githubusercontent.com/open-telemetry/weaver/v0.15.0/schemas/semconv.schema.json": [
4+
"https://raw.githubusercontent.com/open-telemetry/weaver/v0.15.3/schemas/semconv.schema.json": [
55
"model/**/*.yaml"
66
]
77
},

CONTRIBUTING.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ requirements and recommendations.
1818
- [Prerequisites](#prerequisites)
1919
- [1. Modify the YAML model](#1-modify-the-yaml-model)
2020
- [Code structure](#code-structure)
21-
- [Schema files](#schema-files)
2221
- [2. Update the markdown files](#2-update-the-markdown-files)
2322
- [Hugo frontmatter](#hugo-frontmatter)
2423
- [3. Check new convention](#3-check-new-convention)
@@ -36,6 +35,7 @@ requirements and recommendations.
3635
- [Update the tables of content](#update-the-tables-of-content)
3736
- [Markdown link check](#markdown-link-check)
3837
- [Yamllint check](#yamllint-check)
38+
- [Schema files](#schema-files)
3939
- [Merging existing ECS conventions](#merging-existing-ecs-conventions)
4040

4141
<!-- tocstop -->
@@ -57,8 +57,7 @@ key, but non-obvious, aspects:
5757
- All descriptions, normative language are defined in the `docs/` directory.
5858
- All changes to existing attributes, metrics, etc. MUST be allowed as
5959
per our [stability guarantees][stability guarantees] and
60-
defined in a schema file. As part of any contribution, you should
61-
include attribute changes defined in the `schema-next.yaml` file.
60+
defined in a schema file.
6261
- Links to the specification repository MUST point to a tag and **not** to the `main` branch.
6362
The tag version MUST match with the one defined in [README](README.md).
6463

@@ -164,21 +163,6 @@ are defined in `/model/aws/lambda-spans.yaml` and `/model/aws/sdk-spans.yaml` fi
164163
Deprecated conventions should be placed under `/model/{root-namespace}/deprecated`
165164
folder.
166165

167-
#### Schema files
168-
169-
When making changes to existing semantic conventions (attributes, metrics, etc)
170-
you MUST also update the `schema-next.yaml` file with the changes.
171-
172-
For details, please read
173-
[the schema specification](https://opentelemetry.io/docs/specs/otel/schemas/).
174-
175-
You can also take examples from past changes inside the `schemas` folder.
176-
177-
> [!WARNING]
178-
>
179-
> DO NOT add your changes to files inside the `schemas` folder. Always add your
180-
> changes to the `schema-next.yaml` file.
181-
182166
### 2. Update the markdown files
183167

184168
After updating the YAML file(s), you need to update
@@ -434,6 +418,23 @@ If it is the first time to run this command, install `yamllint` first:
434418
make install-yamllint
435419
```
436420

421+
## Schema files
422+
423+
> [!WARNING]
424+
>
425+
> DO NOT add your changes to files inside the `schemas` folder. These files are
426+
> generated automatically by the release scripts and can't be updated after
427+
> the corresponding version is released.
428+
429+
Release script uses the following command to generate new schema file:
430+
431+
```bash
432+
make generate-schema-next NEXT_SEMCONV_VERSION={next version}
433+
```
434+
435+
For details, please read
436+
[the schema specification](https://opentelemetry.io/docs/specs/otel/schemas/).
437+
437438
## Merging existing ECS conventions
438439

439440
The Elastic Common Schema (ECS) is being merged into OpenTelemetry Semantic

Makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,22 @@ check-dead-yaml:
348348
--config=/home/weaver/templates/registry/signal-groups-weaver.yaml \
349349
. \
350350
/home/weaver/target
351-
$(TOOLS_DIR)/scripts/find-dead-yaml.sh $(PWD)/internal/tools/bin/signal-groups.txt $(PWD)/docs
351+
$(TOOLS_DIR)/scripts/find-dead-yaml.sh $(PWD)/internal/tools/bin/signal-groups.txt $(PWD)/docs
352+
353+
NEXT_SEMCONV_VERSION ?= next
354+
.PHONY: generate-schema-next
355+
generate-schema-next:
356+
mkdir -p $(TOOLS_DIR)/bin
357+
$(DOCKER_RUN) --rm \
358+
$(DOCKER_USER_IS_HOST_USER_ARG) \
359+
--mount 'type=bind,source=$(PWD)/internal/tools/scripts,target=/home/weaver/templates,readonly' \
360+
--mount 'type=bind,source=$(PWD)/model,target=/home/weaver/source,readonly' \
361+
--mount 'type=bind,source=$(TOOLS_DIR)/bin,target=/home/weaver/target' \
362+
$(WEAVER_CONTAINER) registry diff \
363+
--registry=/home/weaver/source \
364+
--baseline-registry=https://github.com/open-telemetry/semantic-conventions/archive/refs/tags/v$(LATEST_RELEASED_SEMCONV_VERSION).zip[model] \
365+
--diff-format yaml \
366+
--diff-template /home/weaver/templates/schema-diff \
367+
--output /home/weaver/target
368+
# --param next_version=$(NEXT_SEMCONV_VERSION)
369+
$(TOOLS_DIR)/scripts/generate-schema-next.sh $(NEXT_SEMCONV_VERSION) $(LATEST_RELEASED_SEMCONV_VERSION) $(TOOLS_DIR)/bin/schema-diff.yaml

dependencies.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Dependabot can keep this file up to date with latest containers.
44

55
# Weaver is used to generate markdown docs, and enforce policies on the model.
6-
FROM otel/weaver:v0.15.2@sha256:b13acea09f721774daba36344861f689ac4bb8d6ecd94c4600b4d590c8fb34b9 AS weaver
6+
FROM otel/weaver:v0.15.3@sha256:a84032d6eb95b81972d19de61f6ddc394a26976c1c1697cf9318bef4b4106976 AS weaver
77

88
# OPA is used to test policies enforced by weaver.
99
FROM openpolicyagent/opa:1.5.1@sha256:7d30d984125161b7f30599c6bdf80a6f2301dbbd526725714c231aad8179e4b9 AS opa
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright The OpenTelemetry Authors
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Generate header and `{next_version}:` section in next schema yaml based on weaver
7+
# diff output.
8+
9+
set -euo pipefail
10+
11+
cur_version="$1"
12+
prev_version="$2"
13+
diff_file="$3"
14+
cur_version_schema_file="schemas/$cur_version"
15+
prev_version_schema_file="schemas/$prev_version"
16+
17+
# Check if the previous version schema file exists
18+
if [[ ! -f "$prev_version_schema_file" ]]; then
19+
echo "Previous version schema file not found: $prev_version_schema_file"
20+
exit 1
21+
fi
22+
23+
# check if the current version schema file exists
24+
if [[ -f "$cur_version_schema_file" ]]; then
25+
echo "Current version schema file already exists: $cur_version_schema_file"
26+
exit 1
27+
fi
28+
29+
if ! grep -q "^versions:$" "$prev_version_schema_file"; then
30+
echo "String 'versions:' not found in the file $prev_version_schema_file."
31+
exit 1
32+
fi
33+
34+
prev_header_lines=$(awk '/^versions:/{print NR; exit}' "$prev_version_schema_file")
35+
36+
# need to replace the next_version_placeholder in the header file due to https://github.com/open-telemetry/weaver/issues/775
37+
# TODO: remove it after the issue is fixed
38+
{
39+
sed "s/next_version_placeholder/$cur_version/g" "$diff_file"
40+
tail -n +"$((prev_header_lines + 1))" "$prev_version_schema_file"
41+
} > "$cur_version_schema_file"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{{- template.set_file_name("schema-diff.yaml") }}
2+
3+
file_format: 1.1.0
4+
schema_url: https://opentelemetry.io/schemas/{{ctx.next_version}}
5+
versions:
6+
{{ctx.next_version}}:
7+
{% if ctx.renames.registry_attributes | length > 0 %}
8+
all:
9+
changes:
10+
- rename_attributes:
11+
attribute_map:
12+
{% for attr in ctx.renames.registry_attributes %}
13+
{{attr.old_name}}: {{attr.new_name}}
14+
{% endfor %}
15+
{% endif %}
16+
{% if ctx.renames.metrics | length > 0 %}
17+
metrics:
18+
changes:
19+
- rename_metrics:
20+
{% for metric in ctx.renames.metrics %}
21+
{{metric.old_name}}: {{metric.new_name}}
22+
{% endfor %}
23+
{% endif %}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
params:
2+
next_version: "next_version_placeholder" # https://github.com/open-telemetry/weaver/issues/775
3+
templates:
4+
- pattern: schema-diff.j2
5+
filter: >
6+
.
7+
| {
8+
renames: .changes | with_entries(.value |= (map(select(.type == "renamed")) | sort_by(.old_name))),
9+
next_version: $next_version,
10+
latest_released_version: .baseline.semconv_version,
11+
}
12+
application_mode: single
13+
whitespace_control:
14+
trim_blocks: true
15+
lstrip_blocks: true
16+
keep_trailing_newline: true

0 commit comments

Comments
 (0)