forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (136 loc) · 6.19 KB
/
namespace_declarations.yml
File metadata and controls
169 lines (136 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#/
# @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@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
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
# Provide a GitHub token for authentication
token: ${{ secrets.STDLIB_BOT_PAT_REPO_WRITE }}
# Store GitHub token in local Git configuration:
persist-credentials: true
timeout-minutes: 10
# Install Node.js:
- name: 'Install Node.js'
# Pin action to full length commit SHA
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.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
# Namespace without the '@stdlib/' scope for display in commit messages and PR titles:
display_namespace="${namespace#@stdlib/}"
# Branch name slug with slashes replaced by dashes:
branch_name="update-${display_namespace//\//-}-declarations"
# If an open PR already exists for this branch, skip this namespace entirely:
existing_pr=$(gh pr list --head "$branch_name" --state open --json number -q '.[0].number' || true)
if [ -n "$existing_pr" ]; then
echo "Open PR exists for $branch_name (#$existing_pr). Skipping $namespace."
continue
fi
# Switch to the new branch:
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 \`${display_namespace}\` TypeScript declarations" --signoff
# Push branch and create PR:
git push origin "$branch_name"
gh pr create \
--title "feat: update \`${display_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 "@stdlib-js/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 }}