Skip to content

Commit dc3be18

Browse files
GHA-190 Refactor rule metadata summary generation and update PR creation step (#98)
1 parent 12cd128 commit dc3be18

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

.github/workflows/test-update-rule-metadata.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
fi
118118
119119
# Test that PR creation uses the branch input for base
120-
if grep -A20 "peter-evans/create-pull-request" update-rule-metadata/action.yml | grep -q "base.*inputs.branch"; then
120+
if grep -A20 "create-pull-request" update-rule-metadata/action.yml | grep -q "base.*inputs.branch"; then
121121
echo "✓ PR creation uses branch input for base"
122122
else
123123
echo "✗ PR creation does not use branch input for base"

update-rule-metadata/action.yml

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,43 +161,51 @@ runs:
161161
shell: bash
162162
run: |
163163
rm rule-api.jar
164-
164+
165165
- name: Generate summary
166166
id: generate-summary
167167
shell: bash
168168
run: |
169-
summary=""
169+
summary_file="rule-api-summary.md"
170170
current_sonarpedia=""
171+
has_entries=false
172+
total_rules=0
173+
174+
# Build a markdown table
175+
echo "| Sonarpedia | Rules to update |" > "$summary_file"
176+
echo "|---|---:|" >> "$summary_file"
171177
172178
while IFS= read -r line; do
173179
if [[ $line == "=== "* ]]; then
174180
current_sonarpedia=$(echo "$line" | sed 's/=== \(.*\) ===/\1/')
175181
elif [[ $line == *"Found "* && $line == *" rule(s) to update"* ]]; then
176182
rule_count=$(echo "$line" | grep -o 'Found [0-9]\+' | grep -o '[0-9]\+')
177183
if [[ -n "$rule_count" && "$rule_count" != "0" && -n "$current_sonarpedia" ]]; then
178-
if [[ -n "$summary" ]]; then
179-
summary="${summary},\n"
180-
fi
181-
summary="${summary} ${rule_count} rules for ${current_sonarpedia}"
184+
echo "| \`${current_sonarpedia}\` | ${rule_count} |" >> "$summary_file"
185+
total_rules=$((total_rules + rule_count))
186+
has_entries=true
182187
fi
183188
fi
184189
done < rule-api-logs.txt
185190
186-
if [[ -z "$summary" ]]; then
187-
summary="Update rule metadata"
191+
if [[ "$has_entries" == "true" ]]; then
192+
echo "| **Total** | **${total_rules}** |" >> "$summary_file"
193+
fi
194+
195+
# Write summary to output using delimiter to preserve newlines
196+
if [[ "$has_entries" == "false" ]]; then
197+
echo "summary=Update rule metadata" >> $GITHUB_OUTPUT
188198
else
189-
summary="Check rule metadata for:\n ${summary}"
199+
{
200+
echo "summary<<EOF"
201+
cat "$summary_file"
202+
echo "EOF"
203+
} >> $GITHUB_OUTPUT
190204
fi
191205
192-
echo "summary=${summary}" >> $GITHUB_OUTPUT
193206
rm rule-api-logs.txt
207+
rm -f "$summary_file"
194208
195-
- name: Prepare summary for PR
196-
id: pr-summary
197-
shell: bash
198-
run: |
199-
echo "summary=${{ steps.generate-summary.outputs.summary }}" | sed ':a;N;$!ba;s/\n/<br>/g' >> $GITHUB_OUTPUT
200-
201209
- name: Check Rule Metadata Changes
202210
id: check-changes
203211
shell: bash
@@ -221,14 +229,14 @@ runs:
221229
- name: Create PR
222230
if: ${{ steps.check-changes.outputs.has-changes == 'true' }}
223231
id: create-pr
224-
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
232+
uses: SonarSource/release-github-actions/create-pull-request@v1
225233
with:
226234
commit-message: Update rule metadata
227235
title: Update rule metadata
228236
body: |
229237
## Rule Metadata Update Summary
230238
231-
${{ steps.pr-summary.outputs.summary }}
239+
${{ steps.generate-summary.outputs.summary }}
232240
233241
This PR was automatically generated to update rule metadata across all supported languages.
234242
base: ${{ inputs.branch }}

0 commit comments

Comments
 (0)