forked from ubiquity-os/ubiquity-os-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/development' into feat/jest
# Conflicts: # .gitignore # bun.lockb # package.json # src/github/types/env.ts # tests/__mocks__/db.ts # tests/main.test.ts
- Loading branch information
Showing
24 changed files
with
835 additions
and
100 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { KnipConfig } from "knip"; | ||
|
||
const config: KnipConfig = { | ||
entry: ["build/index.ts"], | ||
project: ["src/**/*.ts"], | ||
ignore: ["src/types/config.ts"], | ||
ignoreExportsUsedInFile: true, | ||
ignoreDependencies: [], | ||
}; | ||
|
||
export default config; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Build & Deploy | ||
|
||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
# with: | ||
# submodules: "recursive" # Ensures submodules are checked out | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20.10.0 | ||
|
||
- name: Build | ||
run: | | ||
npm i -g bun | ||
bun install | ||
bun build src/worker.ts | ||
# env: # Set environment variables for the build | ||
# SUPABASE_URL: "https://wfzpewmlyiozupulbuur.supabase.co" | ||
# SUPABASE_ANON_KEY: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6IndmenBld21seWlvenVwdWxidXVyIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTU2NzQzMzksImV4cCI6MjAxMTI1MDMzOX0.SKIL3Q0NOBaMehH0ekFspwgcu3afp3Dl9EDzPqs1nKs" |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Run Jest testing suite | ||
on: | ||
workflow_dispatch: | ||
pull_request_target: | ||
types: [ opened, synchronize ] | ||
|
||
env: | ||
NODE_ENV: "test" | ||
|
||
jobs: | ||
testing: | ||
permissions: write-all | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.10.0' | ||
- uses: actions/checkout@master | ||
with: | ||
fetch-depth: 0 | ||
- name: Build & Run test suite | ||
run: | | ||
npm i -g bun | ||
bun install | ||
bun test | tee ./coverage.txt && exit ${PIPESTATUS[0]} | ||
- name: Jest Coverage Comment | ||
# Ensures this step is run even on previous step failure (e.g. test failed) | ||
if: always() | ||
uses: MishaKav/jest-coverage-comment@main | ||
with: | ||
coverage-summary-path: coverage/coverage-summary.json | ||
junitxml-path: junit.xml | ||
junitxml-title: JUnit | ||
coverage-path: ./coverage.txt |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Knip | ||
|
||
on: | ||
pull_request_target: | ||
workflow_dispatch: | ||
|
||
permissions: write-all | ||
|
||
jobs: | ||
run-knip: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20.10.0 | ||
|
||
- name: Install toolchain | ||
run: | | ||
npm i -g bun | ||
bun install | ||
- name: Report knip results to pull request | ||
uses: Codex-/knip-reporter@v2 | ||
with: | ||
verbose: true | ||
comment_id: ${{ github.workflow }}-reporter | ||
command_script_name: knip-ci | ||
annotations: true | ||
ignore_results: false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,8 @@ node_modules | |
.yarn | ||
.pnp.cjs | ||
.pnp.loader.mjs | ||
.env | ||
static/dist | ||
keys | ||
coverage | ||
junit.xml |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,106 @@ | ||
|
||
# @ubiquity/ubiquibot-kernel | ||
|
||
The kernel is designed to: | ||
|
||
- Interface with plugins (GitHub Actions) for longer running processes. | ||
- Run on Cloudflare Workers. | ||
|
||
## Environment variables | ||
## Environment Variables | ||
|
||
- **`PRIVATE_KEY`** | ||
Obtain a private key from your GitHub App settings and convert it to the Public-Key Cryptography Standards #8 (PKCS#8) format. Use the following command to perform this conversion and append the result to your `.dev.vars` file: | ||
|
||
- `PRIVATE_KEY` | ||
You need to obtain a private key from your GitHub App settings and convert it to Public-Key Cryptography Standards #8 (PKCS#8) format. You can use the following command to perform this conversion and append the result to your `.dev.vars` file: | ||
```sh | ||
echo "PRIVATE_KEY=\"$(openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in YOUR_PRIVATE_KEY.PEM | awk 'BEGIN{ORS="\\n"} 1')\"" >> .dev.vars | ||
``` | ||
|
||
```sh | ||
echo "PRIVATE_KEY=\"$(openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in YOUR_PRIVATE_KEY.PEM | awk 'BEGIN{ORS="\\n"} 1')\"" >> .dev.vars | ||
``` | ||
**Note:** Replace `YOUR_PRIVATE_KEY.PEM` with the path to your actual PEM file when running the command. | ||
|
||
###### Please replace `YOUR_PRIVATE_KEY.PEM` with the path to your actual PEM file when running the command. | ||
- **`WEBHOOK_SECRET`** | ||
Set this value in both your GitHub App settings and here. | ||
|
||
- `WEBHOOK_SECRET` | ||
This should be set in your GitHub App settings and also here. | ||
- **`APP_ID`** | ||
Retrieve this from your GitHub App settings. | ||
|
||
- `APP_ID` | ||
You can find this in your GitHub App settings. | ||
- **`WEBHOOK_PROXY_URL` (only for development)** | ||
Obtain a webhook URL at [smee.io](https://smee.io/) and set it in your GitHub App settings. | ||
|
||
- `WEBHOOK_PROXY_URL` (only for development) | ||
You need to obtain a webhook URL at <https://smee.io/> and set it in the GitHub App settings. | ||
|
||
### Quick Start | ||
|
||
```bash | ||
git clone https://github.com/ubiquity/ubiquibot-kernel | ||
cd ubiquibot-kernel | ||
bun | ||
bun install | ||
bun dev | ||
``` | ||
|
||
### Deploying to Cloudflare Workers | ||
|
||
1. **Install Dependencies:** | ||
- Execute `bun install` to install the required dependencies. | ||
|
||
2. **Create a Github App:** | ||
- Generate a Github App and configure its settings. | ||
- Navigate to app settings and click `Permissions & events`. | ||
- Ensure the app is subscribed to all events with the following permissions: | ||
|
||
Repository permissions: | ||
- Actions: Read & Write | ||
- Contents: Read & Write | ||
- Issues: Read & Write | ||
- Pull Requests: Read & Write | ||
|
||
Organization permissions: | ||
- Members: Read only | ||
|
||
3. **Cloudflare Account Setup:** | ||
- If not done already, create a Cloudflare account. | ||
- Run `npx wrangler login` to log in. | ||
|
||
4. **Create a KV Namespace:** | ||
- Generate a KV namespace using `npx wrangler kv:namespace create PLUGIN_CHAIN_STATE`. | ||
- Copy the generated ID and paste it under `[env.dev]` in `wrangler.toml`. | ||
|
||
5. **Manage Secrets:** | ||
- Add (env) secrets using `npx wrangler secret put <KEY> --env dev`. | ||
- For the private key, execute the following (replace `YOUR_PRIVATE_KEY.PEM` with the actual PEM file path): | ||
|
||
```sh | ||
echo $(openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in YOUR_PRIVATE_KEY.PEM) | npx wrangler secret put PRIVATE_KEY --env dev | ||
``` | ||
|
||
6. **Deploy the Kernel:** | ||
- Execute `bun run deploy-dev` to deploy the kernel. | ||
|
||
### Plugin Input and Output | ||
|
||
#### Input | ||
|
||
Inputs are received within the workflow, triggered by the `workflow_dispatch` event. The plugin is designed to handle the following inputs: | ||
|
||
- `stateId`: An identifier used to track the state of plugin chain execution in Cloudflare KV. It is crucial to pass this identifier back in the output. | ||
- `eventName`: The complete name of the event (e.g., `issue_comment.created`). | ||
- `eventPayload`: The payload associated with the event. | ||
- `settings`: A string containing JSON with settings specific to your plugin. The plugin itself defines these settings. | ||
- `authToken`: A JWT token for accessing GitHub's API to the repository where the event occurred. | ||
- `ref`: A reference (branch, tag, commit SHA) indicating the version of the plugin to be utilized. | ||
#### Output | ||
Data is returned using the `repository_dispatch` event on the plugin's repository, and the output is structured within the `client_payload`. | ||
The `event_type` must be set to `return_data_to_ubiquibot_kernel`. | ||
|
||
- `state_id`: The state ID passed in the inputs must be included here. | ||
- `output`: A string containing JSON with custom output, defined by the plugin itself. | ||
|
||
## Testing | ||
|
||
### Jest | ||
|
||
To start Jest tests, run | ||
|
||
```shell | ||
bun test | ||
``` |
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
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
Oops, something went wrong.