Skip to content

Commit 703856d

Browse files
committed
code review updates
1 parent 0ae4cda commit 703856d

File tree

1 file changed

+50
-15
lines changed

1 file changed

+50
-15
lines changed

.github/workflows/metadata-update.yml

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ on:
88
permissions:
99
contents: read
1010

11+
# Should only be one job running at a time to avoid conflicts with the metadata update branch
12+
concurrency:
13+
group: metadata-update
14+
cancel-in-progress: true
15+
1116
jobs:
1217
update:
1318
runs-on: ubuntu-latest
1419
permissions:
1520
contents: write # for git push to PR branch
16-
pull-requests: write # for creating PRs
21+
pull-requests: write # for adding label and assignee to PR
1722

1823
steps:
1924
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -41,42 +46,72 @@ jobs:
4146
run: |
4247
git add docs/instrumentation-list.yaml
4348
if ! git diff --cached --quiet; then
44-
echo "::set-output name=has_diff::true"
49+
echo "has_diff=true" >> $GITHUB_OUTPUT
4550
else
46-
echo "::set-output name=has_diff::false"
51+
echo "has_diff=false" >> $GITHUB_OUTPUT
4752
fi
4853
4954
- name: Use CLA approved github bot
5055
if: steps.diffcheck.outputs.has_diff == 'true'
5156
run: .github/scripts/use-cla-approved-bot.sh
5257

5358
- uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
59+
if: steps.diffcheck.outputs.has_diff == 'true'
5460
id: otelbot-token
5561
with:
5662
app-id: ${{ vars.OTELBOT_APP_ID }}
5763
private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }}
5864

59-
- name: Create PR if changes detected
65+
- name: Find or create metadata update branch
6066
if: steps.diffcheck.outputs.has_diff == 'true'
67+
id: findbranch
6168
env:
6269
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
6370
run: |
64-
BRANCH_NAME="metadata-update-automation-$(date +%s)-$RANDOM"
65-
git checkout -b "$BRANCH_NAME"
66-
git add docs/instrumentation-list.yaml
67-
git commit -m "chore: update instrumentation list [automated]"
68-
git push origin "$BRANCH_NAME"
69-
gh pr create \
70-
--title "chore: update instrumentation list [automated]" \
71-
--body "This PR was created automatically by the metadata update workflow." \
72-
--head "$BRANCH_NAME" \
73-
--base main
71+
BRANCH_NAME="metadata-update-main"
72+
echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT
73+
if git ls-remote --exit-code --heads origin "$BRANCH_NAME"; then
74+
git fetch origin "$BRANCH_NAME"
75+
git checkout "$BRANCH_NAME"
76+
else
77+
git checkout -b "$BRANCH_NAME"
78+
fi
7479
75-
- name: Add label to PR
80+
- name: Commit and push changes
81+
if: steps.diffcheck.outputs.has_diff == 'true'
82+
env:
83+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
84+
run: |
85+
BRANCH_NAME="${{ steps.findbranch.outputs.branch }}"
86+
git commit -m "chore: update instrumentation list [automated]" || echo "No changes to commit."
87+
git push origin "$BRANCH_NAME" --force-with-lease
88+
89+
- name: Create PR if needed
7690
if: steps.diffcheck.outputs.has_diff == 'true'
91+
id: createpr
92+
env:
93+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
94+
run: |
95+
BRANCH_NAME="${{ steps.findbranch.outputs.branch }}"
96+
PR_EXISTS=$(gh pr list --state open --head "$BRANCH_NAME" --label automation --json url -q '.[0].url')
97+
if [ -z "$PR_EXISTS" ]; then
98+
gh pr create \
99+
--title "chore: update instrumentation list [automated]" \
100+
--body "This PR was created automatically by the metadata update workflow." \
101+
--head "$BRANCH_NAME" \
102+
--base main
103+
echo "new_pr=true" >> $GITHUB_OUTPUT
104+
else
105+
echo "PR already exists: $PR_EXISTS"
106+
echo "new_pr=false" >> $GITHUB_OUTPUT
107+
fi
108+
109+
- name: Add label to PR
110+
if: steps.createpr.outputs.new_pr == 'true'
77111
env:
78112
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79113
run: |
114+
BRANCH_NAME="${{ steps.findbranch.outputs.branch }}"
80115
PR_URL=$(gh pr list --state open --head "$BRANCH_NAME" --json url -q '.[0].url')
81116
if [ -n "$PR_URL" ]; then
82117
gh pr edit "$PR_URL" --add-label "automation" --add-assignee jaydeluca

0 commit comments

Comments
 (0)