|
| 1 | +name: Auto-update semantic conventions |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # hourly at minute 46 |
| 6 | + - cron: "46 * * * *" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + check-versions: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + current-version: ${{ steps.check-versions.outputs.current-version }} |
| 17 | + latest-version: ${{ steps.check-versions.outputs.latest-version }} |
| 18 | + already-opened: ${{ steps.check-versions.outputs.already-opened }} |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 21 | + |
| 22 | + - id: check-versions |
| 23 | + name: Check versions |
| 24 | + env: |
| 25 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 26 | + run: | |
| 27 | + current_version=$(grep -Po 'var semanticConventionsVersion = "\K[0-9]+\.[0-9]+\.[0-9]+' build.gradle.kts) |
| 28 | + latest_version=$(gh release view \ |
| 29 | + --repo open-telemetry/semantic-conventions \ |
| 30 | + --json tagName \ |
| 31 | + --jq .tagName \ |
| 32 | + | sed 's/^v//') |
| 33 | +
|
| 34 | + matches=$(gh pr list \ |
| 35 | + --author app/otelbot \ |
| 36 | + --state open \ |
| 37 | + --search "in:title \"Update the semantic conventions version to $latest_version\"") |
| 38 | + if [ ! -z "$matches" ] |
| 39 | + then |
| 40 | + already_opened=true |
| 41 | + fi |
| 42 | +
|
| 43 | + echo "current-version=$current_version" >> $GITHUB_OUTPUT |
| 44 | + echo "latest-version=$latest_version" >> $GITHUB_OUTPUT |
| 45 | + echo "already-opened=$already_opened" >> $GITHUB_OUTPUT |
| 46 | +
|
| 47 | + update-semconv: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + if: | |
| 50 | + needs.check-versions.outputs.current-version != needs.check-versions.outputs.latest-version && |
| 51 | + needs.check-versions.outputs.already-opened != 'true' |
| 52 | + needs: |
| 53 | + - check-versions |
| 54 | + steps: |
| 55 | + - uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1 |
| 56 | + id: otelbot-token |
| 57 | + with: |
| 58 | + app-id: ${{ vars.OTELBOT_SEMANTIC_CONVENTIONS_JAVA_APP_ID }} |
| 59 | + private-key: ${{ secrets.OTELBOT_SEMANTIC_CONVENTIONS_JAVA_PRIVATE_KEY }} |
| 60 | + |
| 61 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 62 | + with: |
| 63 | + # using custom token so the changelog PR link update push triggers workflows |
| 64 | + token: ${{ steps.otelbot-token.outputs.token }} |
| 65 | + |
| 66 | + - name: Update version |
| 67 | + env: |
| 68 | + VERSION: ${{ needs.check-versions.outputs.latest-version }} |
| 69 | + run: ./.github/scripts/update-semconv-version.sh $VERSION |
| 70 | + |
| 71 | + - name: Set up Java for build |
| 72 | + uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 |
| 73 | + with: |
| 74 | + distribution: temurin |
| 75 | + java-version: 21 |
| 76 | + |
| 77 | + - uses: gradle/actions/setup-gradle@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0 |
| 78 | + |
| 79 | + - name: Generate code |
| 80 | + run: ./gradlew clean generateSemanticConventions --console=plain |
| 81 | + |
| 82 | + - name: Apply formatting |
| 83 | + run: ./gradlew spotlessApply |
| 84 | + |
| 85 | + - name: Use CLA approved bot |
| 86 | + run: .github/scripts/use-cla-approved-bot.sh |
| 87 | + |
| 88 | + - name: Create pull request against main |
| 89 | + if: success() || failure() |
| 90 | + env: |
| 91 | + VERSION: ${{ needs.check-versions.outputs.latest-version }} |
| 92 | + # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows |
| 93 | + GH_TOKEN: ${{ steps.otelbot-token.outputs.token }} |
| 94 | + run: | |
| 95 | + message="Update the semantic conventions version to $VERSION" |
| 96 | + body="Update the semantic conventions version to \`$VERSION\`." |
| 97 | + branch="otelbot/update-semconv-to-${VERSION}" |
| 98 | +
|
| 99 | + git checkout -b $branch |
| 100 | + git add -u |
| 101 | + git add semconv**/src/main/java |
| 102 | + git commit -m "$message" |
| 103 | + git push --set-upstream origin $branch |
| 104 | + pr_url=$(gh pr create --title "$message" \ |
| 105 | + --body "$body" \ |
| 106 | + --base main) |
| 107 | +
|
| 108 | + pr_number=$(echo "$pr_url" | grep -oE '[0-9]+$') |
| 109 | + sed -i "s/PRNUM/${pr_number}/g" CHANGELOG.md |
| 110 | + git add CHANGELOG.md |
| 111 | + git commit -m "Update changelog PR link" |
| 112 | + git push |
0 commit comments