Skip to content

Commit 4fb75ab

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 8f745c7 + 23702bf commit 4fb75ab

File tree

15 files changed

+1000
-143
lines changed

15 files changed

+1000
-143
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2024 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# Workflow name:
20+
name: generate_pr_commit_message
21+
22+
# Workflow triggers:
23+
on:
24+
pull_request:
25+
types:
26+
- labeled
27+
28+
# Global permissions:
29+
permissions:
30+
contents: read
31+
issues: write
32+
pull-requests: write
33+
34+
# Workflow jobs:
35+
jobs:
36+
37+
# Job to generate commit message draft:
38+
generate-commit-message:
39+
40+
# Define a display name:
41+
name: 'Generate PR Commit Message Draft'
42+
43+
# Define the type of virtual host machine:
44+
runs-on: ubuntu-latest
45+
46+
# Ensure the job only runs when the specified label is added:
47+
if: github.event.label.name == 'Ready to Merge'
48+
49+
# Define environment variables:
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
PR_NUMBER: ${{ github.event.pull_request.number }}
53+
54+
# Define the sequence of job steps...
55+
steps:
56+
# Checkout repository:
57+
- name: 'Checkout repository'
58+
uses: actions/checkout@v4
59+
with:
60+
# Fetch all commits to ensure we have the full commit history:
61+
fetch-depth: 0
62+
63+
# Generate commit message:
64+
- name: 'Generate commit message'
65+
id: commit_message
66+
run: |
67+
COMMIT_MESSAGE=$($GITHUB_WORKSPACE/.github/workflows/scripts/generate_pr_commit_message $PR_NUMBER)
68+
echo "commit_message<<EOF" >> $GITHUB_OUTPUT
69+
echo "$COMMIT_MESSAGE" >> $GITHUB_OUTPUT
70+
echo "EOF" >> $GITHUB_OUTPUT
71+
72+
# Post commit message as PR comment:
73+
- name: 'Post commit message as PR comment'
74+
uses: peter-evans/create-or-update-comment@v3
75+
with:
76+
token: ${{ secrets.CHATBOT_GITHUB_TOKEN }}
77+
issue-number: ${{ github.event.pull_request.number }}
78+
body: |
79+
### PR Commit Message
80+
81+
```text
82+
${{ steps.commit_message.outputs.commit_message }}
83+
```
84+
85+
*Please review the above commit message and make any necessary adjustments.*

.github/workflows/scripts/check_contributing_guidelines_acceptance

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ GITHUB_REPOSITORY="stdlib-js/stdlib"
4343
# Set the contributing guidelines link:
4444
CONTRIBUTING_LINK="https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md"
4545

46+
4647
# FUNCTIONS #
4748

4849
# Error handler.
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#!/bin/bash
2+
#/
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2024 The Stdlib Authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#/
19+
20+
# Script to generate a commit message for a pull request.
21+
#
22+
# Usage: generate_pr_commit_message PR_NUMBER
23+
#
24+
# Arguments:
25+
#
26+
# PR_NUMBER Pull request number.
27+
#
28+
# Environment variables:
29+
#
30+
# GITHUB_TOKEN GitHub token for authentication.
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:
33+
set -o pipefail
34+
35+
36+
# VARIABLES #
37+
38+
# Get the pull request number:
39+
pr_number="$1"
40+
41+
# GitHub API base URL
42+
GITHUB_API_URL="https://api.github.com"
43+
44+
# Repository owner and name
45+
REPO_OWNER="stdlib-js"
46+
REPO_NAME="stdlib"
47+
48+
49+
# FUNCTIONS #
50+
51+
# Error handler.
52+
#
53+
# $1 - error status
54+
on_error() {
55+
echo 'ERROR: An error was encountered during execution.' >&2
56+
exit "$1"
57+
}
58+
59+
# Function to resolve GitHub handle to name and email using .mailmap
60+
#
61+
# $1 - GitHub handle
62+
resolve_user() {
63+
local github_handle="$1"
64+
local mailmap_file=".mailmap"
65+
local name_email
66+
67+
# Try to find a match for the GitHub handle:
68+
name_email=$(grep -i "$github_handle" "$mailmap_file" | head -n 1)
69+
70+
if [ -n "$name_email" ]; then
71+
# Extract name and email from the matching line:
72+
echo "$name_email" | sed -E 's/^(.*)<(.*)>.*$/\1 <\2>/' | xargs
73+
else
74+
# If no match found, use the GitHub handle as is:
75+
echo "$github_handle <$github_handle@users.noreply.github.com>"
76+
fi
77+
}
78+
79+
# Function to make authenticated GitHub API requests
80+
#
81+
# $1 - HTTP method (GET or POST)
82+
# $2 - API endpoint
83+
# $3 - Data for POST requests
84+
github_api() {
85+
local method="$1"
86+
local endpoint="$2"
87+
local data="$3"
88+
89+
if [ "$method" == "GET" ]; then
90+
curl -s -H "Authorization: token $GITHUB_TOKEN" "$GITHUB_API_URL$endpoint"
91+
elif [ "$method" == "POST" ]; then
92+
curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -d "$data" "$GITHUB_API_URL$endpoint"
93+
else
94+
echo "Invalid HTTP method: $method"
95+
on_error 1
96+
fi
97+
}
98+
99+
# Main execution sequence.
100+
main() {
101+
# Fetch pull request details:
102+
pr_details=$(github_api "GET" "/repos/$REPO_OWNER/$REPO_NAME/pulls/$pr_number")
103+
pr_title=$(echo "$pr_details" | jq -r '.title')
104+
pr_body=$(echo "$pr_details" | jq -r '.body // ""')
105+
pr_url=$(echo "$pr_details" | jq -r '.html_url')
106+
107+
# Extract reviewers:
108+
pr_reviews=$(github_api "GET" "/repos/$REPO_OWNER/$REPO_NAME/pulls/$pr_number/reviews")
109+
reviewers=$(echo "$pr_reviews" | jq -r '.[] | select(.state == "APPROVED" ) | .user.login' | sort -u)
110+
111+
# Fetch commits in the PR:
112+
pr_commits=$(github_api "GET" "/repos/$REPO_OWNER/$REPO_NAME/pulls/$pr_number/commits")
113+
114+
# Extract co-authors from commits:
115+
co_authors=$(echo "$pr_commits" | jq -r '.[].commit.message' | grep -i "Co-authored-by:" | awk -F': ' '{print $2}' | sort | uniq | paste -sd '\n' -)
116+
117+
# Extract linked issues from PR body (e.g., #123)
118+
issue_numbers=$(echo "$pr_body" | grep -oE '#[0-9]+' | grep -oE '[0-9]+' | sort | uniq)
119+
closes_issues=""
120+
ref_issues=""
121+
for issue in $issue_numbers; do
122+
if echo "$pr_body" | grep -qi "closes.*#$issue"; then
123+
closes_issues+="Closes: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
124+
else
125+
ref_issues+="Ref: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
126+
fi
127+
done
128+
closes_issues=$(echo -e "$closes_issues" | sed '$ s/\n$//')
129+
ref_issues=$(echo -e "$ref_issues" | sed '$ s/\n$//')
130+
131+
# Assemble commit message components:
132+
commit_subject="$pr_title"
133+
commit_body="PR-URL: $pr_url"
134+
135+
if [ -n "$closes_issues" ]; then
136+
commit_body+="\n$closes_issues"
137+
fi
138+
if [ -n "$ref_issues" ]; then
139+
commit_body+="\n$ref_issues"
140+
fi
141+
if [ -n "$co_authors" ]; then
142+
commit_body+="\n$co_authors"
143+
fi
144+
for reviewer in $reviewers; do
145+
resolved_reviewer=$(resolve_user "$reviewer")
146+
commit_body+="\nReviewed-by: $resolved_reviewer"
147+
done
148+
149+
# Add Signed-off-by line:
150+
pr_author=$(echo "$pr_details" | jq -r '.user.login')
151+
signed_off_by=$(resolve_user "$pr_author")
152+
commit_body+="\nSigned-off-by: $signed_off_by"
153+
154+
# Combine subject and body:
155+
commit_message="$commit_subject\n\n$commit_body"
156+
157+
# Output the commit message:
158+
echo -e "$commit_message"
159+
}
160+
161+
# Call main with all command-line arguments:
162+
main "$@"

