namespace_declarations #223
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
#/ | |
# @license Apache-2.0 | |
# | |
# Copyright (c) 2021 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: namespace_declarations | |
# Workflow triggers: | |
on: | |
schedule: | |
# Run the workflow once a day at 2:00 AM UTC: | |
- cron: '0 2 * * *' | |
# Allow the workflow to be manually run: | |
workflow_dispatch: | |
# Global permissions: | |
permissions: | |
# Allow read-only access to the repository contents: | |
contents: read | |
# Workflow jobs: | |
jobs: | |
# Define a job for updating namespace TypeScript declarations... | |
update: | |
# Define a display name: | |
name: 'Update TypeScript Declarations' | |
# Ensure the job does not run on forks: | |
if: github.repository == 'stdlib-js/stdlib' | |
# 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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
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 | |
# Avoid storing GitHub token in local Git configuration: | |
persist-credentials: false | |
timeout-minutes: 10 | |
# Install Node.js: | |
- name: 'Install Node.js' | |
# Pin action to full length commit SHA | |
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | |
with: | |
node-version: '20' # 'lts/*' | |
timeout-minutes: 5 | |
# Install dependencies (accounting for possible network failures, etc, when installing node module dependencies): | |
- name: 'Install dependencies' | |
run: | | |
make install-node-modules || make install-node-modules || make install-node-modules | |
timeout-minutes: 15 | |
# Disable Git hooks: | |
- name: 'Disable Git hooks' | |
run: | | |
rm -rf .git/hooks | |
# Import GPG key to sign commits: | |
- name: 'Import GPG key to sign commits' | |
# Pin action to full length commit SHA | |
uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0 | |
with: | |
gpg_private_key: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }} | |
passphrase: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }} | |
git_user_signingkey: true | |
git_commit_gpgsign: true | |
# Update namespace Typescript declarations and create PRs: | |
- name: 'Update declarations and create PRs' | |
run: | | |
# Create a temporary file to store the list of namespaces: | |
make list-pkgs-namespaces > namespaces.txt | |
# Process each namespace: | |
while IFS= read -r namespace; do | |
if [ -n "$namespace" ] && [[ $namespace != *"_tools"* ]]; then | |
branch_name="update-$(echo "$namespace" | sed 's/@stdlib\///' | sed 's/\//-/g')-declarations" | |
git checkout -b "$branch_name" | |
# Generate declarations for this namespace: | |
echo "$namespace" | node lib/node_modules/@stdlib/_tools/scripts/create_namespace_types.js | |
# Check if there are changes: | |
if ! git diff --quiet -- lib/node_modules/@stdlib; then | |
# Stage only changes in the stdlib directory: | |
git add lib/node_modules/@stdlib | |
# Commit changes: | |
git commit -m "feat: update \`${namespace}\` TypeScript declarations" --signoff | |
# Push branch and create PR: | |
git push origin "$branch_name" | |
gh pr create \ | |
--title "feat: update \`${namespace}\` TypeScript declarations" \ | |
--body "This PR updates TypeScript declarations for the \`${namespace}\` namespace. | |
## Reviewer Checklist | |
- [ ] **Check the scope of the changes** (following [Conventional Commits](https://www.conventionalcommits.org)): | |
- Are these **new APIs**? Then this is a \`feat\`. | |
- Are these **changes to existing APIs** that could break compatibility? Then this is a \`feat!\` (i.e., a breaking change). | |
- Are these **only documentation** changes to existing APIs? Then this is \`docs\`. | |
- [ ] Update the PR title to align with the change type (\`feat\`, \`feat!\`, or \`docs\`). | |
- [ ] Approve the PR once you are confident about the classification and changes made." \ | |
--label "Documentation" \ | |
--label "automated-pr" \ | |
--reviewer "reviewers" \ | |
--base develop \ | |
--head "$branch_name" | |
fi | |
git checkout develop | |
fi | |
done < namespaces.txt | |
# Clean up temporary file: | |
rm namespaces.txt | |
env: | |
GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_PAT_REPO_WRITE }} |