1-
21# /
32# @license Apache-2.0
43#
@@ -22,25 +21,159 @@ name: scaffold_package_via_pull_request_assignment
2221
2322# Workflow triggers:
2423on :
25- pull_request :
24+ pull_request_target :
2625 types : [assigned]
2726
2827# Workflow jobs:
2928jobs :
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