feat: refactor string package remove-first
#93
Workflow file for this run
This file contains 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) 2022 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: scaffold_package_via_pull_request_assignment | |
# Workflow triggers: | |
on: | |
pull_request_target: | |
types: [assigned] | |
# Workflow jobs: | |
jobs: | |
# Define a job for checking whether the pull request originates from `stdlib-js` organization: | |
check: | |
# Define a display name: | |
name: 'Check whether pull request originates from `stdlib-js` organization' | |
# Define the type of virtual host machine on which to run the job: | |
runs-on: ubuntu-latest | |
# Define job outputs: | |
outputs: | |
external: ${{ steps.check-external.outputs.external }} | |
# Define the sequence of job steps... | |
steps: | |
# Check whether the pull request originates from `stdlib-js` organization: | |
- name: 'Check whether the pull request originates from `stdlib-js` organization' | |
id: check-external | |
run: | | |
if [ ${{ github.event.pull_request.head.repo.owner.login }} = "stdlib-js" ]; then | |
echo "external=false" >> $GITHUB_OUTPUT | |
else | |
echo "external=true" >> $GITHUB_OUTPUT | |
fi | |
# Define a job for scaffolding a package based off `README.md` contents: | |
scaffold-external: | |
# Define a display name: | |
name: 'Scaffold package based off `README.md` contents (external pull request)' | |
# Wait for the `check` job to complete before running this job: | |
needs: [check] | |
# Only run this job if the pull request originates from an external repository and the pull request is assigned to `stdlib-js-bot`: | |
if: needs.check.outputs.external == 'true' && github.event.pull_request.assignee.login == 'stdlib-bot' | |
# Define the type of virtual host machine on which to run the job: | |
runs-on: ubuntu-latest | |
# Define the sequence of job steps... | |
steps: | |
# Checkout the pull request branch: | |
- name: 'Checkout the pull request branch' | |
uses: actions/checkout@v3 | |
with: | |
# Refers to the branch name of the pull request: | |
ref: 'develop' | |
# Refers to the repository name of the pull request: | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
# Limit clone depth to the most recent commit: | |
fetch-depth: 1 | |
# Specify whether to remove untracked files before checking out the repository: | |
clean: true | |
# Specify whether to download Git-LFS files: | |
lfs: false | |
timeout-minutes: 10 | |
# Configure git: | |
- name: 'Configure git' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "stdlib-bot" | |
git fetch --all | |
# Get list of changed files: | |
- name: 'Get list of changed files' | |
id: changed-files | |
uses: tj-actions/changed-files@v35 | |
with: | |
separator: ' ' | |
base_sha: ${{ github.event.pull_request.base.sha }} | |
sha: ${{ github.event.pull_request.head.sha }} | |
# Extract file path of added or modified `README.md` file: | |
- name: 'Extract file path of added or modified `README.md` file' | |
id: extract-readme | |
run: | | |
pkg_path=$(echo ${{ steps.changed-files.outputs.all_changed_files }} | tr ' ' '\n' | grep 'README.md' | head -n 1) | |
# Keep substring after `lib/node_modules/@stdlib/` and strip trailing `README.md`: | |
pkg_path=$(echo $pkg_path | sed 's/.*lib\/node_modules\/@stdlib\///g' | sed 's/\/README.md//g') | |
# Set package path as output: | |
echo "pkg_path=$pkg_path" >> $GITHUB_OUTPUT | |
# Copy files from forked repository to new branch on `stdlib-js/stdlib` repository: | |
- name: 'Copy files from forked repository to new branch on `stdlib-js/stdlib` repository' | |
run: | | |
SCAFFOLD_BRANCH="scaffold-${{ github.event.pull_request.number }}/${{ steps.extract-readme.outputs.pkg_path }}" | |
SLUG='stdlib-js/stdlib' | |
REPO="https://github.com/${SLUG}.git" | |
# Add remote for `stdlib-js/stdlib` repository: | |
git remote add source $REPO | |
# Fetch `stdlib-js/stdlib` repository: | |
git fetch source | |
# Create `scaffold/<path>` branch: | |
git branch $SCAFFOLD_BRANCH origin/${{ github.event.pull_request.head.ref }} | |
# Checkout `scaffold/<path>` branch: | |
git checkout $SCAFFOLD_BRANCH | |
# Run the command to scaffold a package: | |
- name: 'Scaffold package' | |
id: scaffold | |
uses: stdlib-js/scaffold-pkg-pr-action@main | |
with: | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
added-files: ${{ steps.changed-files.outputs.all_changed_files }} | |
# Commit changes: | |
- name: 'Commit changes' | |
run: | | |
git add -A | |
git commit -m "Scaffold ${{ steps.extract-readme.outputs.pkg_path }} package files" | |
# Push changes to `stdlib-js/stdlib` repository: | |
- name: 'Push changes to `stdlib-js/stdlib` repository' | |
env: | |
GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} | |
run: | | |
SCAFFOLD_BRANCH="scaffold-${{ github.event.pull_request.number }}/${{ steps.extract-readme.outputs.pkg_path }}" | |
SLUG='stdlib-js/stdlib' | |
# Push `scaffold/<path>` branch to `stdlib-js/stdlib` repository: | |
git push "https://$GITHUB_ACTOR:[email protected]/$SLUG" $SCAFFOLD_BRANCH | |
# Add a comment to the pull request: | |
- name: 'Add comment to pull request' | |
uses: peter-evans/create-or-update-comment@v1 | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
Based off the `README.md` file, the [stdlib-bot](https://github.com/stdlib-bot) has generated contents for the [${{ steps.scaffold.outputs.alias }}](../tree/scaffold-${{ github.event.pull_request.number }}/${{ steps.scaffold.outputs.path }}/${{ steps.scaffold.outputs.dir }}) package. | |
From your local fork, make sure you are on the pull request branch: | |
```bash | |
git checkout ${{ github.event.pull_request.head.ref }} | |
``` | |
Make sure you have an `upstream` remote pointing to the original `stdlib-js/stdlib` repository (you may check with `git remote -v`). If not, add it as follows: | |
```bash | |
git remote add upstream https://github.com/stdlib-js/stdlib.git | |
``` | |
Fetch the scaffold branch from the `stdlib-js/stdlib` repository: | |
```bash | |
git fetch upstream scaffold-${{ github.event.pull_request.number }}/${{ steps.scaffold.outputs.path }} | |
``` | |
You can then merge the changes from the upstream repository into your branch as follows: | |
```bash | |
git merge upstream/scaffold-${{ github.event.pull_request.number }}/${{ steps.scaffold.outputs.path }} | |
``` | |
## Notes | |
* :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: | |
# Define a job for scaffolding a package based off `README.md` contents: | |
scaffold-internal: | |
# Define a display name: | |
name: 'Scaffold package based off `README.md` contents (internal pull request)' | |
# Wait for the `check` job to complete before running this job: | |
needs: [check] | |
# Only run this job if the pull request originates from the `stdlib-js` organization and the pull request is assigned to `stdlib-js-bot`: | |
if: needs.check.outputs.external == 'false' && github.event.pull_request.assignee.login == 'stdlib-bot' | |
# Define the type of virtual host machine on which to run the job: | |
runs-on: ubuntu-latest | |
# Define the sequence of job steps... | |
steps: | |
# Checkout the pull request branch: | |
- uses: actions/checkout@v3 | |
with: | |
# Refers to the branch name of the pull request: | |
ref: ${{ github.event.pull_request.head.ref }} | |
# Refers to the repository name of the pull request: | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
# Run the command to scaffold a package: | |
- name: 'Scaffold package' | |
id: scaffold | |
uses: stdlib-js/scaffold-pkg-pr-action@main | |
with: | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Configure git: | |
- name: 'Configure git' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "stdlib-bot" | |
# Commit changes: | |
- name: 'Commit changes' | |
run: | | |
git add -A | |
git commit -m "Scaffold ${{ steps.scaffold.outputs.path }} package files" | |
# Push changes: | |
- name: 'Push changes' | |
env: | |
GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} | |
run: | | |
SLUG=${{ github.repository }} | |
echo "Pushing changes to $SLUG..." | |
git push "https://$GITHUB_ACTOR:[email protected]/$SLUG.git" HEAD:${{ github.event.pull_request.head.ref }} | |
# Add comment to the pull request: | |
- name: 'Add comment to pull request' | |
uses: peter-evans/create-or-update-comment@v1 | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
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 and pushed them to the pull request branch. | |
## Notes | |
* :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: |