Skip to content

Commit

Permalink
Merge pull request #6 from gentlementlegen/feat/worker-instance
Browse files Browse the repository at this point in the history
feat!: assistive-pricing as a Worker
  • Loading branch information
gentlementlegen authored May 23, 2024
2 parents fd41b71 + 207a189 commit 437ed6a
Show file tree
Hide file tree
Showing 31 changed files with 816 additions and 439 deletions.
2 changes: 1 addition & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "**/*.toml", "src/adapters/supabase/types/database.ts"],
"useGitignore": true,
"language": "en",
"words": ["dataurl", "devpool", "outdir", "servedir", "supabase", "typebox", "typeguards"],
"words": ["dataurl", "devpool", "outdir", "servedir", "supabase", "typebox", "typeguards", "mswjs", "ubiquibot"],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
"ignoreRegExpList": ["[0-9a-fA-F]{6}"]
Expand Down
2 changes: 2 additions & 0 deletions .dev.vars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SUPABASE_URL=
SUPABASE_KEY=
6 changes: 3 additions & 3 deletions .github/knip.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { KnipConfig } from "knip";

const config: KnipConfig = {
entry: ["build/index.ts"],
entry: ["src/index.ts"],
project: ["src/**/*.ts"],
ignore: ["src/types/config.ts"],
ignore: ["src/types/config.ts", "src/adapters/supabase/types/database.ts"],
ignoreExportsUsedInFile: true,
ignoreDependencies: [],
ignoreDependencies: ["ts-node", "@types/jest"],
};

export default config;
2 changes: 1 addition & 1 deletion .github/workflows/jest-testing.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Run Jest testing suite
on:
workflow_dispatch:
pull_request_target:
pull_request:
types: [ opened, synchronize ]

env:
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/knip-reporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Knip-reporter

on:
workflow_run:
workflows: ["Knip"]
types:
- completed

permissions: write-all

jobs:
knip-reporter:
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: knip-results
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Read pr number
id: pr-number
uses: juliangruber/read-file-action@v1
with:
path: ./pr-number.txt
trim: true

- name: Report knip results to pull request
if: ${{ github.event.workflow_run.conclusion != 'success' }}
uses: gitcoindev/knip-reporter@main
with:
verbose: true
comment_id: ${{ github.workflow }}-reporter
command_script_name: knip-ci
annotations: true
ignore_results: false
json_input: true
json_input_file_name: knip-results.json
pull_request_number: ${{ steps.pr-number.outputs.content }}
token: ${{ secrets.GITHUB_TOKEN }}
28 changes: 14 additions & 14 deletions .github/workflows/knip.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
name: Knip

on:
pull_request_target:
pull_request:
workflow_dispatch:

permissions: write-all

jobs:
run-knip:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Setup Node
uses: actions/setup-node@v4
with:
Expand All @@ -25,11 +19,17 @@ jobs:
- name: Install toolchain
run: yarn install

- name: Report knip results to pull request
uses: Codex-/knip-reporter@v2
- name: Store PR number
run: echo ${{ github.event.number }} > pr-number.txt

- name: Run Knip
run: yarn knip || yarn knip --reporter json > knip-results.json

