-
-
Notifications
You must be signed in to change notification settings - Fork 908
build: add workflow and script to leave comment with make instructions #5640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3774388
build: add workflow and script to leave comment with make instructions
Planeshifter f82ffc9
build: rename slash command
Planeshifter 8b4e5ca
build: simplify and leave comment when multiple packages are changed
Planeshifter 18c033f
build: also check for capital X when verifying contributing guideline…
Planeshifter 9c92eed
build: address PR feedback
Planeshifter 5b3cf06
Apply suggestions from code review
kgryte e61f2b3
docs: update comment
kgryte e1f8224
chore: update copy
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#/ | ||
# @license Apache-2.0 | ||
# | ||
# Copyright (c) 2025 The Stdlib Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#/ | ||
|
||
# Workflow name: | ||
name: pr_commands_comment | ||
|
||
# Workflow triggers: | ||
on: | ||
# Allow the workflow to be triggered by other workflows | ||
workflow_call: | ||
# Define the input parameters for the workflow: | ||
inputs: | ||
pull_request_number: | ||
description: 'Pull request number' | ||
required: true | ||
type: number | ||
|
||
# Define the secrets accessible by the workflow: | ||
secrets: | ||
STDLIB_BOT_GITHUB_TOKEN: | ||
description: 'stdlib-bot GitHub token to create pull request comments' | ||
required: true | ||
|
||
# Allow the workflow to be manually triggered: | ||
workflow_dispatch: | ||
inputs: | ||
pull_request_number: | ||
description: 'Pull request number' | ||
required: true | ||
type: number | ||
|
||
# Global permissions: | ||
permissions: | ||
# Allow read-only access to the repository contents: | ||
contents: read | ||
|
||
# Workflow jobs: | ||
jobs: | ||
|
||
# Define a job for leaving a comment on a PR with package make command instructions: | ||
pr_commands_comment: | ||
|
||
# Define a display name: | ||
name: 'Leave comment with package make command instructions' | ||
|
||
# Define the type of virtual host machine: | ||
runs-on: ubuntu-latest | ||
|
||
# Define the sequence of job steps... | ||
steps: | ||
|
||
# Leave comment with package make command instructions: | ||
- name: 'Leave comment with package make command instructions' | ||
env: | ||
PR_NUMBER: ${{ inputs.pull_request_number }} | ||
run: | | ||
. "$GITHUB_WORKSPACE/.github/workflows/scripts/package_commands_comment" "$PR_NUMBER" | ||
timeout-minutes: 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,253 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# @license Apache-2.0 | ||
# | ||
# Copyright (c) 2025 The Stdlib Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Script to post a comment with relevant `make` commands tailored to package changed in a PR. | ||
# | ||
# Usage: package_commands_comment <pr_number> | ||
# | ||
# Arguments: | ||
# | ||
# pr_number Pull request number. | ||
# | ||
# Environment variables: | ||
# | ||
# GITHUB_TOKEN GitHub token for authentication. | ||
|
||
# Ensure that the exit status of pipelines is non-zero in the event that at least one of the commands in a pipeline fails: | ||
set -o pipefail | ||
|
||
|
||
# VARIABLES # | ||
|
||
# Resolve the pull request number: | ||
pr_number="$1" | ||
|
||
# GitHub API base URL: | ||
github_api_url="https://api.github.com" | ||
|
||
# Repository owner and name: | ||
repo_owner="stdlib-js" | ||
repo_name="stdlib" | ||
|
||
|
||
# FUNCTIONS # | ||
|
||
# Error handler. | ||
# | ||
# $1 - error status | ||
on_error() { | ||
echo 'ERROR: An error was encountered during execution.' >&2 | ||
exit "$1" | ||
} | ||
|
||
# Prints a success message. | ||
print_success() { | ||
echo 'Success!' >&2 | ||
} | ||
|
||
# Performs a GitHub API request. | ||
# | ||
# $1 - HTTP method (GET or POST) | ||
# $2 - API endpoint | ||
# $3 - data for POST requests | ||
github_api() { | ||
local method="$1" | ||
local endpoint="$2" | ||
local data="$3" | ||
|
||
# Initialize an array to hold curl headers: | ||
local headers=() | ||
|
||
# If GITHUB_TOKEN is set, add the Authorization header: | ||
if [ -n "${GITHUB_TOKEN}" ]; then | ||
headers+=("-H" "Authorization: token ${GITHUB_TOKEN}") | ||
fi | ||
|
||
# Determine the HTTP method and construct the curl command accordingly... | ||
case "${method}" in | ||
GET) | ||
curl -s "${headers[@]}" "${github_api_url}${endpoint}" | ||
;; | ||
POST) | ||
# For POST requests, always set the Content-Type header: | ||
headers+=("-H" "Content-Type: application/json") | ||
|
||
# If data is provided, include it in the request: | ||
if [ -n "${data}" ]; then | ||
curl -s -X POST "${headers[@]}" -d "${data}" "${github_api_url}${endpoint}" | ||
else | ||
# Handle cases where POST data is required but not provided: | ||
echo "ERROR: POST request requires data." | ||
on_error 1 | ||
fi | ||
;; | ||
*) | ||
echo "ERROR: Invalid HTTP method: ${method}." | ||
on_error 1 | ||
;; | ||
esac | ||
} | ||
|
||
# Main execution sequence. | ||
main() { | ||
local directories | ||
local packages | ||
local response | ||
local c_files | ||
local comment | ||
local files | ||
|
||
if [ -z "${pr_number}" ]; then | ||
echo "ERROR: Pull request number is required." >&2 | ||
on_error 1 | ||
fi | ||
|
||
# Fetch changed files in pull request (no need to paginate because skipping PRs affecting multiple packages anyway): | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
response=$(github_api "GET" "/repos/${repo_owner}/${repo_name}/pulls/${pr_number}/files?per_page=100") | ||
files=$(echo "${response}" | jq -r '.[] | .filename') | ||
|
||
# Extract files associated with native add-ons: | ||
c_files=$(echo "${files}" | grep -e '/benchmark/c' -e '/examples/c' -e '/binding.gyp' -e '/include.gypi' -e '/src/') | ||
|
||
# Find unique package directories: | ||
directories=$(echo "${files}" | tr ' ' '\n' | \ | ||
xargs dirname | \ | ||
grep '^lib/node_modules/@stdlib' | \ | ||
sed -E 's/\/(benchmark|bin|data|docs|etc|examples|include|lib|scripts|src|test)(\/.*)?$//' | \ | ||
sort -u) | ||
|
||
# Extract package names from changed package directories (e.g., @stdlib/math/base/special/sin) by removing the leading 'lib/node_modules/': | ||
packages=$(echo "${directories}" | sed -E 's/^lib\/node_modules\///') | ||
|
||
# Documentation links: | ||
docs_links=" | ||
## Documentation Links | ||
|
||
- [make rules for running examples][make-docs-examples] | ||
- [make rules for running project unit tests][make-docs-test] | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- [make rules for running benchmarks][make-docs-benchmark] | ||
|
||
[make-docs-examples]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/examples/README.md | ||
[make-docs-test]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/test/README.md | ||
[make-docs-benchmark]: https://github.com/stdlib-js/stdlib/blob/develop/tools/make/lib/benchmark/README.md" | ||
|
||
# Count the number of packages: | ||
package_count=$(echo "${packages}" | wc -l) | ||
|
||
if [[ $package_count -gt 1 ]]; then | ||
# Multiple packages case: | ||
comment="Hello! 👋 | ||
|
||
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. | ||
|
||
For each of the commands, please run them from the root stdlib repository directory (not the package folder!). | ||
|
||
You can use pattern matching to target specific packages as follows: | ||
|
||
\`\`\`bash | ||
# Run tests for all packages in the math namespace: | ||
make test TESTS_FILTER=\".*/@stdlib/math/.*\" | ||
|
||
# Run benchmarks for specific packages (using OR pattern): | ||
make benchmark BENCHMARKS_FILTER=\".*/@stdlib/math/base/special/(sin|cos)/.*\" | ||
\`\`\` | ||
|
||
## Changed Packages | ||
|
||
$(echo "${packages}" | sed 's/^/- `/' | sed 's/$/`/') | ||
${docs_links}" | ||
|
||
else | ||
# Single package case: | ||
if [[ "${#c_files[@]}" -eq 0 ]]; then | ||
comment="Hello! 👋 | ||
|
||
Pro-tip: Use the below \`make\` commands during local development to ensure that all tests, examples, and benchmark files in your PR run successfully. | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
For each of the commands, please run them from the root stdlib repository directory (not the package folder!). | ||
|
||
To run unit tests, | ||
|
||
\`\`\`bash | ||
make test TESTS_FILTER=\".*/${packages}/.*\" | ||
\`\`\` | ||
|
||
To run benchmarks, | ||
|
||
\`\`\`bash | ||
make benchmark BENCHMARKS_FILTER=\".*/${packages}/.*\" | ||
\`\`\` | ||
|
||
To run examples, | ||
|
||
\`\`\`bash | ||
make examples EXAMPLES_FILTER=\".*/${packages}/.*\" | ||
\`\`\` | ||
${docs_links}" | ||
else | ||
comment="Hello! 👋 | ||
|
||
Pro-tip: Use the below \`make\` commands during local development to ensure that all tests, examples, and benchmark files in your PR run successfully. | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
For each of the commands, please run them from the root stdlib repository directory (not the package folder!). | ||
|
||
To build the native add-on, | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
\`\`\`bash | ||
NODE_ADDONS_PATTERN=\"${packages}\" make install-node-addons | ||
\`\`\` | ||
|
||
To run unit tests, | ||
|
||
\`\`\`bash | ||
make test TESTS_FILTER=\".*/${packages}/.*\" | ||
\`\`\` | ||
|
||
To run benchmarks, | ||
|
||
\`\`\`bash | ||
make benchmark BENCHMARKS_FILTER=\".*/${packages}/.*\" | ||
\`\`\` | ||
|
||
\`\`\`bash | ||
make benchmark-c BENCHMARKS_FILTER=\".*/${packages}/.*\" | ||
\`\`\` | ||
|
||
To run examples, | ||
|
||
\`\`\`bash | ||
make examples EXAMPLES_FILTER=\".*/${packages}/.*\" | ||
\`\`\` | ||
|
||
\`\`\`bash | ||
make examples-c EXAMPLES_FILTER=\".*/${packages}/.*\" | ||
\`\`\` | ||
${docs_links}" | ||
fi | ||
fi | ||
|
||
if ! github_api "POST" "/repos/${repo_owner}/${repo_name}/issues/${pr_number}/comments" "{\"body\":$(echo "${comment}" | jq -R -s -c .)}"; then | ||
echo "Failed to post comment on PR." | ||
on_error 1 | ||
fi | ||
|
||
print_success | ||
exit 0 | ||
} | ||
|
||
main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.