Skip to content

Commit 2565ef2

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents c85743c + 0848cd9 commit 2565ef2

21 files changed

Lines changed: 1306 additions & 59 deletions

File tree

.github/workflows/check_required_files.yml

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,31 @@ name: check_required_files
2323
on:
2424
# Allow the workflow to be triggered by other workflows
2525
workflow_call:
26+
# Define the input parameters for the workflow:
27+
inputs:
28+
pull_request_number:
29+
description: 'Pull request number'
30+
required: true
31+
type: number
32+
user:
33+
required: true
34+
type: string
35+
# Define the secrets accessible by the workflow:
36+
secrets:
37+
STDLIB_BOT_GITHUB_TOKEN:
38+
description: 'stdlib-bot GitHub token to create pull request comments'
39+
required: true
40+
41+
# Allow the workflow to be manually triggered:
42+
workflow_dispatch:
43+
inputs:
44+
pull_request_number:
45+
description: 'Pull request number'
46+
required: true
47+
type: number
48+
user:
49+
required: true
50+
type: string
2651

2752
# Global permissions:
2853
permissions:
@@ -44,42 +69,15 @@ jobs:
4469
# Define the sequence of job steps...
4570
steps:
4671

47-
# Checkout the repository:
48-
- name: 'Checkout repository'
49-
# Pin action to full length commit SHA
50-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
51-
with:
52-
# Specify whether to remove untracked files before checking out the repository:
53-
clean: true
54-
55-
# Refers to the development branch:
56-
ref: 'develop'
57-
58-
# Refers to the repository name of the pull request:
59-
repository: ${{ github.event.issue.pull_request.head.repo.full_name }}
60-
61-
# Limit clone depth to the most recent commit:
62-
fetch-depth: 1
63-
64-
# Specify whether to download Git-LFS files:
65-
lfs: false
66-
timeout-minutes: 10
67-
68-
# Configure git:
69-
- name: 'Configure git'
70-
run: |
71-
git config --local user.email "noreply@stdlib.io"
72-
git config --local user.name "stdlib-bot"
73-
git fetch --all
74-
7572
# Get list of added files:
7673
- name: 'Get list of added files'
7774
id: added-files
7875
run: |
7976
page=1
8077
files=""
8178
while true; do
82-
new_files=$(curl -s -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ github.event.issue.pull_request.number }}/files?page=$page&per_page=100" | jq -r '.[] | select(.status == "added") | .filename')
79+
new_files=$(curl -s -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN
80+
}}" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ inputs.pull_request_number }}/files?page=$page&per_page=100" | jq -r '.[] | select(.status == "added") | .filename')
8381
if [ -z "$new_files" ]; then
8482
break
8583
fi
@@ -99,7 +97,6 @@ jobs:
9997
10098
# Check whether the pull request contains files which are required to be present for all packages:
10199
- name: 'Check whether the pull request contains files which are required to be present for all packages'
102-
id: check-required-files
103100
run: |
104101
# Define a list of required files:
105102
required_files=(
@@ -169,15 +166,15 @@ jobs:
169166
170167
body=""
171168
if [[ "${#missing_files[@]}" -eq 0 ]]; then
172-
body="Hi @${{ github.event.issue.pull_request.user.login }}, thank you for your contribution!
169+
body="Hi @${{ inputs.user }}, thank you for your contribution!
173170
174171
:tada: Your pull request contains all required files for the new package: :tada:
175172
176173
${checkbox_list}
177174
178175
-- stdlib-bot"
179176
else
180-
body="Hi @${{ github.event.issue.pull_request.user.login }}, thank you for your contribution! Your pull request contains a new package, but is missing some of the required files.
177+
body="Hi @${{ inputs.user }}, thank you for your contribution! Your pull request contains a new package, but is missing some of the required files.
181178
182179
Use the following checklist to keep track of the required files and which ones are still missing:
183180
@@ -188,11 +185,8 @@ jobs:
188185
-- stdlib-bot"
189186
fi
190187
191-
# Add the comment body to the workflow output after escaping to preserve newlines:
192-
body="${body//'%'/'%25'}"
193-
body="${body//$'\n'/'%0A'}"
194-
body="${body//$'\r'/'%0D'}"
195-
echo "comment-body=${body}" >> $GITHUB_OUTPUT
188+
# Write the comment body to a file:
189+
echo "${body}" > ./comment-body.txt
196190
197191
shell: bash
198192
timeout-minutes: 10
@@ -203,7 +197,10 @@ jobs:
203197
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
204198
with:
205199
# Specify the issue or pull request number:
206-
issue-number: ${{ github.issue.pull_request.number }}
200+
issue-number: ${{ inputs.pull_request_number }}
201+
202+
# Specify the comment body path:
203+
body-path: ./comment-body.txt
207204

208-
# Specify the comment body:
209-
body: ${{ steps.check-required-files.outputs.comment-body }}
205+
# GitHub token:
206+
token: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}

