|
| 1 | +name: Update semconv integration branch |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # daily at 10:24 UTC |
| 6 | + - cron: '24 10 * * *' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + update-semconv-integration-branch: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: github.repository == 'open-telemetry/opentelemetry.io' |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + # this is needed in order to do the rebase below |
| 17 | + fetch-depth: 0 |
| 18 | + # this is needed in order to trigger workflows when pushing new commits to the PR |
| 19 | + token: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} |
| 20 | + |
| 21 | + - name: Set environment variables |
| 22 | + env: |
| 23 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + run: | |
| 25 | + branch_prefix="opentelemetrybot/semconv-integration" |
| 26 | +
|
| 27 | + version=$(git branch -r \ |
| 28 | + | grep "^ *origin/$branch_prefix-v[0-9]+\.[0-9]+\..*-dev" \ |
| 29 | + | sed "s|^ *origin/$branch_prefix-||" \ |
| 30 | + | sed "s|-dev$||") |
| 31 | +
|
| 32 | + if [[ -z "$versions" ]]; then |
| 33 | + latest_version=$(gh release view \ |
| 34 | + --repo open-telemetry/semantic-conventions \ |
| 35 | + --json tagName \ |
| 36 | + --jq .tagName) |
| 37 | + if [[ $latest_version =~ ^v([0-9]+)\.([0-9]+)\. ]]; then |
| 38 | + major="${BASH_REMATCH[1]}" |
| 39 | + minor="${BASH_REMATCH[2]}" |
| 40 | + version="v$major.$((minor + 1)).0" |
| 41 | + else |
| 42 | + echo "unexpected version: $latest_version" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + fi |
| 46 | +
|
| 47 | + echo "VERSION=$version" >> $GITHUB_ENV |
| 48 | + echo "BRANCH=$branch_prefix-$version-dev" >> $GITHUB_ENV |
| 49 | +
|
| 50 | + - name: Checkout or create branch |
| 51 | + run: | |
| 52 | + if ! git ls-remote --exit-code --heads origin $BRANCH; then |
| 53 | + git checkout -b $BRANCH origin/main |
| 54 | + git push -u origin $BRANCH |
| 55 | + else |
| 56 | + git checkout $BRANCH |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Use CLA approved github bot |
| 60 | + run: | |
| 61 | + git config user.name opentelemetrybot |
| 62 | + git config user.email [email protected] |
| 63 | +
|
| 64 | + - name: Merge from main |
| 65 | + run: | |
| 66 | + previous=$(git rev-parse HEAD) |
| 67 | + git fetch origin |
| 68 | + git merge origin/main |
| 69 | + if [ "$(git rev-parse HEAD)" != "$previous" ]; then |
| 70 | + git push |
| 71 | + fi |
| 72 | +
|
| 73 | + - name: Update submodule |
| 74 | + run: | |
| 75 | + git submodule update --init content-modules/semantic-conventions |
| 76 | + cd content-modules/semantic-conventions |
| 77 | +
|
| 78 | + if git ls-remote --exit-code --tags origin $VERSION; then |
| 79 | + git reset --hard $VERSION |
| 80 | + else |
| 81 | + git reset --hard origin/main |
| 82 | + fi |
| 83 | +
|
| 84 | + commit_desc=$(git describe --tags) |
| 85 | + cd ../.. |
| 86 | +
|
| 87 | + sed -i "s/^\tsemconv-pin = .*/\tsemconv-pin = $commit_desc/" .gitmodules |
| 88 | +
|
| 89 | + if ! git diff-index --quiet HEAD; then |
| 90 | + git commit -am "Update semconv submodule to $commit_desc" |
| 91 | + git push |
| 92 | + fi |
| 93 | +
|
| 94 | + - name: Create pull request if needed |
| 95 | + env: |
| 96 | + # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows |
| 97 | + GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} |
| 98 | + run: | |
| 99 | + prs=$(gh pr list --state open --head $BRANCH) |
| 100 | + if [ -z "$prs" ]; then |
| 101 | + gh pr create --title "Update semantic conventions to $VERSION-dev" \ |
| 102 | + --body "This PR updates the semantic conventions to $VERSION-dev." \ |
| 103 | + --draft |
| 104 | + fi |
0 commit comments