Skip to content

Commit f29a736

Browse files
committed
build: simplify and leave comment when multiple packages are changed
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: passed - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent f82ffc9 commit f29a736

File tree

1 file changed

+57
-25
lines changed

1 file changed

+57
-25
lines changed

.github/workflows/scripts/package_commands_comment

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ main() {
119119

120120
# Fetch changed files in pull request (no need to paginate because skipping PRs affecting multiple packages anyway):
121121
response=$(github_api "GET" "/repos/${repo_owner}/${repo_name}/pulls/${pr_number}/files?per_page=100")
122-
files=$(echo $response | jq -r '.[] | .filename')
122+
files=$(echo "${response}" | jq -r '.[] | .filename')
123123

124124
# Extract files associated with native add-ons:
125-
c_files=$(echo $files | grep -e '/benchmark/c' -e '/examples/c' -e '/binding.gyp' -e '/include.gypi' -e '/src/')
125+
c_files=$(echo "${files}" | grep -e '/benchmark/c' -e '/examples/c' -e '/binding.gyp' -e '/include.gypi' -e '/src/')
126126

127127
# Find unique package directories:
128128
directories=$(echo "${files}" | tr ' ' '\n' | \
@@ -134,11 +134,48 @@ main() {
134134
# Extract package names from changed package directories (e.g., @stdlib/math/base/special/sin) by removing the leading 'lib/node_modules/':
135135
packages=$(echo "${directories}" | sed -E 's/^lib\/node_modules\///')
136136

137-
case "$packages" in
138-
*)
139-
# Post a comment on the PR when only a single package is changed in PR:
140-
if [[ "${#c_files[@]}" -eq 0 ]]; then
141-
comment="Hello! 👋
137+
# Documentation links:
138+
docs_links="
139+
## Documentation Links
140+
141+
- [make rules for running examples][make-docs-examples]
142+
- [make rules for running project unit tests][make-docs-test]
143+
- [make rules for running benchmarks][make-docs-benchmark]
144+
145+
[make-docs-examples]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/examples/README.md
146+
[make-docs-test]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/test/README.md
147+
[make-docs-benchmark]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/benchmark/README.md"
148+
149+
# Count the number of packages:
150+
package_count=$(echo "${packages}" | wc -l)
151+
152+
if [[ $package_count -gt 1 ]]; then
153+
# Multiple packages case:
154+
comment="Hello! 👋
155+
156+
Pro-tip: This PR changes multiple packages. You can use various \`make′ rules with \`*_FILTERS\` environment variables to run tests, benchmarks, and examples for specific packages.
157+
158+
For each of the commands, please run them from the root stdlib repository directory (not the package folder!).
159+
160+
You can use pattern matching to target specific packages as follows:
161+
162+
\`\`\`bash
163+
# Run tests for all packages in the math namespace:
164+
make test TESTS_FILTER=\".*/@stdlib/math/.*\"
165+
166+
# Run benchmarks for specific packages (using OR pattern):
167+
make benchmark BENCHMARKS_FILTER=\".*/@stdlib/math/base/special/sin/.*|.*/@stdlib/math/base/special/cos/.*\"
168+
\`\`\`
169+
170+
## Changed Packages
171+
172+
$(echo "${packages}" | sed 's/^/- `/' | sed 's/$/`/')
173+
${docs_links}"
174+
175+
else
176+
# Single package case:
177+
if [[ "${#c_files[@]}" -eq 0 ]]; then
178+
comment="Hello! 👋
142179
143180
Pro-tip: Use the below \`make\` commands during local development to ensure that all tests, examples, and benchmark files in your PR run successfully.
144181
@@ -161,9 +198,9 @@ To run examples,
161198
\`\`\`bash
162199
make examples EXAMPLES_FILTER=\".*/${packages}/.*\"
163200
\`\`\`
164-
"
165-
else
166-
comment="Hello! 👋
201+
${docs_links}"
202+
else
203+
comment="Hello! 👋
167204
168205
Pro-tip: Use the below \`make\` commands during local development to ensure that all tests, examples, and benchmark files in your PR run successfully.
169206
@@ -172,7 +209,7 @@ For each of the commands, please run them from the root stdlib repository direct
172209
To build the native add-on,
173210
174211
\`\`\`bash
175-
NODE_ADDONS_PATTERN="${packages}" make install-node-addons
212+
NODE_ADDONS_PATTERN=\"${packages}\" make install-node-addons
176213
\`\`\`
177214
178215
To run unit tests,
@@ -200,22 +237,17 @@ make examples EXAMPLES_FILTER=\".*/${packages}/.*\"
200237
\`\`\`bash
201238
make examples-c EXAMPLES_FILTER=\".*/${packages}/.*\"
202239
\`\`\`
203-
"
204-
fi
240+
${docs_links}"
241+
fi
242+
fi
205243

206-
if ! github_api "POST" "/repos/${repo_owner}/${repo_name}/issues/${pr_number}/comments" "{\"body\":$(echo "${comment}" | jq -R -s -c .)}"; then
207-
echo "Failed to post comment on PR."
208-
on_error 1
209-
fi
244+
if ! github_api "POST" "/repos/${repo_owner}/${repo_name}/issues/${pr_number}/comments" "{\"body\":$(echo "${comment}" | jq -R -s -c .)}"; then
245+
echo "Failed to post comment on PR."
246+
on_error 1
247+
fi
210248

211-
exit 0
212-
;;
213-
*\ * )
214-
echo "Skip leaving comment for PRs changing multiple packages."
215-
print_success
216-
exit 0
217-
;;
218-
esac
249+
print_success
250+
exit 0
219251
}
220252

221253
main

0 commit comments

Comments
 (0)