Skip to content

Commit

Permalink
Merge pull request #223 from peace-maker/ci
Browse files Browse the repository at this point in the history
Add Continuous Integration using Github Actions
  • Loading branch information
JJ-8 authored Apr 29, 2024
2 parents 97a79ed + 5a1face commit c2e0638
Show file tree
Hide file tree
Showing 21 changed files with 3,056 additions and 940 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Continuous Integration

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_PASSWORD: ctfnote
POSTGRES_USER: ctfnote
ports:
- 5432:5432

strategy:
fail-fast: false
matrix:
node: [20, 19, 18]

name: Node.js ${{ matrix.node }} build
steps:
- uses: actions/checkout@v4

- name: Set up Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: "yarn"
cache-dependency-path: |
api/yarn.lock
front/yarn.lock
- name: Build api
working-directory: ./api
run: |
yarn install --immutable --immutable-cache --check-cache
yarn build
yarn run pg-validate-migrations ./migrations
- name: Build frontend
working-directory: ./front
run: |
yarn install --immutable --immutable-cache --check-cache
yarn build
- name: Run database migrations and codegen
env:
PAD_CREATE_URL: http://hedgedoc:3000/new
PAD_SHOW_URL: /
DB_DATABASE: ctfnote
DB_ADMIN_LOGIN: ctfnote
DB_ADMIN_PASSWORD: ctfnote
DB_USER_LOGIN: user_postgraphile
DB_USER_PASSWORD: secret_password
DB_HOST: 127.0.0.1
DB_PORT: 5432
WEB_PORT: 3000
run: |
cd ./api
# create database tables first, running migrations
DB_MIGRATE_ONLY=1 yarn start
# then start the api backend server
nohup yarn start &
cd ../front
# and finally validate the generated files are up to date
bash ../api/start.sh 127.0.0.1 3000 yarn run graphql-codegen --config codegen.yml --check
lint:
runs-on: ubuntu-latest
name: Lint
steps:
- uses: actions/checkout@v4
- name: Set up Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18
cache: "yarn"
cache-dependency-path: |
api/yarn.lock
front/yarn.lock
- name: Install frontend dependencies
working-directory: ./front
run: yarn install --immutable --immutable-cache --check-cache

- name: Lint frontend
working-directory: ./front
run: |
yarn run eslint --ext .js,.ts,.vue,.graphql ./src
yarn run prettier --check 'src/**/*.{ts,js,vue,graphql}'
- name: Install api dependencies
working-directory: ./api
run: yarn install --immutable --immutable-cache --check-cache

- name: Lint api
working-directory: ./api
run: |
yarn run eslint --ext .ts ./src
yarn run prettier --check 'src/**/*.ts'
2 changes: 2 additions & 0 deletions api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type CTFNoteConfig = DeepReadOnly<{
};
host: string;
port: number;
migrateOnly: boolean;
};
pad: {
createUrl: string;
Expand Down Expand Up @@ -73,6 +74,7 @@ const config: CTFNoteConfig = {
},
host: getEnv("DB_HOST"),
port: getEnvInt("DB_PORT"),
migrateOnly: !!process.env["DB_MIGRATE_ONLY"],
},
pad: {
createUrl: getEnv("PAD_CREATE_URL"),
Expand Down
4 changes: 3 additions & 1 deletion api/src/discord/commands/archiveCtf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ async function archiveCtfLogic(
);
}

const actionRow: any = new ActionRowBuilder().addComponents(buttons);
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
buttons
);

await interaction.editReply({
content: "Which CTF do you want to archive?",
Expand Down
4 changes: 3 additions & 1 deletion api/src/discord/commands/createCtf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ async function createCtfLogic(client: Client, interaction: CommandInteraction) {
}

// Create the action row with the button components
const actionRow: any = new ActionRowBuilder().addComponents(buttons);
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
buttons
);

await interaction.editReply({
content: ctfNamesMessage,
Expand Down
5 changes: 3 additions & 2 deletions api/src/discord/commands/deleteCtf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
ApplicationCommandType,
ButtonBuilder,
ButtonStyle,
ChannelType,
Client,
CommandInteraction,
Interaction,
Expand Down Expand Up @@ -64,7 +63,9 @@ async function deleteCtfLogic(client: Client, interaction: CommandInteraction) {
);
}

const actionRow: any = new ActionRowBuilder().addComponents(buttons);
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
buttons
);

await interaction.editReply({
content:
Expand Down
1 change: 1 addition & 0 deletions api/src/discord/database/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Task {
flag: string;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function buildTask(row: any): Task {
return {
id: row.id as bigint,
Expand Down
4 changes: 4 additions & 0 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ async function performMigrations() {

async function main() {
await performMigrations();
if (config.db.migrateOnly) {
console.log("Migrations done. Exiting.");
return;
}
const postgraphileOptions = createOptions();
const app = createApp(postgraphileOptions);

Expand Down
5 changes: 4 additions & 1 deletion api/src/plugins/savepointWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Client } from "pg";

async function savepointWrapper(pgClient: Client, f: () => any): Promise<any> {
async function savepointWrapper<Type>(
pgClient: Client,
f: () => Type
): Promise<Type> {
const name = `"CHECKPOINT-${Math.floor(Math.random() * 0xffff)}"`;
await pgClient.query(`SAVEPOINT ${name}`);
try {
Expand Down
Loading

0 comments on commit c2e0638

Please sign in to comment.