Skip to content

Commit c2d4b39

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 74be267 + 8ce1ea8 commit c2d4b39

3 files changed

Lines changed: 166 additions & 10 deletions

File tree

.github/workflows/scaffold_pkg_via_branch_push.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#/
32
# @license Apache-2.0
43
#
@@ -18,13 +17,14 @@
1817
#/
1918

2019
# Workflow name:
21-
name: Scaffold Package via Push to Branch
20+
name: scaffold_package_via_push_to_branch
2221

2322
# Workflow triggers:
2423
on:
2524
push:
2625
branches:
2726
- 'scaffold/**'
27+
- 'scaffold-**/**'
2828

2929
# Workflow jobs:
3030
jobs:
@@ -85,4 +85,26 @@ jobs:
8585
run: |
8686
SLUG=${{ github.repository }}
8787
echo "Pushing changes to $SLUG..."
88-
git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" HEAD:scaffold/${{ steps.scaffold.outputs.path }}
88+
git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" HEAD:${{ github.event.push.head.ref }}
89+
90+
# Check if branch name contains an issue number:
91+
- name: 'Check if branch name contains an issue number'
92+
id: check-branch-name
93+
run: |
94+
if [[ ${{ github.event.push.head.ref }} =~ ^scaffold-([0-9]+) ]]; then
95+
echo "Branch name contains an issue number: ${BASH_REMATCH[1]}"
96+
echo "::set-output name=issue-number::${BASH_REMATCH[1]}"
97+
fi
98+
99+
# Add a comment to the pull request:
100+
- name: 'Add comment to pull request'
101+
if: steps.check-branch-name.outputs.issue-number != ''
102+
uses: peter-evans/create-or-update-comment@v1
103+
with:
104+
issue-number: ${{ steps.check-branch-name.outputs.issue-number }}
105+
body: |
106+
Based off the `README.md` file, the [stdlib-bot](https://github.com/stdlib-bot) has generated contents for the [${{ steps.scaffold.outputs.alias }}](../tree/${{ steps.scaffold.outputs.path }}/${{ steps.scaffold.outputs.dir }}) package.
107+
108+
## Notes
109+
110+
* :warning: The stdlib-bot uses AI to generate package content. The generated content is not guaranteed to be correct, and will require manual review and editing. :warning:

.github/workflows/scaffold_pkg_via_issue_comment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#/
32
# @license Apache-2.0
43
#

.github/workflows/scaffold_pkg_via_pull_request_assignment.yml

Lines changed: 141 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#/
32
# @license Apache-2.0
43
#
@@ -22,25 +21,159 @@ name: scaffold_package_via_pull_request_assignment
2221

2322
# Workflow triggers:
2423
on:
25-
pull_request:
24+
pull_request_target:
2625
types: [assigned]
2726

2827
# Workflow jobs:
2928
jobs:
30-
scaffold:
29+
# Define a job for checking whether the pull request originates from `stdlib-js` organization:
30+
check:
31+
# Define the type of virtual host machine on which to run the job:
32+
runs-on: ubuntu-latest
33+
34+
# Define job outputs:
35+
outputs:
36+
external: ${{ steps.check-external.outputs.external }}
37+
38+
# Define the sequence of job steps...
39+
steps:
40+
# Check whether the pull request originates from `stdlib-js` organization:
41+
- name: 'Check whether the pull request originates from `stdlib-js` organization'
42+
id: check-external
43+
run: |
44+
if [ ${{ github.event.pull_request.head.repo.owner }} = "stdlib-js" ]; then
45+
echo "::set-output name=external::false"
46+
else
47+
echo "::set-output name=external::true"
48+
fi
49+
50+
# Define a job for scaffolding a package based off `README.md` contents:
51+
scaffold-external:
52+
53+
# Wait for the `check` job to complete before running this job:
54+
needs: [check]
55+
56+
# Only run this job if the pull request originates from an external repository:
57+
if: needs.check.outputs.external == 'true'
58+
3159
# Define the type of virtual host machine on which to run the job:
3260
runs-on: ubuntu-latest
3361

3462
# Define the sequence of job steps...
3563
steps:
64+
65+
# Stop if pull request is not assigned to the `stdlib-bot` user:
66+
- name: 'Stop if pull request is not assigned to the `stdlib-bot` user'
67+
if: ${{ github.event.assignee.login != 'stdlib-bot' }}
68+
run: |
69+
echo "Pull request is not assigned to the `stdlib-bot` user. Exiting..."
70+
exit 0
71+
72+
# Checkout the pull request branch:
73+
- name: 'Checkout the pull request branch'
74+
uses: actions/checkout@v3
75+
with:
76+
# Refers to the branch name of the pull request:
77+
ref: 'develop'
78+
79+
# Refers to the repository name of the pull request:
80+
repository: ${{ github.event.pull_request.head.repo.full_name }}
81+
82+
# Limit clone depth to the most recent commit:
83+
fetch-depth: 1
84+
85+
# Specify whether to remove untracked files before checking out the repository:
86+
clean: true
87+
88+
# Specify whether to download Git-LFS files:
89+
lfs: false
90+
timeout-minutes: 10
91+
92+
# Configure git:
93+
- name: 'Configure git'
94+
run: |
95+
git config --local user.email "noreply@stdlib.io"
96+
git config --local user.name "stdlib-bot"
97+
git fetch --all
98+
99+
# Get list of changed files:
100+
- name: Get list of changed files
101+
id: changed-files
102+
uses: tj-actions/changed-files@v32
103+
with:
104+
separator: ' '
105+
base_sha: ${{ github.event.pull_request.base.sha }}
106+
sha: ${{ github.event.pull_request.head.sha }}
107+
108+
# Extract file path of added `README.md` file:
109+
- name: 'Extract file path of added `README.md` file'
110+
id: extract-readme
111+
run: |
112+
pkg_path=$(echo ${{ steps.changed-files.outputs.added_files }} | tr ' ' '\n' | grep 'README.md' | head -n 1)
113+
114+
# Keep substring after `lib/node_modules/@stdlib/` and strip trailing `README.md`:
115+
pkg_path=$(echo $pkg_path | sed 's/.*lib\/node_modules\/@stdlib\///g' | sed 's/\/README.md//g')
116+
117+
# Set package path as output:
118+
echo "::set-output name=pkg_path::$pkg_path"
119+
120+
# Copy files from forked repository to new branch on `stdlib-js/stdlib` repository:
121+
- name: 'Copy files from forked repository to new branch on `stdlib-js/stdlib` repository'
122+
env:
123+
GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
124+
run: |
125+
SCAFFOLD_BRANCH="scaffold-${{ github.event.pull_request.number }}/${{ steps.extract-readme.outputs.pkg_path }}"
126+
SLUG='stdlib-js/stdlib'
127+
REPO="https://github.com/${SLUG}.git"
128+
129+
# Add remote for `stdlib-js/stdlib` repository:
130+
git remote add source $REPO
131+
132+
# Fetch `stdlib-js/stdlib` repository:
133+
git fetch source
134+
135+
# Create `scaffold/<path>` branch:
136+
git branch $SCAFFOLD_BRANCH origin/${{ github.event.pull_request.head.ref }}
137+
138+
# Rebase `scaffold/<path>` branch to develop branch of `stdlib-js/stdlib` repository:
139+
git rebase develop $SCAFFOLD_BRANCH --onto source/develop
140+
141+
# Push `scaffold/<path>` branch to `stdlib-js/stdlib` repository:
142+
git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG" $SCAFFOLD_BRANCH
143+
144+
# Define a job for scaffolding a package based off `README.md` contents:
145+
scaffold-internal:
146+
147+
# Wait for the `check` job to complete before running this job:
148+
needs: [check]
149+
150+
# Only run this job if the pull request originates from the `stdlib-js` organization:
151+
if: needs.check.outputs.external == 'false'
152+
153+
# Define the type of virtual host machine on which to run the job:
154+
runs-on: ubuntu-latest
155+
156+
# Define the sequence of job steps...
157+
steps:
158+
# Stop if pull request is not assigned to the `stdlib-bot` user:
159+
- name: 'Stop if pull request is not assigned to the `stdlib-bot` user'
160+
if: ${{ github.event.assignee.login != 'stdlib-bot' }}
161+
run: |
162+
echo "Pull request is not assigned to the `stdlib-bot` user. Exiting..."
163+
exit 0
164+
36165
# Checkout the pull request branch:
37166
- uses: actions/checkout@v2
38167
with:
168+
# Refers to the branch name of the pull request:
39169
ref: ${{ github.event.pull_request.head.ref }}
170+
171+
# Refers to the repository name of the pull request:
40172
repository: ${{ github.event.pull_request.head.repo.full_name }}
41173

42174
# Run the command to scaffold a package:
43-
- name: Scaffold package
175+
- name: 'Scaffold package'
176+
if: steps.check-external.outputs.external == 'false'
44177
id: scaffold
45178
uses: stdlib-js/scaffold-pkg-pr-action@main
46179
with:
@@ -57,16 +190,18 @@ jobs:
57190
- name: 'Commit changes'
58191
run: |
59192
git add -A
60-
git commit -m "Scaffold ${{ steps.scaffold.outputs.path }} package"
193+
git commit -m "Scaffold ${{ steps.scaffold.outputs.path }} package files"
61194
62195
# Push changes:
63196
- name: 'Push changes'
197+
env:
198+
GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
64199
run: |
65200
SLUG=${{ github.repository }}
66201
echo "Pushing changes to $SLUG..."
67202
git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" HEAD:${{ steps.scaffold.outputs.path }}
68203
69-
# Add a comment to the pull request:
204+
# Add comment to the pull request:
70205
- name: 'Add comment to pull request'
71206
uses: peter-evans/create-or-update-comment@v1
72207
with:

0 commit comments

Comments
 (0)