Skip to content

Commit 3654635

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into update-package-meta-data
2 parents b70f98b + 99e32d3 commit 3654635

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

.github/workflows/pr_commands_comment.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ on:
2929
description: 'Pull request number'
3030
required: true
3131
type: number
32+
debug:
33+
description: 'Enable debug output'
34+
required: false
35+
default: false
36+
type: boolean
3237

3338
# Define the secrets accessible by the workflow:
3439
secrets:
@@ -43,6 +48,14 @@ on:
4348
description: 'Pull request number'
4449
required: true
4550
type: number
51+
debug:
52+
description: 'Enable debug output'
53+
required: false
54+
default: 'false'
55+
type: choice
56+
options:
57+
- 'true'
58+
- 'false'
4659

4760
# Global permissions:
4861
permissions:
@@ -78,7 +91,8 @@ jobs:
7891
- name: 'Leave comment with package make command instructions'
7992
env:
8093
PR_NUMBER: ${{ inputs.pull_request_number }}
81-
GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
94+
GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN || secrets.STDLIB_BOT_PAT_REPO_WRITE }}
95+
DEBUG: ${{ inputs.debug || 'false' }}
8296
run: |
8397
. "$GITHUB_WORKSPACE/.github/workflows/scripts/package_commands_comment" "$PR_NUMBER"
8498
timeout-minutes: 30

.github/workflows/scripts/package_commands_comment

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
# Environment variables:
2828
#
2929
# GITHUB_TOKEN GitHub token for authentication.
30+
# DEBUG Whether to enable verbose debug output. Default: `false`.
3031

3132
# Ensure that the exit status of pipelines is non-zero in the event that at least one of the commands in a pipeline fails:
3233
set -o pipefail
@@ -44,9 +45,22 @@ github_api_url="https://api.github.com"
4445
repo_owner="stdlib-js"
4546
repo_name="stdlib"
4647

48+
# Set debug mode:
49+
debug="${DEBUG:-false}"
50+
4751

4852
# FUNCTIONS #
4953

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+
5064
# Error handler.
5165
#
5266
# $1 - error status
@@ -70,6 +84,8 @@ github_api() {
7084
local endpoint="$2"
7185
local data="$3"
7286

87+
debug_log "Making API request: ${method} ${endpoint}"
88+
7389
# Initialize an array to hold curl headers:
7490
local headers=()
7591

@@ -117,12 +133,20 @@ main() {
117133
on_error 1
118134
fi
119135

136+
debug_log "Processing PR #${pr_number}"
137+
120138
# Fetch changed files in pull request:
121139
response=$(github_api "GET" "/repos/${repo_owner}/${repo_name}/pulls/${pr_number}/files?per_page=100")
122140
files=$(echo "${response}" | jq -r '.[] | .filename')
141+
debug_log "Found $(echo "${files}" | wc -l) changed files"
123142

124143
# Extract files associated with native add-ons:
125144
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
126150

127151
# Find unique package directories:
128152
directories=$(echo "${files}" | tr ' ' '\n' | \
@@ -133,6 +157,7 @@ main() {
133157

134158
# Extract package names from changed package directories (e.g., @stdlib/math/base/special/sin) by removing the leading 'lib/node_modules/':
135159
packages=$(echo "${directories}" | sed -E 's/^lib\/node_modules\///')
160+
debug_log "Found packages: $(echo "${packages}" | tr '\n' ' ')"
136161

137162
# Documentation links:
138163
docs_links="
@@ -148,9 +173,11 @@ main() {
148173

149174
# Count the number of packages:
150175
package_count=$(echo "${packages}" | wc -l)
176+
debug_log "Package count: ${package_count}"
151177

152178
if [[ $package_count -gt 1 ]]; then
153179
# Multiple packages case:
180+
debug_log "Multiple packages detected, generating multi-package comment"
154181
comment="Hello! 👋
155182
156183
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}"
174201

175202
else
176203
# 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"
178207
comment="Hello! 👋
179208
180209
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}/.*\"
200229
\`\`\`
201230
${docs_links}"
202231
else
232+
debug_log "C files found, generating native addon comment"
203233
comment="Hello! 👋
204234
205235
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}"
241271
fi
242272
fi
243273

274+
debug_log "Posting comment on PR #${pr_number}"
244275
if ! github_api "POST" "/repos/${repo_owner}/${repo_name}/issues/${pr_number}/comments" "{\"body\":$(echo "${comment}" | jq -R -s -c .)}"; then
245276
echo "Failed to post comment on PR."
246277
on_error 1
247278
fi
279+
debug_log "Successfully posted comment on PR #${pr_number}"
248280

249281
print_success
250282
exit 0

0 commit comments

Comments
 (0)