Skip to content

Commit 4f34baa

Browse files
authored
Add collector sync workflow (#29)
1 parent 884f3ab commit 4f34baa

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash -e
2+
3+
# https://github.com/open-telemetry/community/blob/main/assets.md#otelbot
4+
git config user.name otelbot
5+
git config user.email [email protected]
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Nightly Registry Update
2+
3+
on:
4+
schedule:
5+
# Run daily at 2 AM UTC
6+
- cron: '0 2 * * *'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
issues: write
12+
pull-requests: write
13+
14+
jobs:
15+
synchronize-collector-inventory:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
20+
with:
21+
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
22+
23+
- name: Detect repository type (if on a fork we use different git config)
24+
id: repo_check
25+
run: |
26+
if [ "${{ github.repository }}" == "open-telemetry/opentelemetry-ecosystem-explorer" ]; then
27+
echo "is_primary=true" >> $GITHUB_OUTPUT
28+
else
29+
echo "is_primary=false" >> $GITHUB_OUTPUT
30+
fi
31+
32+
- name: Configure git (primary repository)
33+
if: steps.repo_check.outputs.is_primary == 'true'
34+
run: |
35+
.github/scripts/use-cla-approved-bot.sh
36+
37+
- name: Configure git (fork)
38+
if: steps.repo_check.outputs.is_primary == 'false'
39+
run: |
40+
git config user.name "github-actions[bot]"
41+
git config user.email "github-actions[bot]@users.noreply.github.com"
42+
43+
- name: Cache repository clones
44+
uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2
45+
with:
46+
path: tmp_repos
47+
key: tmp-repos
48+
restore-keys: |
49+
tmp-repos-
50+
51+
- name: Install uv
52+
uses: astral-sh/setup-uv@61cb8a9741eeb8a550a1b8544337180c0fc8476b # v7.2.0
53+
with:
54+
enable-cache: true
55+
56+
- name: Set up Python
57+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
58+
59+
- name: Install dependencies
60+
run: uv sync
61+
62+
- name: Run collector-watcher
63+
run: |
64+
uv run collector-watcher
65+
66+
- name: Check for inventory changes
67+
id: check_changes
68+
run: |
69+
git add -N ecosystem-registry/ 2>/dev/null || true
70+
if git diff --quiet ecosystem-registry/ && [ -z "$(git ls-files --others --exclude-standard ecosystem-registry/)" ]; then
71+
echo "has_changes=false" >> $GITHUB_OUTPUT
72+
else
73+
echo "has_changes=true" >> $GITHUB_OUTPUT
74+
fi
75+
76+
- name: Commit and push changes
77+
if: steps.check_changes.outputs.has_changes == 'true'
78+
env:
79+
GH_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
80+
run: |
81+
BRANCH="automated-inventory-update"
82+
83+
git add ecosystem-registry/
84+
85+
git commit -m "Update component inventory"
86+
87+
# Push to branch (force push to update existing branch)
88+
git push -f origin HEAD:${BRANCH}
89+
90+
PR_TITLE="[automated] Update registry inventory"
91+
PR_BODY="$(cat <<'EOF'
92+
Automated nightly scan detected changes in registry data.
93+
---
94+
95+
_This PR is automatically generated by the Nightly Registry Update workflow._
96+
EOF
97+
)"
98+
99+
# Check if an open PR exists for this branch
100+
if gh pr list --head ${BRANCH} --state open --json number --jq '.[0].number' | grep -q .; then
101+
echo "Open PR already exists, updating..."
102+
gh pr edit ${BRANCH} --title "${PR_TITLE}" --body "${PR_BODY}"
103+
else
104+
echo "Creating new PR..."
105+
gh pr create --title "${PR_TITLE}" --body "${PR_BODY}" --base main --head ${BRANCH}
106+
fi

0 commit comments

Comments
 (0)