Skip to content

Commit

Permalink
potentially add ci and cd
Browse files Browse the repository at this point in the history
Signed-off-by: CyberFlame <[email protected]>
  • Loading branch information
CyberFlameGO committed Dec 23, 2023
1 parent 6786527 commit 855746f
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 95 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 }}
48 changes: 0 additions & 48 deletions .github/workflows/ci.yml.disabled

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/register.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 0 additions & 6 deletions .github/workflows/register.yml.disabled

This file was deleted.

48 changes: 24 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 1 addition & 6 deletions src/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
10 changes: 1 addition & 9 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>();

Expand Down
9 changes: 9 additions & 0 deletions src/worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 */,
Expand Down

0 comments on commit 855746f

Please sign in to comment.