- name: Upload knip result
if: failure()
uses: actions/upload-artifact@v4
with:
verbose: true
comment_id: ${{ github.workflow }}-reporter
command_script_name: knip-ci
annotations: true
ignore_results: false
name: knip-results
path: |
knip-results.json
pr-number.txt
29 changes: 29 additions & 0 deletions .github/workflows/worker-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Deploy

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
- uses: actions/checkout@v4
- uses: cloudflare/wrangler-action@v3
with:
wranglerVersion: '3.57.0'
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
secrets: |
SUPABASE_URL
SUPABASE_KEY
UBIQUIBOT_TOKEN
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
UBIQUIBOT_TOKEN: ${{ secrets.UBIQUIBOT_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ static/dist
coverage
junit.xml
cypress/screenshots

.dev.vars
/tests/http/http-client.private.env.json
61 changes: 49 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,62 @@
# `@ubiquibot/assistive-pricing`

This template repository includes support for the following:
Helps settings prices and adds label to the issues accordingly.

- TypeScript
- Environment Variables
- Conventional Commits
- Automatic deployment to Cloudflare Pages

## Testing
## Usage
Example of valid configuration:
```yml
- plugin: https://ubiquibot-assistive-pricing.ubq.fi
type: github
with:
labels:
time:
- "Time: <1 Hour"
- "Time: <2 Hours"
- "Time: <4 Hours"
- "Time: <1 Day"
- "Time: <1 Week"
priority:
- "Priority: 1 (Normal)"
- "Priority: 2 (Medium)"
- "Priority: 3 (High)"
- "Priority: 4 (Urgent)"
- "Priority: 5 (Emergency)"
basePriceMultiplier: 1
publicAccessControl:
setLabel: true
fundExternalClosedIssue: false
```
### Cypress
To test with Cypress Studio UI, run
## Running locally
### Supabase
Supabase can be started through the CLI running
```shell
yarn cy:open
supabase start
```

Otherwise to simply run the tests through the console, run
### Worker
Start the Worker by running
```shell
yarn cy:run
yarn worker
```

### Make requests
To trigger the worker, `POST` requests should be made to http://localhost:4000 with a `Content-Type: application/json`
header and a body
looking like
```json
{
"stateId": "",
"eventName": "",
"eventPayload": "",
"settings": "",
"ref": ""
}
```
For convenience you can find an `.http` file with a valid request [here](/tests/http/request.http).

## Testing

### Jest
To start Jest tests, run
```shell
Expand Down
11 changes: 0 additions & 11 deletions cypress.config.ts

This file was deleted.

11 changes: 0 additions & 11 deletions cypress/e2e/main.cy.ts

This file was deleted.

5 changes: 0 additions & 5 deletions cypress/fixtures/example.json

This file was deleted.

37 changes: 0 additions & 37 deletions cypress/support/commands.ts

This file was deleted.

20 changes: 0 additions & 20 deletions cypress/support/e2e.ts

This file was deleted.

15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"node": ">=20.10.0"
},
"scripts": {
"worker": "wrangler dev --env dev --port 4000",
"start": "tsx src/index.ts",
"format": "run-s format:lint format:prettier format:cspell",
"format:lint": "eslint --fix .",
Expand All @@ -18,8 +19,6 @@
"knip-ci": "knip --no-exit-code --reporter json --config .github/knip.ts",
"prepare": "husky install",
"test": "jest --setupFiles dotenv/config --coverage",
"cy:open": "cypress open",
"cy:run": "cypress run",
"supabase:generate:local": "supabase gen types typescript --local > src/adapters/supabase/types/database.ts",
"supabase:generate:remote": "dotenv -- cross-env-shell supabase gen types typescript --project-id $SUPABASE_PROJECT_ID --schema public > src/adapters/supabase/types/database.ts"
},
Expand All @@ -38,30 +37,25 @@
"@octokit/webhooks": "^13.1.0",
"@sinclair/typebox": "^0.32.15",
"@supabase/supabase-js": "2.43.1",
"@types/ms": "^0.7.34",
"commander": "12.0.0",
"dotenv": "^16.4.5",
"ms": "^2.1.3"
"dotenv": "^16.4.5"
},
"devDependencies": {
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.2",
"@cspell/dict-node": "^4.0.3",
"@cspell/dict-software-terms": "^3.3.18",
"@cspell/dict-typescript": "^3.1.2",
"@jest/globals": "29.7.0",
"@mswjs/data": "0.16.1",
"@types/jest": "29.5.12",
"@types/node": "^20.11.19",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"cross-env": "7.0.3",
"cspell": "^8.4.0",
"cypress": "13.6.6",
"dotenv-cli": "7.4.2",
"esbuild": "^0.20.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-sonarjs": "^0.24.0",
"husky": "^9.0.11",
"jest": "29.7.0",
Expand All @@ -74,7 +68,8 @@
"ts-jest": "29.1.2",
"ts-node": "10.9.2",
"tsx": "^4.7.1",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"wrangler": "3.57.0"
},
"lint-staged": {
"*.ts": [
Expand Down
Loading

0 comments on commit 437ed6a

Please sign in to comment.