Skip to content

Commit 9976a4d

Browse files
authored
Add tool to check unmapped fields in Alloy (#1723)
1 parent 90f6993 commit 9976a4d

File tree

2 files changed

+553
-0
lines changed

2 files changed

+553
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: Alloy Mapped Fields Checker
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- 'pkg/**/*.go'
8+
9+
jobs:
10+
check-config:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
issues: write
14+
contents: read
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version-file: 'go.mod'
23+
cache: false # Disable caching to avoid extraction conflicts
24+
check-latest: true
25+
26+
- name: Run alloy field checker
27+
id: field-checker
28+
run: |
29+
# First compile the checker to ensure it builds
30+
cd tools/alloy-field-checker
31+
go build -o field-checker
32+
if [ $? -ne 0 ]; then
33+
echo "Failed to build field checker"
34+
exit 1
35+
fi
36+
37+
# Move back to workspace root and run the checker
38+
cd ../..
39+
if [ ! -d "pkg" ]; then
40+
echo "pkg directory not found in $(pwd)"
41+
ls -la
42+
exit 1
43+
fi
44+
45+
tools/alloy-field-checker/field-checker 2>&1 | tee output.txt
46+
if [ ${PIPESTATUS[0]} -ne 0 ]; then
47+
# Create a normalized version of the output (remove line numbers which can change)
48+
grep "unmapped fields:" output.txt > /dev/null && {
49+
echo "has_unmapped=true" >> $GITHUB_OUTPUT
50+
echo "unmapped_fields<<EOF" >> $GITHUB_OUTPUT
51+
# Extract just the field names and struct names, ignore line numbers
52+
grep -o "[a-zA-Z0-9]\+\.[a-zA-Z0-9]\+ (tag: [^)]\+)" output.txt | sort > normalized_output.txt
53+
cat normalized_output.txt >> $GITHUB_OUTPUT
54+
echo "EOF" >> $GITHUB_OUTPUT
55+
} || {
56+
echo "has_unmapped=false" >> $GITHUB_OUTPUT
57+
}
58+
else
59+
echo "has_unmapped=false" >> $GITHUB_OUTPUT
60+
fi
61+
62+
- name: Find existing issues
63+
if: steps.field-checker.outputs.has_unmapped == 'true'
64+
uses: actions/github-script@v7
65+
id: find-issue
66+
with:
67+
script: |
68+
const issues = await github.rest.issues.listForRepo({
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
state: 'open',
72+
labels: []
73+
});
74+
const existingIssue = issues.data.find(issue =>
75+
issue.title === 'Map missing Beyla options in Alloy component'
76+
);
77+
return existingIssue ? existingIssue.number : 0;
78+
result-encoding: string
79+
80+
- name: Manage issue
81+
if: steps.field-checker.outputs.has_unmapped == 'true'
82+
uses: actions/github-script@v7
83+
with:
84+
script: |
85+
const issueNumber = parseInt('${{ steps.find-issue.outputs.result }}');
86+
const issueBody = `Unmapped configuration fields were detected in Beyla's Alloy component:
87+
88+
\`\`\`
89+
${process.env.UNMAPPED_FIELDS}
90+
\`\`\`
91+
92+
Please ensure all configuration fields are properly mapped in the Alloy configuration.
93+
94+
This issue was automatically generated by the config-checker workflow.`;
95+
96+
if (issueNumber > 0) {
97+
// Update existing issue
98+
await github.rest.issues.update({
99+
owner: context.repo.owner,
100+
repo: context.repo.repo,
101+
issue_number: issueNumber,
102+
body: issueBody
103+
});
104+
} else {
105+
// Create new issue
106+
await github.rest.issues.create({
107+
owner: context.repo.owner,
108+
repo: context.repo.repo,
109+
title: 'Map missing Beyla options in Alloy component',
110+
body: issueBody,
111+
assignee: context.repo.owner
112+
});
113+
}
114+
env:
115+
UNMAPPED_FIELDS: ${{ steps.field-checker.outputs.unmapped_fields }}
116+
117+
- name: Close issue if no unmapped fields
118+
if: steps.field-checker.outputs.has_unmapped == 'false'
119+
uses: actions/github-script@v7
120+
with:
121+
script: |
122+
const issues = await github.rest.issues.listForRepo({
123+
owner: context.repo.owner,
124+
repo: context.repo.repo,
125+
state: 'open',
126+
labels: []
127+
});
128+
129+
const existingIssue = issues.data.find(issue =>
130+
issue.title === 'Map missing Beyla options in Alloy component'
131+
);
132+
133+
if (existingIssue) {
134+
await github.rest.issues.update({
135+
owner: context.repo.owner,
136+
repo: context.repo.repo,
137+
issue_number: existingIssue.number,
138+
state: 'closed',
139+
state_reason: 'completed'
140+
});
141+
}

0 commit comments

Comments
 (0)