27
27
# Environment variables:
28
28
#
29
29
# GITHUB_TOKEN GitHub token for authentication.
30
+ # DEBUG Whether to enable verbose debug output. Default: `false`.
30
31
31
32
# Ensure that the exit status of pipelines is non-zero in the event that at least one of the commands in a pipeline fails:
32
33
set -o pipefail
@@ -44,9 +45,22 @@ github_api_url="https://api.github.com"
44
45
repo_owner=" stdlib-js"
45
46
repo_name=" stdlib"
46
47
48
+ # Set debug mode:
49
+ debug=" ${DEBUG:- false} "
50
+
47
51
48
52
# FUNCTIONS #
49
53
54
+ # Prints debug messages if DEBUG environment variable is set to "true".
55
+ #
56
+ # $1 - debug message
57
+ debug_log () {
58
+ # Only print debug messages if DEBUG environment variable is set to "true":
59
+ if [ " $debug " = true ]; then
60
+ echo " [DEBUG] $1 " >&2
61
+ fi
62
+ }
63
+
50
64
# Error handler.
51
65
#
52
66
# $1 - error status
@@ -70,6 +84,8 @@ github_api() {
70
84
local endpoint=" $2 "
71
85
local data=" $3 "
72
86
87
+ debug_log " Making API request: ${method} ${endpoint} "
88
+
73
89
# Initialize an array to hold curl headers:
74
90
local headers=()
75
91
@@ -117,12 +133,20 @@ main() {
117
133
on_error 1
118
134
fi
119
135
136
+ debug_log " Processing PR #${pr_number} "
137
+
120
138
# Fetch changed files in pull request:
121
139
response=$( github_api " GET" " /repos/${repo_owner} /${repo_name} /pulls/${pr_number} /files?per_page=100" )
122
140
files=$( echo " ${response} " | jq -r ' .[] | .filename' )
141
+ debug_log " Found $( echo " ${files} " | wc -l) changed files"
123
142
124
143
# Extract files associated with native add-ons:
125
144
c_files=$( echo " ${files} " | grep -e ' /benchmark/c' -e ' /examples/c' -e ' /binding.gyp' -e ' /include.gypi' -e ' /src/' )
145
+ if [[ -z " ${c_files} " ]]; then
146
+ debug_log " No native add-on files found"
147
+ else
148
+ debug_log " Found native add-on files: $( echo " ${c_files} " | wc -l) files"
149
+ fi
126
150
127
151
# Find unique package directories:
128
152
directories=$( echo " ${files} " | tr ' ' ' \n' | \
@@ -133,6 +157,7 @@ main() {
133
157
134
158
# Extract package names from changed package directories (e.g., @stdlib/math/base/special/sin) by removing the leading 'lib/node_modules/':
135
159
packages=$( echo " ${directories} " | sed -E ' s/^lib\/node_modules\///' )
160
+ debug_log " Found packages: $( echo " ${packages} " | tr ' \n' ' ' ) "
136
161
137
162
# Documentation links:
138
163
docs_links="
@@ -148,9 +173,11 @@ main() {
148
173
149
174
# Count the number of packages:
150
175
package_count=$( echo " ${packages} " | wc -l)
176
+ debug_log " Package count: ${package_count} "
151
177
152
178
if [[ $package_count -gt 1 ]]; then
153
179
# Multiple packages case:
180
+ debug_log " Multiple packages detected, generating multi-package comment"
154
181
comment=" Hello! 👋
155
182
156
183
Pro-tip: This PR changes multiple packages. You can use various \` make\` rules with \` *_FILTER\` environment variables to run tests, benchmarks, and examples for specific packages.
@@ -174,7 +201,9 @@ ${docs_links}"
174
201
175
202
else
176
203
# Single package case:
177
- if [[ " ${# c_files[@]} " -eq 0 ]]; then
204
+ debug_log " Single package detected: ${packages} "
205
+ if [[ -z " ${c_files} " ]]; then
206
+ debug_log " No C files found, generating JS-only comment"
178
207
comment=" Hello! 👋
179
208
180
209
Pro-tip: Use the \` make\` commands below during local development to ensure that all tests, examples, and benchmark files in your PR run successfully.
@@ -200,6 +229,7 @@ make examples EXAMPLES_FILTER=\".*/${packages}/.*\"
200
229
\`\`\`
201
230
${docs_links} "
202
231
else
232
+ debug_log " C files found, generating native addon comment"
203
233
comment=" Hello! 👋
204
234
205
235
Pro-tip: Use the \` make\` below commands during local development to ensure that all tests, examples, and benchmark files in your PR run successfully.
@@ -241,10 +271,12 @@ ${docs_links}"
241
271
fi
242
272
fi
243
273
274
+ debug_log " Posting comment on PR #${pr_number} "
244
275
if ! github_api " POST" " /repos/${repo_owner} /${repo_name} /issues/${pr_number} /comments" " {\" body\" :$( echo " ${comment} " | jq -R -s -c .) }" ; then
245
276
echo " Failed to post comment on PR."
246
277
on_error 1
247
278
fi
279
+ debug_log " Successfully posted comment on PR #${pr_number} "
248
280
249
281
print_success
250
282
exit 0
0 commit comments