From 855746ff670c24aa8c2c5c81e14925533696f91a Mon Sep 17 00:00:00 2001 From: CyberFlame Date: Sun, 24 Dec 2023 06:07:45 +1300 Subject: [PATCH] potentially add ci and cd Signed-off-by: CyberFlame --- .github/workflows/ci.yml | 57 +++++++++++++++++++++++++ .github/workflows/ci.yml.disabled | 48 --------------------- .github/workflows/register.yml | 31 ++++++++++++++ .github/workflows/register.yml.disabled | 6 --- pnpm-lock.yaml | 48 ++++++++++----------- src/discord.ts | 2 +- src/register.js | 7 +-- src/server.ts | 10 +---- src/worker-configuration.d.ts | 9 ++++ tsconfig.json | 2 +- 10 files changed, 125 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/ci.yml.disabled create mode 100644 .github/workflows/register.yml delete mode 100644 .github/workflows/register.yml.disabled create mode 100644 src/worker-configuration.d.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4850136 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: "CI/CD" + +on: + push: + branches: + - main + pull_request: + branches: [ main ] + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20] + steps: + - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2 + with: + version: 8 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - name: Install dependencies + run: pnpm install + + - run: pnpm run lint + deploy: + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20] + needs: [lint] + environment: + name: 'production' + url: 'https://discord.worker.nceahelp.com/' + steps: + - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2 + with: + version: 8 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - name: Install dependencies + run: pnpm install + + - name: Deploy + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CF_ACCOUNT_ID }} diff --git a/.github/workflows/ci.yml.disabled b/.github/workflows/ci.yml.disabled deleted file mode 100644 index a8e6754..0000000 --- a/.github/workflows/ci.yml.disabled +++ /dev/null @@ -1,48 +0,0 @@ -on: - push: - branches: - - main - pull_request: - name: ci - jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [20] - steps: - - uses: actions/checkout@v3 - - uses: pnpm/action-setup@v2 - with: - version: 8 - - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - run: npm install - - run: npm test - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - run: pnpm install - - run: pnpm run lint - deploy: - if: github.ref == 'refs/heads/main' - runs-on: ubuntu-latest - needs: [test, lint] - environment: - name: 'production' - url: 'https://discord.worker.nceahelp.com/' - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - run: pnpm install - - run: pnpm run publish - env: - CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }} - CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} diff --git a/.github/workflows/register.yml b/.github/workflows/register.yml new file mode 100644 index 0000000..44f02f5 --- /dev/null +++ b/.github/workflows/register.yml @@ -0,0 +1,31 @@ +name: "Register to Discord" + +on: + push: + branches: + - 'main' + paths: + - 'src/commands.js' +jobs: + lint: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20] + steps: + - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2 + with: + version: 8 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - name: Install dependencies + run: pnpm install + + - run: pnpm run register + with: + DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} + DISCORD_APPLICATION_ID: ${{ secrets.DISCORD_APPLICATION_ID }} diff --git a/.github/workflows/register.yml.disabled b/.github/workflows/register.yml.disabled deleted file mode 100644 index 86b0dd4..0000000 --- a/.github/workflows/register.yml.disabled +++ /dev/null @@ -1,6 +0,0 @@ -on: - push: - branches: - - 'main' - paths: - - 'src/metadata.js' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 050c159..b2e0e1b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -465,7 +465,7 @@ packages: engines: {node: '>= 8'} dependencies: '@nodelib/fs.scandir': 2.1.5 - fastq: 1.15.0 + fastq: 1.16.0 dev: true /@pkgr/utils@2.4.2: @@ -532,7 +532,7 @@ packages: resolution: {integrity: sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==} dependencies: '@types/connect': 3.4.38 - '@types/node': 20.10.4 + '@types/node': 20.10.5 dev: false /@types/cacheable-request@6.0.3: @@ -540,27 +540,27 @@ packages: dependencies: '@types/http-cache-semantics': 4.0.4 '@types/keyv': 3.1.4 - '@types/node': 20.10.4 + '@types/node': 20.10.5 '@types/responselike': 1.0.3 dev: true /@types/cheerio@0.22.35: resolution: {integrity: sha512-yD57BchKRvTV+JD53UZ6PD8KWY5g5rvvMLRnZR3EQBCZXiDT/HR+pKpMzFGlWNhFrXlo7VPZXtKvIEwZkAWOIA==} dependencies: - '@types/node': 20.10.4 + '@types/node': 20.10.5 dev: false /@types/connect@3.4.38: resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==} dependencies: - '@types/node': 20.10.4 + '@types/node': 20.10.5 dev: false /@types/express-serve-static-core@4.17.41: resolution: {integrity: sha512-OaJ7XLaelTgrvlZD8/aa0vvvxZdUmlCn6MtWeB7TkiKW70BQLc9XEPpDLPdbo52ZhXUCrznlWdCHWxJWtdyajA==} dependencies: - '@types/node': 20.10.4 - '@types/qs': 6.9.10 + '@types/node': 20.10.5 + '@types/qs': 6.9.11 '@types/range-parser': 1.2.7 '@types/send': 0.17.4 dev: false @@ -570,7 +570,7 @@ packages: dependencies: '@types/body-parser': 1.19.5 '@types/express-serve-static-core': 4.17.41 - '@types/qs': 6.9.10 + '@types/qs': 6.9.11 '@types/serve-static': 1.15.5 dev: false @@ -589,7 +589,7 @@ packages: /@types/keyv@3.1.4: resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==} dependencies: - '@types/node': 20.10.4 + '@types/node': 20.10.5 dev: true /@types/mime@1.3.5: @@ -603,16 +603,16 @@ packages: /@types/node-forge@1.3.10: resolution: {integrity: sha512-y6PJDYN4xYBxwd22l+OVH35N+1fCYWiuC3aiP2SlXVE6Lo7SS+rSx9r89hLxrP4pn6n1lBGhHJ12pj3F3Mpttw==} dependencies: - '@types/node': 20.10.4 + '@types/node': 20.10.5 dev: true - /@types/node@20.10.4: - resolution: {integrity: sha512-D08YG6rr8X90YB56tSIuBaddy/UXAA9RKJoFvrsnogAum/0pmjkgi4+2nx96A330FmioegBWmEYQ+syqCFaveg==} + /@types/node@20.10.5: + resolution: {integrity: sha512-nNPsNE65wjMxEKI93yOP+NPGGBJz/PoN3kZsVLee0XMiJolxSekEVD8wRwBUBqkwc7UWop0edW50yrCQW4CyRw==} dependencies: undici-types: 5.26.5 - /@types/qs@6.9.10: - resolution: {integrity: sha512-3Gnx08Ns1sEoCrWssEgTSJs/rsT2vhGP+Ja9cnnk9k4ALxinORlQneLXFeFKOTJMOeZUFD1s7w+w2AphTpvzZw==} + /@types/qs@6.9.11: + resolution: {integrity: sha512-oGk0gmhnEJK4Yyk+oI7EfXsLayXatCWPHary1MtcmbAifkobT9cM9yutG/hZKIseOU0MqbIwQ/u2nn/Gb+ltuQ==} dev: false /@types/range-parser@1.2.7: @@ -622,14 +622,14 @@ packages: /@types/responselike@1.0.3: resolution: {integrity: sha512-H/+L+UkTV33uf49PH5pCAUBVPNj2nDBXTN+qS1dOwyyg24l3CcicicCA7ca+HMvJBZcFgl5r8e+RR6elsb4Lyw==} dependencies: - '@types/node': 20.10.4 + '@types/node': 20.10.5 dev: true /@types/send@0.17.4: resolution: {integrity: sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA==} dependencies: '@types/mime': 1.3.5 - '@types/node': 20.10.4 + '@types/node': 20.10.5 dev: false /@types/serve-static@1.15.5: @@ -637,14 +637,14 @@ packages: dependencies: '@types/http-errors': 2.0.4 '@types/mime': 3.0.4 - '@types/node': 20.10.4 + '@types/node': 20.10.5 dev: false /@types/yauzl@2.10.3: resolution: {integrity: sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==} requiresBuild: true dependencies: - '@types/node': 20.10.4 + '@types/node': 20.10.5 dev: true optional: true @@ -944,7 +944,7 @@ packages: dev: true /concat-map@0.0.1: - resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} + resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} dev: true /convert-source-map@2.0.0: @@ -1321,7 +1321,7 @@ packages: human-signals: 4.3.1 is-stream: 3.0.0 merge-stream: 2.0.0 - npm-run-path: 5.1.0 + npm-run-path: 5.2.0 onetime: 6.0.0 signal-exit: 3.0.7 strip-final-newline: 3.0.0 @@ -1373,8 +1373,8 @@ packages: resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==} dev: true - /fastq@1.15.0: - resolution: {integrity: sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==} + /fastq@1.16.0: + resolution: {integrity: sha512-ifCoaXsDrsdkWTtiNJX5uzHDsrck5TzfKKDcuFFTIrrc/BS076qgEIfoIy1VeZqViznfKiysPYTh/QeHtnIsYA==} dependencies: reusify: 1.0.4 dev: true @@ -2017,8 +2017,8 @@ packages: path-key: 3.1.1 dev: true - /npm-run-path@5.1.0: - resolution: {integrity: sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==} + /npm-run-path@5.2.0: + resolution: {integrity: sha512-W4/tgAXFqFA0iL7fk0+uQ3g7wkL8xJmx3XdK0VGb4cHW//eZTtKGvFBBoRKVTpY7n6ze4NL9ly7rgXcHufqXKg==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: path-key: 4.0.0 diff --git a/src/discord.ts b/src/discord.ts index e54aaa2..40b9488 100644 --- a/src/discord.ts +++ b/src/discord.ts @@ -4,7 +4,7 @@ import { RESTPostOAuth2RefreshTokenResult, Snowflake, } from 'discord-api-types/v10'; -import { Bindings } from './server'; +import { Bindings } from './worker-configuration'; import * as storage from './storage'; export function getOAuthUrl(env: any) { diff --git a/src/register.js b/src/register.js index 9ba1b1c..f8a8926 100644 --- a/src/register.js +++ b/src/register.js @@ -79,12 +79,7 @@ const metadata = [ }, ]; -const cmds = [ - commands.REVIVE_COMMAND, - commands.TEST_COMMAND, - commands.PING_COMMAND, - commands.LOOKUP_COMMAND, -]; +const cmds = Object.values(commands); const commandEndpoint = `https://discord.com/api/v10/applications/${applicationId}/commands`; const metadataEndpoint = `https://discord.com/api/v10/applications/${applicationId}/role-connections/metadata`; diff --git a/src/server.ts b/src/server.ts index 17c130c..5a05fbb 100644 --- a/src/server.ts +++ b/src/server.ts @@ -14,16 +14,8 @@ import * as discordJs from 'discord-api-types/v10'; import { isValidRequest } from 'discord-verify'; import * as storage from './storage.js'; import * as discord from './discord.js'; +import { Bindings } from './worker-configuration.js'; -export type Bindings = { - DISCORD_PUBLIC_KEY: string; - DISCORD_APPLICATION_ID: string; - DISCORD_CLIENT_SECRET: string; - TOKEN: string; - WORKER_URL: string; - COOKIE_SECRET: string; - TOKEN_STORE: KVNamespace; -}; const router = new Hono<{ Bindings: Bindings }>(); diff --git a/src/worker-configuration.d.ts b/src/worker-configuration.d.ts new file mode 100644 index 0000000..03a94b0 --- /dev/null +++ b/src/worker-configuration.d.ts @@ -0,0 +1,9 @@ +export type Bindings = { + DISCORD_PUBLIC_KEY: string; + DISCORD_APPLICATION_ID: string; + DISCORD_CLIENT_SECRET: string; + TOKEN: string; + WORKER_URL: string; + COOKIE_SECRET: string; + TOKEN_STORE: KVNamespace; + }; diff --git a/tsconfig.json b/tsconfig.json index f5cb954..92e3798 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -34,7 +34,7 @@ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ "types": [ - "@cloudflare/workers-types" + "@cloudflare/workers-types/experimental" ] /* Specify type package names to be included without being referenced in a source file. */, // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ "resolveJsonModule": true /* Enable importing .json files */,