.github/workflows/scripts/update_copyright_years

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ current_year=$(date +"%Y")
3030
directory_to_scan="${1:-.}"
3131

3232
for file in ${@}; do
33+
if [[ ! -f "$file" ]]; then
34+
echo "File not found: $file"
35+
continue
36+
fi
3337
echo "Updating copyright notice in $file..."
34-
# For macOS, adding '' after -i to specify no backup file is created.
35-
sed -i '' "s/Copyright (c) [0-9]\{4\} The Stdlib Authors./Copyright \(c\) $current_year The Stdlib Authors./g" "$file"
38+
if [[ "$OSTYPE" == "darwin"* ]]; then
39+
# macOS, where sed requires '' after -i to specify no backup...
40+
sed -i '' "s/Copyright (c) [0-9]\{4\} The Stdlib Authors./Copyright \(c\) $current_year The Stdlib Authors./g" "$file"
41+
else
42+
# Linux and others, no '' required...
43+
sed -i "s/Copyright (c) [0-9]\{4\} The Stdlib Authors./Copyright \(c\) $current_year The Stdlib Authors./g" "$file"
44+
fi
3645
done
3746

3847
echo "Copyright notices updated to $current_year."

.github/workflows/slash_commands.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ jobs:
3535

3636
# Run reusable workflow:
3737
uses: ./.github/workflows/check_required_files.yml
38+
with:
39+
pull_request_number: ${{ github.event.issue.number }}
40+
user: ${{ github.event.comment.user.login }}
41+
secrets:
42+
STDLIB_BOT_GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
3843

3944
# Define a job for updating copyright header years:
4045
update_copyright_years:
@@ -44,3 +49,10 @@ jobs:
4449

4550
# Run reusable workflow:
4651
uses: ./.github/workflows/update_pr_copyright_years.yml
52+
with:
53+
pull_request_number: ${{ github.event.issue.number }}
54+
secrets:
55+
REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
56+
STDLIB_BOT_GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
57+
STDLIB_BOT_GPG_PRIVATE_KEY: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }}
58+
STDLIB_BOT_GPG_PASSPHRASE: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }}

.github/workflows/update_pr_copyright_years.yml

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ on:
2424

2525
# Allow the workflow to be triggered by other workflows
2626
workflow_call:
27+
# Define the input parameters for the workflow:
28+
inputs:
29+
pull_request_number:
30+
description: 'PR number'
31+
required: true
32+
type: number
33+
# Define the secrets accessible by the workflow:
34+
secrets:
35+
STDLIB_BOT_GITHUB_TOKEN:
36+
description: 'GitHub token for stdlb-bot'
37+
required: true
38+
REPO_GITHUB_TOKEN:
39+
description: 'GitHub token for accessing the repository'
40+
required: true
41+
STDLIB_BOT_GPG_PRIVATE_KEY:
42+
description: 'GPG private key for stdlb-bot'
43+
required: true
44+
STDLIB_BOT_GPG_PASSPHRASE:
45+
description: 'GPG passphrase for stdlb-bot'
46+
required: true
2747

2848
# Workflow jobs:
2949
jobs:
@@ -40,33 +60,67 @@ jobs:
4060
# Define the sequence of job steps...
4161
steps:
4262

63+
# Get PR details:
64+
- name: 'Get PR details'
65+
id: pr-details
66+
run: |
67+
pr_response=$(curl -s \
68+
-H "Accept: application/vnd.github.v3+json" \
69+
-H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}" \
70+
"https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ inputs.pull_request_number }}")
71+
72+
# Escape control characters:
73+
pr_response=$(echo "$pr_response" | tr -d '\000-\031')
74+
75+
# Extract the needed details:
76+
pr_branch=$(echo "$pr_response" | jq -r '.head.ref') # PR's branch
77+
pr_repo_full_name=$(echo "$pr_response" | jq -r '.head.repo.full_name') # PR's repo full name
78+
79+
# Set outputs for the branch and repository:
80+
echo "branch=$pr_branch" >> $GITHUB_OUTPUT
81+
echo "repository=$pr_repo_full_name" >> $GITHUB_OUTPUT
82+
4383
# Checkout the repository:
4484
- name: 'Checkout repository'
4585
# Pin action to full length commit SHA
4686
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
4787
with:
4888
# Refers to the branch name of the branch being pushed:
49-
ref: ${{ github.event.pull_request.head.ref }}
89+
ref: ${{ steps.pr-details.outputs.branch }}
90+
91+
# Refers to the repository name:
92+
repository: ${{ steps.pr-details.outputs.repository }}
5093

