Skip to content

Auto-update semantic conventions #3521

Auto-update semantic conventions

Auto-update semantic conventions #3521

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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- 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 \
--state open \
--head "otelbot/update-semconv-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@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
id: otelbot-token
with:
app-id: ${{ vars.OTELBOT_SEMANTIC_CONVENTIONS_JAVA_APP_ID }}
private-key: ${{ secrets.OTELBOT_SEMANTIC_CONVENTIONS_JAVA_PRIVATE_KEY }}
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
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@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0
with:
distribution: temurin
java-version: 21
- uses: gradle/actions/setup-gradle@3f131e8634966bd73d06cc69884922b02e6faf92 # v6.2.0
- name: Generate code
run: ./gradlew clean generateSemanticConventions --console=plain
- name: Apply formatting
run: ./gradlew spotlessApply
- name: Generate API diffs
run: ./gradlew jApiCmp
- 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 add docs/apidiffs/
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