.github/workflows/windows_test_npm_install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ jobs:
273273
TEST_NPM_INSTALL_GITHUB_URL: 'https://github.com/stdlib-js/stdlib'
274274
run: |
275275
. "${{ env.NVS_HOME }}/nvs.sh" && nvs use ${{ matrix.NODE_VERSION }}
276-
. "./.github/workflows/scripts/task_runner" ${{ matrix.BUILD_TASK }} "${{ env.LOG_FILE_BUILD_TASK }}"
276+
. "$GITHUB_WORKSPACE/.github/workflows/scripts/task_runner" ${{ matrix.BUILD_TASK }} "${{ env.LOG_FILE_BUILD_TASK }}"
277277
timeout-minutes: 360
278278

279279
# View the log file if the previous step fails:

lib/node_modules/@stdlib/blas/dswap/docs/types/test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import dswap = require( './index' );
2424

2525
// The function returns an ndarray...
2626
{
27-
dswap( zeros( [ 10 ] ), zeros( [ 10 ] ) ); // $ExpectType float64ndarray
27+
dswap( zeros( [ 10 ], { 'dtype': 'float64' } ), zeros( [ 10 ], { 'dtype': 'float64' } ) ); // $ExpectType float64ndarray
2828
}
2929

3030
// The compiler throws an error if the function is provided a first argument which is not an ndarray...
3131
{
32-
const y = zeros( [ 10 ] );
32+
const y = zeros( [ 10 ], { 'dtype': 'float64' } );
3333

3434
dswap( 10, y ); // $ExpectError
3535
dswap( '10', y ); // $ExpectError
@@ -54,7 +54,7 @@ import dswap = require( './index' );
5454

5555
// The compiler throws an error if the function is provided a second argument which is not an ndarray...
5656
{
57-
const x = zeros( [ 10 ] );
57+
const x = zeros( [ 10 ], { 'dtype': 'float64' } );
5858

5959
dswap( x, 10 ); // $ExpectError
6060
dswap( x, '10' ); // $ExpectError
@@ -79,8 +79,8 @@ import dswap = require( './index' );
7979

8080
// The compiler throws an error if the function is provided a third argument which is not a number...
8181
{
82-
const x = zeros( [ 10 ] );
83-
const y = zeros( [ 10 ] );
82+
const x = zeros( [ 10 ], { 'dtype': 'float64' } );
83+
const y = zeros( [ 10 ], { 'dtype': 'float64' } );
8484

8585
dswap( x, y, '10' ); // $ExpectError
8686
dswap( x, y, true ); // $ExpectError
@@ -93,8 +93,8 @@ import dswap = require( './index' );
9393

9494
// The compiler throws an error if the function is provided an unsupported number of arguments...
9595
{
96-
const x = zeros( [ 10 ] );
97-
const y = zeros( [ 10 ] );
96+
const x = zeros( [ 10 ], { 'dtype': 'float64' } );
97+
const y = zeros( [ 10 ], { 'dtype': 'float64' } );
9898

9999
dswap(); // $ExpectError
100100
dswap( x ); // $ExpectError

0 commit comments

Comments
 (0)