-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tool to check unmapped fields in Alloy (#1723)
- Loading branch information
Showing
2 changed files
with
553 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
name: Alloy Mapped Fields Checker | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- 'pkg/**/*.go' | ||
|
||
jobs: | ||
check-config: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
issues: write | ||
contents: read | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
cache: false # Disable caching to avoid extraction conflicts | ||
check-latest: true | ||
|
||
- name: Run alloy field checker | ||
id: field-checker | ||
run: | | ||
# First compile the checker to ensure it builds | ||
cd tools/alloy-field-checker | ||
go build -o field-checker | ||
if [ $? -ne 0 ]; then | ||
echo "Failed to build field checker" | ||
exit 1 | ||
fi | ||
# Move back to workspace root and run the checker | ||
cd ../.. | ||
if [ ! -d "pkg" ]; then | ||
echo "pkg directory not found in $(pwd)" | ||
ls -la | ||
exit 1 | ||
fi | ||
tools/alloy-field-checker/field-checker 2>&1 | tee output.txt | ||
if [ ${PIPESTATUS[0]} -ne 0 ]; then | ||
# Create a normalized version of the output (remove line numbers which can change) | ||
grep "unmapped fields:" output.txt > /dev/null && { | ||
echo "has_unmapped=true" >> $GITHUB_OUTPUT | ||
echo "unmapped_fields<<EOF" >> $GITHUB_OUTPUT | ||
# Extract just the field names and struct names, ignore line numbers | ||
grep -o "[a-zA-Z0-9]\+\.[a-zA-Z0-9]\+ (tag: [^)]\+)" output.txt | sort > normalized_output.txt | ||
cat normalized_output.txt >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
} || { | ||
echo "has_unmapped=false" >> $GITHUB_OUTPUT | ||
} | ||
else | ||
echo "has_unmapped=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Find existing issues | ||
if: steps.field-checker.outputs.has_unmapped == 'true' | ||
uses: actions/github-script@v7 | ||
id: find-issue | ||
with: | ||
script: | | ||
const issues = await github.rest.issues.listForRepo({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
state: 'open', | ||
labels: [] | ||
}); | ||
const existingIssue = issues.data.find(issue => | ||
issue.title === 'Map missing Beyla options in Alloy component' | ||
); | ||
return existingIssue ? existingIssue.number : 0; | ||
result-encoding: string | ||
|
||
- name: Manage issue | ||
if: steps.field-checker.outputs.has_unmapped == 'true' | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const issueNumber = parseInt('${{ steps.find-issue.outputs.result }}'); | ||
const issueBody = `Unmapped configuration fields were detected in Beyla's Alloy component: | ||
\`\`\` | ||
${process.env.UNMAPPED_FIELDS} | ||
\`\`\` | ||
Please ensure all configuration fields are properly mapped in the Alloy configuration. | ||
This issue was automatically generated by the config-checker workflow.`; | ||
if (issueNumber > 0) { | ||
// Update existing issue | ||
await github.rest.issues.update({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
body: issueBody | ||
}); | ||
} else { | ||
// Create new issue | ||
await github.rest.issues.create({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
title: 'Map missing Beyla options in Alloy component', | ||
body: issueBody, | ||
assignee: context.repo.owner | ||
}); | ||
} | ||
env: | ||
UNMAPPED_FIELDS: ${{ steps.field-checker.outputs.unmapped_fields }} | ||
|
||
- name: Close issue if no unmapped fields | ||
if: steps.field-checker.outputs.has_unmapped == 'false' | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const issues = await github.rest.issues.listForRepo({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
state: 'open', | ||
labels: [] | ||
}); | ||
const existingIssue = issues.data.find(issue => | ||
issue.title === 'Map missing Beyla options in Alloy component' | ||
); | ||
if (existingIssue) { | ||
await github.rest.issues.update({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: existingIssue.number, | ||
state: 'closed', | ||
state_reason: 'completed' | ||
}); | ||
} |
Oops, something went wrong.