Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
kgryte committed Jul 29, 2024
2 parents 308005e + 6f3e683 commit 7927319
Show file tree
Hide file tree
Showing 17 changed files with 309 additions and 89 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/check_contributing_guidelines_acceptance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#/
# @license Apache-2.0
#
# Copyright (c) 2024 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: check_contributing_guidelines_acceptance

# 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
user:
required: true
type: string
# Define the secrets accessible by the workflow:
secrets:
STDLIB_BOT_GITHUB_TOKEN:
description: 'stdlib-bot GitHub token to create pull request comments'
required: true

# Trigger on pull request events:
pull_request_target:
types: [opened, edited, synchronize, reopened]

# Global permissions:
permissions:
# Allow read-only access to the repository contents:
contents: read

# Allow write access to pull requests:
pull-requests: write

# Workflow jobs:
jobs:

# Define a job for checking the contributing guidelines acknowledgment...
check_acknowledgment:

# Define a display name:
name: 'Check Contributing Guidelines Acknowledgment'

# Define the type of virtual host machine:
runs-on: ubuntu-latest

# Define the sequence of job steps...
steps:
# Checkout the repository:
- name: 'Checkout repository'
# Pin action to full length commit SHA
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
# Specify whether to remove untracked files before checking out the repository:
clean: true

# Limit clone depth to the most recent commit:
fetch-depth: 1

# Specify whether to download Git-LFS files:
lfs: false
timeout-minutes: 10

# Check contributing guidelines acceptance:
- name: 'Check contributing guidelines acceptance'
env:
GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pull_request_number }}
run: |
. "$GITHUB_WORKSPACE/.github/workflows/scripts/check_contributing_guidelines_acceptance" $PR_NUMBER
118 changes: 118 additions & 0 deletions .github/workflows/scripts/check_contributing_guidelines_acceptance
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env bash
#
# @license Apache-2.0
#
# Copyright (c) 2024 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 check if a pull request contains the checked contributing guidelines acknowledgment checkbox.
#
# Usage: check_contributing_guidelines 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 #

# Get the pull request number:
pr_number="$1"

# Set the repository name:
GITHUB_REPOSITORY="stdlib-js/stdlib"

# Set the contributing guidelines link:
CONTRIBUTING_LINK="https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md"

# 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
}

