44 pull_request :
55 types : [opened, synchronize, reopened]
66
7+ concurrency :
8+ group : metrics-check-${{ github.event.pull_request.number }}
9+ cancel-in-progress : true
10+
711jobs :
812 check-metrics-changes :
913 runs-on : ubuntu-latest
3034 fi
3135
3236 # Regex pattern to match metric-related code changes
33- METRIC_REGEX_PATTERN="(counter!|gauge!|histogram!|#\\[metrics\\])"
37+ METRIC_REGEX_PATTERN="(counter!|gauge!|histogram!|#\\[metrics\\])" # ci trigger
3438
3539 # Check for metric-related changes
3640 METRIC_CHANGES=$(git diff $BASE_COMMIT..HEAD --unified=0 | grep -E "$METRIC_REGEX_PATTERN" || true)
@@ -44,43 +48,39 @@ jobs:
4448
4549 # Set output variables for the comment step
4650 echo "metric_changes_found=$([ -n "$METRIC_CHANGES" ] && echo "true" || echo "false")" >> $GITHUB_OUTPUT
47- echo "metric_pattern=$METRIC_REGEX_PATTERN" >> $GITHUB_OUTPUT
51+ echo "metric_changes<<EOF" >> $GITHUB_OUTPUT
52+ echo "$METRIC_CHANGES" >> $GITHUB_OUTPUT
53+ echo "EOF" >> $GITHUB_OUTPUT
54+
55+ - name : Look for previous comment
56+ if : github.repository == github.event.pull_request.head.repo.full_name && steps.check-metrics.outputs.metric_changes_found == 'true'
57+ id : find-comment
58+ uses : peter-evans/find-comment@v3
59+ with :
60+ issue-number : ${{ github.event.pull_request.number }}
61+ comment-author : github-actions[bot]
62+ body-includes : " ## Metrics Change Detection ⚠️"
4863
4964 - name : Comment on PR (if applicable)
5065 if : github.repository == github.event.pull_request.head.repo.full_name && steps.check-metrics.outputs.metric_changes_found == 'true'
51- uses : actions/github-script@v7
66+ uses : peter-evans/create-or-update-comment@v4
5267 with :
53- script : |
54- const { execSync } = require('child_process');
55-
56- try {
57- // Get the base commit for comparison
58- const baseCommit = context.payload.pull_request.base.sha;
59-
60- // Get the metric pattern from the previous step
61- const metricPattern = "${{ steps.check-metrics.outputs.metric_pattern }}";
62-
63- // Check for metric changes
64- const metricChanges = execSync(`git diff ${baseCommit}..HEAD --unified=0 | grep -E "${metricPattern}" || true`, { encoding: 'utf8' });
65-
66- if (metricChanges.trim()) {
67- const comment = '## Metrics Change Detection ⚠️\n\n' +
68- 'This PR contains changes related to metrics:\n\n' +
69- '```\n' +
70- metricChanges +
71- '\n```\n\n' +
72- 'However, the dashboard was not modified.\n\n' +
73- 'You may need to update `benchmark/Grafana-dashboard.json` accordingly.\n\n' +
74- '---\n' +
75- '*This check is automated to help maintain the dashboard.*';
76-
77- github.rest.issues.createComment({
78- issue_number: context.issue.number,
79- owner: context.repo.owner,
80- repo: context.repo.repo,
81- body: comment
82- });
83- }
84- } catch (error) {
85- console.log('No metric changes found or error occurred:', error.message);
86- }
68+ issue-number : ${{ github.event.pull_request.number }}
69+ body : |
70+ ## Metrics Change Detection ⚠️
71+
72+ This PR contains changes related to metrics:
73+
74+ ```
75+ ${{ steps.check-metrics.outputs.metric_changes }}
76+ ```
77+
78+ However, the dashboard was not modified.
79+
80+ You may need to update `benchmark/Grafana-dashboard.json` accordingly.
81+
82+ ---
83+
84+ *This check is automated to help maintain the dashboard.*
85+ edit-mode : replace
86+ comment-id : ${{ steps.find-comment.outputs.comment-id }}
0 commit comments