-
Notifications
You must be signed in to change notification settings - Fork 18
183 lines (163 loc) · 5.97 KB
/
metadata_handler.yml
File metadata and controls
183 lines (163 loc) · 5.97 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Metadata Handler
# Reusable workflow for processing plugin metadata
# Called by the orchestrator when only metadata changes are detected
on:
workflow_call:
inputs:
plugin-dir:
description: "Comma-separated paths to plugin directories"
required: true
type: string
plugin-type:
description: "Plugin type (models or benchmarks)"
required: true
type: string
domain:
description: "Domain (language or vision)"
required: true
type: string
db-connection:
description: "If true, establish database connection"
required: false
type: boolean
default: false
secrets:
BSC_DATABASESECRET:
required: true
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
APPROVAL_TOKEN:
required: true
workflow_dispatch:
inputs:
plugin-dir:
description: "Path to plugin directory"
required: true
type: string
plugin-type:
description: "Plugin type (models or benchmarks)"
required: true
type: string
domain:
description: "Domain (language or vision)"
required: true
type: string
default: "language"
db-connection:
description: "If true, establish database connection"
required: false
type: boolean
default: false
jobs:
handle_metadata:
runs-on: ubuntu-latest
env:
BSC_DATABASESECRET: ${{ secrets.BSC_DATABASESECRET }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip setuptools
python -m pip install ".[test]"
pip install pyyaml
- name: Configure Git
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: "us-east-1"
- name: Run Metadata Handler
id: run_metadata
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Split comma-separated plugin-dir input into array
IFS=',' read -ra PLUGIN_DIRS <<< "${{ inputs.plugin-dir }}"
pr_numbers=""
for dir in "${PLUGIN_DIRS[@]}"; do
echo "Processing metadata in directory: $dir"
pr_num=$(python -m brainscore_core.plugin_management.handle_metadata \
--plugin-dir "$dir" \
--plugin-type "${{ inputs.plugin-type }}" \
--domain "${{ inputs.domain }}" \
--db-connection)
echo "PR number for $dir: $pr_num"
if [ -z "$pr_numbers" ]; then
pr_numbers="$pr_num"
else
pr_numbers="$pr_numbers,$pr_num"
fi
done
echo "pr_numbers=${pr_numbers}" >> $GITHUB_OUTPUT
- name: Auto-approve PRs
if: steps.run_metadata.outputs.pr_numbers != ''
env:
GITHUB_TOKEN: ${{ secrets.APPROVAL_TOKEN }}
run: |
IFS=',' read -ra PR_ARRAY <<< "${{ steps.run_metadata.outputs.pr_numbers }}"
for pr in "${PR_ARRAY[@]}"; do
echo "Auto-approving PR #$pr"
gh pr review $pr --approve --repo ${{ github.repository }}
done
- name: Wait for Status Checks
if: steps.run_metadata.outputs.pr_numbers != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
IFS=',' read -ra PR_ARRAY <<< "${{ steps.run_metadata.outputs.pr_numbers }}"
TOKEN="${{ secrets.GITHUB_TOKEN }}"
MAX_WAIT=600
SLEEP_INTERVAL=10
for pr in "${PR_ARRAY[@]}"; do
echo "Waiting for status checks on PR #$pr"
commit_sha=$(gh pr view $pr --json headRefOid --jq '.headRefOid')
echo "Commit SHA for PR #$pr is $commit_sha"
sleep 30
ELAPSED=30
while true; do
statuses=$(curl -s -H "Authorization: token $TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/commits/$commit_sha/statuses")
latest_statuses=$(echo "$statuses" | jq '[group_by(.context)[] | max_by(.created_at)]')
pending=$(echo "$latest_statuses" | jq 'map(select(.state=="pending")) | length')
failures=$(echo "$latest_statuses" | jq 'map(select(.state=="failure" or .state=="error")) | length')
echo "Status summary: $pending pending, $failures failures"
if [ "$failures" -gt 0 ]; then
echo "One or more status checks failed for PR #$pr - aborting"
exit 1
fi
if [ "$pending" -eq 0 ]; then
echo "All status checks passed for PR #$pr"
break
fi
sleep $SLEEP_INTERVAL
ELAPSED=$((ELAPSED + SLEEP_INTERVAL))
if [ "$ELAPSED" -ge "$MAX_WAIT" ]; then
echo "Timeout of $MAX_WAIT seconds reached for PR #$pr - aborting"
exit 1
fi
done
done
- name: Merge PRs
if: steps.run_metadata.outputs.pr_numbers != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
IFS=',' read -ra PR_ARRAY <<< "${{ steps.run_metadata.outputs.pr_numbers }}"
for pr in "${PR_ARRAY[@]}"; do
echo "Merging PR #$pr"
gh pr merge $pr --squash --delete-branch --repo ${{ github.repository }}
done