-
Notifications
You must be signed in to change notification settings - Fork 30
Auto-update semconv version #404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+138
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #!/bin/bash -e | ||
|
|
||
| # Updates the semantic conventions version to a new release. | ||
| # Usage: ./update-semconv-version.sh <new-version> | ||
| # Example: ./update-semconv-version.sh 1.40.0 | ||
|
|
||
| version=$1 | ||
|
|
||
| # Update semanticConventionsVersion in build.gradle.kts | ||
| old_version=$(grep -Po 'var semanticConventionsVersion = "\K[0-9]+\.[0-9]+\.[0-9]+' build.gradle.kts) | ||
| sed -Ei "s/var semanticConventionsVersion = \"[^\"]*\"/var semanticConventionsVersion = \"$version\"/" build.gradle.kts | ||
|
|
||
| # Add old version to schemaUrlVersions list (after semanticConventionsVersion,) | ||
| sed -Ei "s/( semanticConventionsVersion,)/\1\n \"$old_version\",/" build.gradle.kts | ||
|
|
||
| # Add new version constant to SchemaUrls.java | ||
| version_underscore=${version//./_} | ||
| sed -Ei "s/(public final class SchemaUrls \{)/\1\n\n public static final String V${version_underscore} = \"https:\/\/opentelemetry.io\/schemas\/${version}\";/" \ | ||
| semconv/src/main/java/io/opentelemetry/semconv/SchemaUrls.java | ||
|
|
||
| # Add changelog entry | ||
| if grep -q "^## Unreleased$" CHANGELOG.md; then | ||
| sed -Ei "s/^## Unreleased$/## Unreleased\n\n* Bump to semconv v${version}\n ([#PRNUM](https:\/\/github.com\/open-telemetry\/semantic-conventions-java\/pull\/PRNUM))/" CHANGELOG.md | ||
| else | ||
| sed -Ei "s/^# Changelog$/# Changelog\n\n## Unreleased\n\n* Bump to semconv v${version}\n ([#PRNUM](https:\/\/github.com\/open-telemetry\/semantic-conventions-java\/pull\/PRNUM))/" CHANGELOG.md | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| name: Auto-update semantic conventions | ||
|
|
||
| on: | ||
| schedule: | ||
| # hourly at minute 46 | ||
| - cron: "46 * * * *" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| check-versions: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| current-version: ${{ steps.check-versions.outputs.current-version }} | ||
| latest-version: ${{ steps.check-versions.outputs.latest-version }} | ||
| already-opened: ${{ steps.check-versions.outputs.already-opened }} | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - id: check-versions | ||
| name: Check versions | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| current_version=$(grep -Po 'var semanticConventionsVersion = "\K[0-9]+\.[0-9]+\.[0-9]+' build.gradle.kts) | ||
| latest_version=$(gh release view \ | ||
| --repo open-telemetry/semantic-conventions \ | ||
| --json tagName \ | ||
| --jq .tagName \ | ||
| | sed 's/^v//') | ||
|
|
||
| matches=$(gh pr list \ | ||
| --author app/otelbot \ | ||
| --state open \ | ||
| --search "in:title \"Update the semantic conventions version to $latest_version\"") | ||
| if [ ! -z "$matches" ] | ||
| then | ||
| already_opened=true | ||
| fi | ||
|
|
||
| echo "current-version=$current_version" >> $GITHUB_OUTPUT | ||
| echo "latest-version=$latest_version" >> $GITHUB_OUTPUT | ||
| echo "already-opened=$already_opened" >> $GITHUB_OUTPUT | ||
|
|
||
| update-semconv: | ||
| runs-on: ubuntu-latest | ||
| if: | | ||
| needs.check-versions.outputs.current-version != needs.check-versions.outputs.latest-version && | ||
| needs.check-versions.outputs.already-opened != 'true' | ||
| needs: | ||
| - check-versions | ||
| steps: | ||
| - uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1 | ||
| id: otelbot-token | ||
| with: | ||
| app-id: ${{ vars.OTELBOT_SEMANTIC_CONVENTIONS_JAVA_APP_ID }} | ||
| private-key: ${{ secrets.OTELBOT_SEMANTIC_CONVENTIONS_JAVA_PRIVATE_KEY }} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do these come? Are they org level vars / secrets?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| # using custom token so the changelog PR link update push triggers workflows | ||
| token: ${{ steps.otelbot-token.outputs.token }} | ||
|
|
||
| - name: Update version | ||
| env: | ||
| VERSION: ${{ needs.check-versions.outputs.latest-version }} | ||
| run: ./.github/scripts/update-semconv-version.sh $VERSION | ||
|
|
||
| - name: Set up Java for build | ||
| uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 | ||
| with: | ||
| distribution: temurin | ||
| java-version: 21 | ||
|
|
||
| - uses: gradle/actions/setup-gradle@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0 | ||
|
|
||
| - name: Generate code | ||
| run: ./gradlew clean generateSemanticConventions --console=plain | ||
|
|
||
| - name: Apply formatting | ||
| run: ./gradlew spotlessApply | ||
|
|
||
| - name: Use CLA approved bot | ||
| run: .github/scripts/use-cla-approved-bot.sh | ||
|
|
||
| - name: Create pull request against main | ||
| if: success() || failure() | ||
| env: | ||
| VERSION: ${{ needs.check-versions.outputs.latest-version }} | ||
| # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows | ||
| GH_TOKEN: ${{ steps.otelbot-token.outputs.token }} | ||
| run: | | ||
| message="Update the semantic conventions version to $VERSION" | ||
| body="Update the semantic conventions version to \`$VERSION\`." | ||
| branch="otelbot/update-semconv-to-${VERSION}" | ||
|
|
||
| git checkout -b $branch | ||
| git add -u | ||
| git add semconv**/src/main/java | ||
| git commit -m "$message" | ||
| git push --set-upstream origin $branch | ||
| pr_url=$(gh pr create --title "$message" \ | ||
| --body "$body" \ | ||
| --base main) | ||
|
|
||
| pr_number=$(echo "$pr_url" | grep -oE '[0-9]+$') | ||
| sed -i "s/PRNUM/${pr_number}/g" CHANGELOG.md | ||
| git add CHANGELOG.md | ||
| git commit -m "Update changelog PR link" | ||
| git push | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this get away with read permissions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are permissions for the default
GITHUB_TOKENand this script is using
OTELBOT_SEMANTIC_CONVENTIONS_JAVA_APP_IDfor all of it's permissions