-
Notifications
You must be signed in to change notification settings - Fork 6
122 lines (102 loc) · 3.69 KB
/
update-metadata.yml
File metadata and controls
122 lines (102 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Update Server Metadata
on:
schedule:
# Run daily at 2:00 AM UTC
- cron: '0 2 * * *'
workflow_dispatch:
inputs:
count:
description: 'Number of oldest entries to update'
required: false
default: '5'
type: string
permissions:
contents: write
pull-requests: write
jobs:
update-metadata:
name: Update Server Metadata
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
with:
go-version-file: 'go.mod'
cache: true
- name: Build catalog
run: go build -o /tmp/catalog ./cmd/catalog
- name: Determine count
id: count
run: echo "value=$INPUT_COUNT" >> $GITHUB_OUTPUT
env:
INPUT_COUNT: ${{ github.event.inputs.count || '5' }}
- name: Switch to metadata branch
run: |
BRANCH="catalog-update-metadata"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Fetch remote branch if it exists so we can build on it
git fetch origin "$BRANCH" 2>/dev/null || true
# If the branch already exists remotely, check it out to
# build on top of accumulated changes from prior runs.
if git rev-parse "origin/$BRANCH" >/dev/null 2>&1; then
git checkout -B "$BRANCH" "origin/$BRANCH"
else
git checkout -B "$BRANCH"
fi
- name: Update oldest entries
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPDATE_COUNT: ${{ steps.count.outputs.value }}
run: |
echo "Updating $UPDATE_COUNT oldest entries..."
/tmp/catalog update-metadata \
--oldest "$UPDATE_COUNT" \
--github-token "$GITHUB_TOKEN" \
-v
- name: Check for changes
id: check-changes
run: |
if git diff --quiet; then
echo "No changes detected"
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "Changes detected"
echo "changed=true" >> $GITHUB_OUTPUT
git diff --stat
fi
- name: Commit and open or update PR
if: steps.check-changes.outputs.changed == 'true'
run: |
BRANCH="catalog-update-metadata"
git add -u registries/
git commit -m "chore: update registry metadata (stars and pulls)"
git push -f origin "$BRANCH"
# Check if PR already exists
EXISTING_PR=$(gh pr list --head "$BRANCH" --json number --jq '.[0].number' 2>/dev/null || true)
if [ -n "$EXISTING_PR" ]; then
echo "PR #$EXISTING_PR already exists, updated branch"
else
gh pr create \
--title "chore: update registry metadata (stars and pulls)" \
--body "$(cat <<'BODY'
## Registry Metadata Update
This PR updates the GitHub stars and pull counts for registry entries
(server.json format).
Each daily run updates the oldest entries by `last_updated` timestamp
and aggregates the changes into this PR.
---
*This is an automated PR created by the daily metadata update workflow.*
BODY
)" \
--head "$BRANCH"
# Enable auto-merge
gh pr merge "$BRANCH" --auto --squash || true
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPDATE_COUNT: ${{ steps.count.outputs.value }}