5194
# Token for accessing the repository:
5295
token: ${{ secrets.REPO_GITHUB_TOKEN }}
5396

54-
# Get list of changed files:
55-
- name: 'Get list of changed files'
56-
id: changed-files
57-
continue-on-error: true
97+
# File path to checkout to:
98+
path: './'
99+
100+
# Get list of added files:
101+
- name: 'Get list of added files'
102+
id: added-files
58103
run: |
59-
# Get the list of changed files in pull request:
60-
ancestor_commit=$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
61-
files=$(git diff --diff-filter=AM --name-only $ancestor_commit ${{ github.event.pull_request.head.sha }})
104+
page=1
105+
files=""
106+
while true; do
107+
new_files=$(curl -s -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN
108+
}}" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ inputs.pull_request_number }}/files?page=$page&per_page=100" | jq -r '.[] | select(.status == "added") | .filename')
109+
if [ -z "$new_files" ]; then
110+
break
111+
fi
112+
files="$files $new_files"
113+
page=$((page+1))
114+
done
115+
files=$(echo "$files" | tr '\n' ' ' | sed 's/^ //;s/ $//')
62116
echo "files=${files}" >> $GITHUB_OUTPUT
63117
64118
# Update the copyright years:
65119
- name: 'Update copyright years'
66120
id: update-years
67121
run: |
68-
files="{{ steps.changed-files.outputs.files }}"
69-
. "$GITHUB_WORKSPACE/.github/workflows/scripts/update_copyright_years" $files
122+
files="${{ steps.added-files.outputs.files }}"
123+
. "$GITHUB_WORKSPACE/.github/workflows/scripts/update_copyright_years" "$files"
70124
71125
# Disable Git hooks:
72126
- name: 'Disable Git hooks'
@@ -88,10 +142,11 @@ jobs:
88142
env:
89143
REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
90144
USER_NAME: stdlb-bot
91-
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
145+
BRANCH_NAME: ${{ inputs.branch }}
146+
REPO_NAME: ${{ inputs.repository }}
92147
run: |
93148
git config --local user.email "82920195+stdlib-bot@users.noreply.github.com"
94149
git config --local user.name "stdlib-bot"
95150
git add .
96151
git commit -m "chore: update copyright years"
97-
git push "https://$USER_NAME:$REPO_GITHUB_TOKEN@github.com/stdlib-js/stdlib.git" $BRANCH_NAME
152+
git push "https://$USER_NAME:$REPO_GITHUB_TOKEN@github.com/$REPO_NAME.git" $BRANCH_NAME

lib/node_modules/@stdlib/array/complex128/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,60 @@ var count = context.count;
16201620
// returns 3
16211621
```
16221622

1623+
<a name="method-reduce"></a>
1624+
1625+
#### Complex128Array.prototype.reduce( reducerFn\[, initialValue] )
1626+
1627+
Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion.
1628+
1629+
```javascript
1630+
var real = require( '@stdlib/complex/real' );
1631+
var imag = require( '@stdlib/complex/imag' );
1632+
var cadd = require( '@stdlib/math/base/ops/cadd' );
1633+
1634+
var arr = new Complex128Array( 3 );
1635+
1636+
arr.set( [ 1.0, 1.0 ], 0 );
1637+
arr.set( [ 2.0, 2.0 ], 1 );
1638+
arr.set( [ 3.0, 3.0 ], 2 );
1639+
1640+
var z = arr.reduce( cadd );
1641+
// returns <Complex128>
1642+
1643+
var re = real( z );
1644+
// returns 6.0
1645+
1646+
var im = imag( z );
1647+
// returns 6.0
1648+
```
1649+
1650+
The reducer function is provided four arguments:
1651+
1652+
- **acc**: accumulated result.
1653+
- **value**: current array element.
1654+
- **index**: current array element index.
1655+
- **arr**: the array on which this method was called.
1656+
1657+
By default, the function initializes the accumulated result to the first element in the array and passes the second array element as `value` during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the first array element as `value` during the first invocation of the provided callback, provide an `initialValue` argument.
1658+
1659+
```javascript
1660+
var real = require( '@stdlib/complex/real' );
1661+
1662+
function reducer( acc, v ) {
1663+
acc += real( v );
1664+
return acc;
1665+
}
1666+
1667+
var arr = new Complex128Array( 3 );
1668+
1669+
arr.set( [ 1.0, 1.0 ], 0 );
1670+
arr.set( [ 2.0, 2.0 ], 1 );
1671+
arr.set( [ 3.0, 3.0 ], 2 );
1672+
1673+
var z = arr.reduce( reducer, 0.0 );
1674+
// returns 6.0
1675+
```
1676+
16231677
<a name="method-reverse"></a>
16241678

16251679
#### Complex128Array.prototype.reverse()

0 commit comments

Comments
 (0)