github
Download and add registry items from a GitHub repository.
Usage
To start adding registry items from a GitHub repository you can run the following command:
jsrepo add https://github.com/<owner>/<repo>/<item-name>The GitHub provider can parse GitHub URLs so that you can just copy and paste a link to a GitHub repository and it will just work:
jsrepo add https://github.com/<owner>/<repo>/<item-name>
jsrepo add https://github.com/<owner>/<repo>/tree/<ref>The github/ shorthand
You can also just use the github/ shorthand in place of https://github.com/.
jsrepo add github/<owner>/<repo>/<item-name>
jsrepo add github/<owner>/<repo>/tree/<ref>If you configured a custom baseUrl in your jsrepo.config file then using the github/ shorthand will use your
custom base url instead of https://github.com/.
Custom base urls
By default the GitHub provider will use https://github.com as the base url for the github/ shorthand. You can configure this behavior by configuring github in your jsrepo.config file:
import { defineConfig } from "jsrepo";
import { github } from "jsrepo/providers";
export default defineConfig({
providers: [github({ baseUrl: "https://my-github-instance.com" })],
});Alternatively you can use the github:https://<url> shorthand to use a custom base url without having to touch your config file:
jsrepo add github:https://my-github-instance.com/<owner>/<repo>/<item-name>This syntax tells the GitHub provider that it can resolve this URL as a GitHub repository.
Authentication
To authenticate with GitHub you can run the following command:
jsrepo auth githubYou can logout of your account by running:
jsrepo auth github --logoutEnvironment Variable
If you prefer to use an environment variable or are in an environment where you can't use the jsrepo auth command you can provide the token via the GITHUB_TOKEN environment variable.
GITHUB_TOKEN=... jsrepo add Deploying your registry to GitHub
When deploying your registry to GitHub you will want to use the repository output type:
import { defineConfig } from "jsrepo";
import { repository } from "jsrepo/outputs";
export default defineConfig({
registry: {
// ...
outputs: [repository()],
},
});This will create a registry.json file that will contain everything users need to use your registry.
The registry.json file must be at the root of your repository otherwise users won't be able to use your registry.
Workflow
If you want to use GitHub Actions to automatically build your registry when you push changes you can use this workflow:
name: build-registry
on:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Build registry.json
run: jsrepo build
- name: Create pull request with changes
uses: peter-evans/create-pull-request@v7
with:
title: 'chore: update `registry.json`'
body: |
- Update `registry.json`
---
This PR was auto generated
branch: build-registry
commit-message: build `registry.json`Options
Prop
Type