|
8 | 8 | permissions: |
9 | 9 | contents: read |
10 | 10 |
|
| 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 | + |
11 | 16 | jobs: |
12 | 17 | update: |
13 | 18 | runs-on: ubuntu-latest |
14 | 19 | permissions: |
15 | 20 | 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 |
17 | 22 |
|
18 | 23 | steps: |
19 | 24 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
@@ -41,42 +46,72 @@ jobs: |
41 | 46 | run: | |
42 | 47 | git add docs/instrumentation-list.yaml |
43 | 48 | if ! git diff --cached --quiet; then |
44 | | - echo "::set-output name=has_diff::true" |
| 49 | + echo "has_diff=true" >> $GITHUB_OUTPUT |
45 | 50 | else |
46 | | - echo "::set-output name=has_diff::false" |
| 51 | + echo "has_diff=false" >> $GITHUB_OUTPUT |
47 | 52 | fi |
48 | 53 |
|
49 | 54 | - name: Use CLA approved github bot |
50 | 55 | if: steps.diffcheck.outputs.has_diff == 'true' |
51 | 56 | run: .github/scripts/use-cla-approved-bot.sh |
52 | 57 |
|
53 | 58 | - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6 |
| 59 | + if: steps.diffcheck.outputs.has_diff == 'true' |
54 | 60 | id: otelbot-token |
55 | 61 | with: |
56 | 62 | app-id: ${{ vars.OTELBOT_APP_ID }} |
57 | 63 | private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }} |
58 | 64 |
|
59 | | - - name: Create PR if changes detected |
| 65 | + - name: Find or create metadata update branch |
60 | 66 | if: steps.diffcheck.outputs.has_diff == 'true' |
| 67 | + id: findbranch |
61 | 68 | env: |
62 | 69 | GH_TOKEN: ${{ steps.otelbot-token.outputs.token }} |
63 | 70 | 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 |
74 | 79 |
|
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 |
76 | 90 | 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' |
77 | 111 | env: |
78 | 112 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
79 | 113 | run: | |
| 114 | + BRANCH_NAME="${{ steps.findbranch.outputs.branch }}" |
80 | 115 | PR_URL=$(gh pr list --state open --head "$BRANCH_NAME" --json url -q '.[0].url') |
81 | 116 | if [ -n "$PR_URL" ]; then |
82 | 117 | gh pr edit "$PR_URL" --add-label "automation" --add-assignee jaydeluca |
|
0 commit comments