-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (148 loc) · 6.65 KB
/
sync-labels.yml
File metadata and controls
176 lines (148 loc) · 6.65 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
name: "Sync: Labels"
run-name: "Sync labels after push to main"
# Runs after any push to main to ensure labels match repository state
# This fixes label propagation issues when PRs are merged manually
on:
push:
branches:
- main
workflow_dispatch:
jobs:
sync-spec-labels:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 2 # Need to see what changed
- name: Install yq for YAML parsing
run: |
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
- name: Detect new specifications merged to main
id: detect
env:
BEFORE: ${{ github.event.before }}
AFTER: ${{ github.event.after }}
run: |
# Get list of specifications added/modified in this push
# Use GitHub event context for reliability (handles first push, force push, etc.)
if [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
# First push or new branch: diff-tree on the after commit only
CHANGED_SPECS=$(git diff-tree --no-commit-id --name-only -r "$AFTER" | \
grep -oP 'plots/\K[^/]+(?=/specification\.(md|yaml))' | \
sort -u || true)
else
# Normal push: diff between before and after SHAs
CHANGED_SPECS=$(git diff --name-only "$BEFORE" "$AFTER" | \
grep -oP 'plots/\K[^/]+(?=/specification\.(md|yaml))' | \
sort -u || true)
fi
if [ -z "$CHANGED_SPECS" ]; then
echo "::notice::No specification changes detected"
echo "specs=" >> $GITHUB_OUTPUT
exit 0
fi
echo "specs<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_SPECS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Sync labels for merged specifications
if: steps.detect.outputs.specs != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "${{ steps.detect.outputs.specs }}" | while read SPEC_ID; do
[ -z "$SPEC_ID" ] && continue
# Extract issue number from specification.yaml
SPEC_YAML="plots/${SPEC_ID}/specification.yaml"
if [ ! -f "$SPEC_YAML" ]; then
echo "::warning::No specification.yaml for ${SPEC_ID}"
continue
fi
ISSUE=$(yq '.issue' "$SPEC_YAML" 2>/dev/null || echo "")
if [ -z "$ISSUE" ] || [ "$ISSUE" == "null" ]; then
echo "::warning::No issue number in ${SPEC_YAML}"
continue
fi
echo "::notice::Syncing labels for spec ${SPEC_ID} (issue #${ISSUE})"
# Get current labels
CURRENT_LABELS=$(gh issue view "$ISSUE" --json labels -q '.labels[].name' 2>/dev/null || echo "")
# If specification is in main, ensure correct labels
if echo "$CURRENT_LABELS" | grep -q "spec-request"; then
echo "::notice::Removing spec-request label from #${ISSUE}"
gh issue edit "$ISSUE" --remove-label "spec-request" 2>/dev/null || true
fi
if ! echo "$CURRENT_LABELS" | grep -q "spec-ready"; then
echo "::notice::Adding spec-ready label to #${ISSUE}"
gh issue edit "$ISSUE" --add-label "spec-ready" 2>/dev/null || true
fi
done
sync-impl-labels:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Install yq for YAML parsing
run: |
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
- name: Detect new implementations merged to main
id: detect
env:
BEFORE: ${{ github.event.before }}
AFTER: ${{ github.event.after }}
run: |
# Get list of implementations added/modified in this push
# Use GitHub event context for reliability (handles first push, force push, etc.)
if [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
# First push or new branch: diff-tree on the after commit only
CHANGED_IMPLS=$(git diff-tree --no-commit-id --name-only -r "$AFTER" | \
grep -P 'plots/[^/]+/implementations/[^/]+\.py$' || true)
else
# Normal push: diff between before and after SHAs
CHANGED_IMPLS=$(git diff --name-only "$BEFORE" "$AFTER" | \
grep -P 'plots/[^/]+/implementations/[^/]+\.py$' || true)
fi
if [ -z "$CHANGED_IMPLS" ]; then
echo "::notice::No implementation changes detected"
echo "impls=" >> $GITHUB_OUTPUT
exit 0
fi
echo "impls<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_IMPLS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Sync labels for merged implementations
if: steps.detect.outputs.impls != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "${{ steps.detect.outputs.impls }}" | while read IMPL_PATH; do
[ -z "$IMPL_PATH" ] && continue
# Extract spec-id and library from path: plots/{spec-id}/implementations/{library}.py
SPEC_ID=$(echo "$IMPL_PATH" | cut -d'/' -f2)
LIBRARY=$(echo "$IMPL_PATH" | cut -d'/' -f4 | sed 's/\.py$//')
# Get issue number
SPEC_YAML="plots/${SPEC_ID}/specification.yaml"
ISSUE=$(yq '.issue' "$SPEC_YAML" 2>/dev/null || echo "")
if [ -z "$ISSUE" ] || [ "$ISSUE" == "null" ]; then
echo "::warning::No issue for ${SPEC_ID}/${LIBRARY}"
continue
fi
echo "::notice::Syncing labels for ${SPEC_ID}/${LIBRARY} (issue #${ISSUE})"
# Remove trigger and pending labels
gh issue edit "$ISSUE" --remove-label "generate:${LIBRARY}" 2>/dev/null || true
gh issue edit "$ISSUE" --remove-label "impl:${LIBRARY}:pending" 2>/dev/null || true
# Create and add done label
gh label create "impl:${LIBRARY}:done" --color "0e8a16" \
--description "${LIBRARY} implementation merged" 2>/dev/null || true
gh issue edit "$ISSUE" --add-label "impl:${LIBRARY}:done" 2>/dev/null || true
echo "::notice::✓ Labels synced for ${SPEC_ID}/${LIBRARY}"
done