# Main execution sequence.
main() {
echo "Checking contributing guidelines acknowledgment for PR #${pr_number}..."

# Fetch the pull request body:
if ! pr_body=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${pr_number}" | \
jq -r .body); then
echo "Failed to fetch PR body."
on_error 1
fi

# Check for the contributing guidelines checkbox:
if echo "${pr_body}" | grep -qE '^\s*-\s*\[x\]\s*Read,\s*understood,\s*and\s*followed\s*the\s*\[contributing\s*guidelines\]'; then
echo "Contributing guidelines acknowledged."
print_success
exit 0
else
echo "Contributing guidelines not acknowledged."

# Post a comment on the PR:
comment="Hello! Thank you for your contribution to stdlib.
We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:
1. Please read our [contributing guidelines][contributing].
2. Update your pull request description to include this checked box:
\`- [x] Read, understood, and followed the [contributing guidelines](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md)\`
This acknowledgment confirms that you've read the guidelines, which include:
- The developer's certificate of origin
- Your agreement to license your contributions under the project's terms
We can't review or accept contributions without this acknowledgment.
Thank you for your understanding and cooperation. We look forward to reviewing your contribution!
[contributing]: ${CONTRIBUTING_LINK}"

if ! curl -s -X POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${pr_number}/comments" \
-d "{\"body\":$(echo "$comment" | jq -R -s -c .)}"; then
echo "Failed to post comment on PR."
on_error 1
fi

exit 1
fi
}

# Set an error handler to print captured output and perform any clean-up tasks:
trap 'on_error' ERR

# Run main:
main
16 changes: 8 additions & 8 deletions .github/workflows/scripts/lint_javascript_files
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,35 @@ files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '\.js$' | grep -v -e '/exam
# Build native addons if present:
packages=$(echo "${files}" | tr ' ' '\n' | sed 's/^lib\/node_modules\///g' | sed 's/\/lib\/.*//g' | sort | uniq)
for pkg in ${packages}; do
if [ -f "lib/node_modules/${pkg}/binding.gyp" ]; then
NODE_ADDONS_PATTERN="${pkg}" make install-node-addons
fi
if [ -f "lib/node_modules/${pkg}/binding.gyp" ]; then
NODE_ADDONS_PATTERN="${pkg}" make install-node-addons
fi
done

if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${fix}" FILES="${files}"
make lint-javascript-files FIX="${fix}" FILES="${files}"
fi

# Lint JavaScript command-line interfaces...
file=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '\.js$' | grep -E '/bin/cli$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${file}" ]]; then
make lint-javascript-files FIX="${fix}" FILES="${file}"
make lint-javascript-files FIX="${fix}" FILES="${file}"
fi

# Lint JavaScript example files:
files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/examples/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${fix}" FILES="${files}" ESLINT_CONF="${eslint_examples_conf}"
make lint-javascript-files FIX="${fix}" FILES="${files}" ESLINT_CONF="${eslint_examples_conf}"
fi

# Lint JavaScript test files:
files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/test/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${fix}" FILES="${files}" ESLINT_CONF="${eslint_tests_conf}"
make lint-javascript-files FIX="${fix}" FILES="${files}" ESLINT_CONF="${eslint_tests_conf}"
fi

# Lint JavaScript benchmark files:
files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/benchmark/.*\.js$' | tr '\n' ' ' | sed 's/ $//')
if [[ -n "${files}" ]]; then
make lint-javascript-files FIX="${fix}" FILES="${files}" ESLINT_CONF="${eslint_benchmarks_conf}"
make lint-javascript-files FIX="${fix}" FILES="${files}" ESLINT_CONF="${eslint_benchmarks_conf}"
fi
48 changes: 24 additions & 24 deletions .github/workflows/scripts/remove_related_packages
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,30 @@
set -o pipefail

for file in ${@}; do
if [[ $file == *README.md ]]; then
awk '
BEGIN { print_mode = 1; in_related = 0; in_related_links = 0 }
/<section class="related">/ {
print; print ""; print "</section>";
in_related = 1; print_mode = 0; next
}
/<\/section>/ {
if (in_related) { in_related = 0; print_mode = 1 }
else { print }
next
}
/<!-- <related-links> -->/ {
print; print ""; print "<!-- </related-links> -->";
in_related_links = 1; print_mode = 0; next
}
/<!-- <\/related-links> -->/ {
if (in_related_links) { in_related_links = 0; print_mode = 1 }
else { print }
next
}
{ if (print_mode == 1) print }
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
fi
if [[ $file == *README.md ]]; then
awk '
BEGIN { print_mode = 1; in_related = 0; in_related_links = 0 }
/<section class="related">/ {
print; print ""; print "</section>";
in_related = 1; print_mode = 0; next
}
/<\/section>/ {
if (in_related) { in_related = 0; print_mode = 1 }
else { print }
next
}
/<!-- <related-links> -->/ {
print; print ""; print "<!-- </related-links> -->";
in_related_links = 1; print_mode = 0; next
}
/<!-- <\/related-links> -->/ {
if (in_related_links) { in_related_links = 0; print_mode = 1 }
else { print }
next
}
{ if (print_mode == 1) print }
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
fi
done

echo "All files processed successfully."
36 changes: 18 additions & 18 deletions .github/workflows/scripts/track_fixmes
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ comment="<!-- This comment is automatically generated by a GitHub Action. -->

# Search for FIXME annotations in the codebase:
for file in $(find bin dist docs tools etc examples lib test tools -type f); do
fixmes=$(grep -E -on "FIXME:" $file) || true
for fixme in $fixmes; do
if [ -n "$fixme" ]; then
# Since a maximum of 65,535 characters can be included in a GitHub comment body, we break out of the loop if the comment body would exceed this limit.
if [ $(( ${#comment} + ${#fixme} )) -gt 65535 ]; then
break
fi
lineNumber=$(echo $fixme | cut -d ":" -f 1)
lineContent=$(awk "NR==$lineNumber" $file)
lineContent=$(echo $lineContent | sed -e 's/<!--/\\<!--/g' -e 's/-->/\\-->/g')
if [ ${#lineContent} -gt 80 ]; then
lineContent=$(echo $lineContent | cut -c 1-80)
lineContent="$lineContent..."
continue
fi
comment="$comment
fixmes=$(grep -E -on "FIXME:" $file) || true
for fixme in $fixmes; do
if [ -n "$fixme" ]; then
# Since a maximum of 65,535 characters can be included in a GitHub comment body, we break out of the loop if the comment body would exceed this limit.
if [ $(( ${#comment} + ${#fixme} )) -gt 65535 ]; then
break
fi
lineNumber=$(echo $fixme | cut -d ":" -f 1)
lineContent=$(awk "NR==$lineNumber" $file)
lineContent=$(echo $lineContent | sed -e 's/<!--/\\<!--/g' -e 's/-->/\\-->/g')
if [ ${#lineContent} -gt 80 ]; then
lineContent=$(echo $lineContent | cut -c 1-80)
lineContent="$lineContent..."
continue
fi
comment="$comment
- [$file#L$lineNumber](https://github.com/stdlib-js/stdlib/blob/develop/$file#L$lineNumber): $lineContent"
fi
done
fi
done
done

echo "$comment"
36 changes: 18 additions & 18 deletions .github/workflows/scripts/track_todos
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ comment="<!-- This comment is automatically generated by a GitHub Action. -->

# Search for TODO annotations in the codebase:
for file in $(find bin dist docs tools etc examples lib test tools -type f); do
todos=$(grep -E -on "TODO:" $file) || true
for todo in $todos; do
if [ -n "$todo" ]; then
# Since a maximum of 65,535 characters can be included in a GitHub comment body, we break out of the loop if the comment body would exceed this limit.
if [ $(( ${#comment} + ${#todo} )) -gt 65535 ]; then
break
fi
lineNumber=$(echo $todo | cut -d ":" -f 1)
lineContent=$(awk "NR==$lineNumber" $file)
lineContent=$(echo $lineContent | sed -e 's/<!--/\\<!--/g' -e 's/-->/\\-->/g')
if [ ${#lineContent} -gt 80 ]; then
lineContent=$(echo $lineContent | cut -c 1-80)
lineContent="$lineContent..."
continue
fi
comment="$comment
todos=$(grep -E -on "TODO:" $file) || true
for todo in $todos; do
if [ -n "$todo" ]; then
# Since a maximum of 65,535 characters can be included in a GitHub comment body, we break out of the loop if the comment body would exceed this limit.
if [ $(( ${#comment} + ${#todo} )) -gt 65535 ]; then
break
fi
lineNumber=$(echo $todo | cut -d ":" -f 1)
lineContent=$(awk "NR==$lineNumber" $file)
lineContent=$(echo $lineContent | sed -e 's/<!--/\\<!--/g' -e 's/-->/\\-->/g')
if [ ${#lineContent} -gt 80 ]; then
lineContent=$(echo $lineContent | cut -c 1-80)
lineContent="$lineContent..."
continue
fi
comment="$comment
- [$file#L$lineNumber](https://github.com/stdlib-js/stdlib/blob/develop/$file#L$lineNumber): $lineContent"
fi
done
fi
done
done

echo "$comment"
Loading

1 comment on commit 7927319

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
blas/base/cscal $\color{green}459/459$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}459/459$
$\color{green}+100.00\%$
blas/base/zscal $\color{green}459/459$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}459/459$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.