Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup+GitHub actions #111

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# some (*)nix distros dont have /bin/bash

echo "Frontend linting"
(cd vinvoor && pnpm --silent run precommit:lint)
if [ $? -ne 0 ]; then
echo "Frontend linting failed. Please fix the errors before committing."
exit 1
fi

echo "Frontend typecheck"
(cd vinvoor && pnpm --silent run precommit:typecheck)
if [ $? -ne 0 ]; then
echo "Frontend type checking failed. Please fix the errors before committing."
exit 1
fi
20 changes: 0 additions & 20 deletions .githooks/vinvoor_format_lint

This file was deleted.

4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
- main
pull_request:

concurrency:
group: docker-main
cancel-in-progress: true

jobs:
build-and-push:
runs-on: ubuntu-latest
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/vingo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
name: Vingo format and clipy check

on:
push:
branches:
- main
paths:
- .github/workflows/vingo.yml
- 'vingo/**/*.rs'
pull_request:
paths:
- .github/workflows/vingo.yml
- 'vingo/**/*.rs'
workflow_dispatch:

jobs:

formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install latest rust toolchain
uses: actions-rs/[email protected]
with:
toolchain: stable
components: rustfmt
override: true

- name: Check formatting
working-directory: vingo/
run: cargo fmt -- --check

clipy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install latest rust toolchain
uses: actions-rs/[email protected]
with:
toolchain: stable
components: clippy
override: true
- name: Clippy check
working-directory: vingo/
run: cargo clippy --locked --all-targets --all-features
27 changes: 27 additions & 0 deletions .github/workflows/vingo_audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Vingo Audit Rust dependencies
on:
pull_request:
paths:
- .github/workflows/vingo_audit.yml
- 'vingo/**/Cargo.toml'
- 'vingo/**/Cargo.lock'

schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
security_audit:
runs-on: ubuntu-latest

permissions:
issues: write
checks: write

steps:
- uses: actions/checkout@v4
- uses: rustsec/[email protected]
working-directory: vingo/
with:
token: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Format and linting
name: Vinvoor Format, Lint & Typecheck

on:
push:
Expand All @@ -14,10 +14,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.15.1
node-version: 22.8.0

- name: Install pnpm
run: npm install -g pnpm
Expand All @@ -26,10 +26,10 @@ jobs:
run: pnpm install
working-directory: vinvoor/

- name: Run formatter
run: pnpm prettier --check .
- name: Run format & lint
run: pnpm eslint .
working-directory: vinvoor/

- name: Run Linter
run: pnpm eslint . --max-warnings=0
- name: Run typecheck
run: pnpm tsc --noEmit
working-directory: vinvoor/
6 changes: 2 additions & 4 deletions vingo/migration/src/m20240903_194156_create_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Migration;
enum Scan {
Table,
Id,
ScanTime,
Time,
CardSerial,
}

Expand All @@ -22,9 +22,7 @@ impl MigrationTrait for Migration {
.table(Scan::Table)
.col(pk_auto(Scan::Id))
.col(text(Scan::CardSerial))
.col(
timestamp_with_time_zone(Scan::ScanTime).default(Expr::current_timestamp()),
)
.col(timestamp_with_time_zone(Scan::Time).default(Expr::current_timestamp()))
.foreign_key(
ForeignKey::create()
.from(Scan::Table, Scan::CardSerial)
Expand Down
2 changes: 1 addition & 1 deletion vingo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use tower_sessions::{cookie::SameSite, MemoryStore, SessionManagerLayer};

use migration::{Migrator, MigratorTrait};

const DB_URL: LazyLock<String> = LazyLock::new(|| {
static DB_URL: LazyLock<String> = LazyLock::new(|| {
env::var("POSTGRES_CONNECTION_STRING").expect("POSTGRES_CONNECTION_STRING not present")
});

Expand Down
12 changes: 6 additions & 6 deletions vingo/src/routes/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ use crate::AppState;
use super::util::errors::{ResponseResult, ResultAndLogError};
use super::util::session::{get_user, SessionKeys};

const ZAUTH_URL: LazyLock<String> =
static ZAUTH_URL: LazyLock<String> =
LazyLock::new(|| env::var("ZAUTH_URL").expect("ZAUTH_URL not present"));
const CALLBACK_URL: LazyLock<String> =
static CALLBACK_URL: LazyLock<String> =
LazyLock::new(|| env::var("ZAUTH_CALLBACK_PATH").expect("ZAUTH_CALLBACK_PATH not present"));
const FRONTEND_URL: LazyLock<String> =
static FRONTEND_URL: LazyLock<String> =
LazyLock::new(|| env::var("FRONTEND_URL").expect("FRONTEND_URL not present"));
const ZAUTH_CLIENT_ID: LazyLock<String> =
static ZAUTH_CLIENT_ID: LazyLock<String> =
LazyLock::new(|| env::var("ZAUTH_CLIENT_ID").expect("ZAUTH_CLIENT_ID not present"));
const ZAUTH_CLIENT_SECRET: LazyLock<String> =
static ZAUTH_CLIENT_SECRET: LazyLock<String> =
LazyLock::new(|| env::var("ZAUTH_CLIENT_SECRET").expect("ZAUTH_CLIENT_SECRET not present"));

pub async fn current_user(session: Session) -> ResponseResult<Json<Model>> {
Expand Down Expand Up @@ -98,7 +98,7 @@ pub async fn callback(
let zauth_url = ZAUTH_URL.to_string();
// get token from zauth with code
let token = client
.post(&format!("{zauth_url}/oauth/token"))
.post(format!("{zauth_url}/oauth/token"))
.basic_auth(
ZAUTH_CLIENT_ID.to_string(),
Some(ZAUTH_CLIENT_SECRET.to_string()),
Expand Down
4 changes: 2 additions & 2 deletions vingo/src/routes/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct Version {
version: String,
}
pub async fn version() -> Json<Version> {
return Json(Version {
Json(Version {
version: env!("CARGO_PKG_VERSION").to_string(),
});
})
}
2 changes: 1 addition & 1 deletion vingo/src/routes/leaderboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn get(
let position_change = leaderboard_last_week
.iter()
.find(|v| v.id == user.id)
.and_then(|v| Some(v.position - user.position));
.map(|v| v.position - user.position);
user.position_change = position_change;
}

Expand Down
2 changes: 1 addition & 1 deletion vingo/src/routes/scans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::util::{
session::{get_season, get_user},
};

const SCAN_KEY: LazyLock<String> =
static SCAN_KEY: LazyLock<String> =
LazyLock::new(|| env::var("SCAN_KEY").expect("SCAN_KEY not present"));

pub async fn get_for_current_user(
Expand Down
4 changes: 2 additions & 2 deletions vingo/src/routes/seasons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub async fn get_all(state: State<AppState>) -> ResponseResult<Json<Vec<SeasonGe
}

pub async fn db_seasons(db: &DatabaseConnection, future: bool) -> ResponseResult<Vec<SeasonGet>> {
Ok(Season::find()
Season::find()
.column_as(
Expr::col(season::Column::Start)
.lte(Expr::current_date())
Expand All @@ -50,7 +50,7 @@ pub async fn db_seasons(db: &DatabaseConnection, future: bool) -> ResponseResult
.into_model::<SeasonGet>()
.all(db)
.await
.or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to get seasons"))?)
.or_log((StatusCode::INTERNAL_SERVER_ERROR, "failed to get seasons"))
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
18 changes: 0 additions & 18 deletions vinvoor/.eslintrc.cjs

This file was deleted.

4 changes: 0 additions & 4 deletions vinvoor/.prettierrc

This file was deleted.

42 changes: 19 additions & 23 deletions vinvoor/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import { includeIgnoreFile } from "@eslint/compat";
import eslint from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";
import path, { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import tseslint from "typescript-eslint";
import antfu from "@antfu/eslint-config";

const __dirname = dirname(fileURLToPath(import.meta.url));
const gitignorePath = path.resolve(__dirname, ".gitignore");

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
includeIgnoreFile(gitignorePath),
export default antfu(
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: __dirname,
},
stylistic: {
quotes: "double",
semi: true,
},

react: true,

typescript: {
tsconfigPath: "./tsconfig.json",
},

formatters: true,

rules: {
"react-hooks/exhaustive-deps": "off",
"ts/switch-exhaustiveness-check": "off",
"ts/strict-boolean-expressions": "off",
},
},
{
ignores: ["eslint.config.mjs", ".eslintrc.cjs"],
},
eslintConfigPrettier,
);
27 changes: 13 additions & 14 deletions vinvoor/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"name": "vinvoor",
"private": true,
"version": "0.0.0",
"type": "module",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "vite",
"host": "vite --host",
"build": "tsc && vite build",
"format": "prettier . --write",
"lint": "eslint . --fix",
"preview": "vite preview"
"lint": "eslint . && tsc --noEmit",
"lint:fix": "eslint . --fix",
"typecheck": "tsc --noEmit",
"preview": "vite preview",
"precommit:lint": "eslint .",
"precommit:typecheck": "tsc --noEmit"
},
"dependencies": {
"@emotion/react": "^11.13.3",
Expand All @@ -18,7 +21,7 @@
"@mui/icons-material": "^5.16.7",
"@mui/material": "^5.16.7",
"@mui/x-date-pickers": "^7.22.2",
"@tanstack/react-query": "^5.60.5",
"@tanstack/react-query": "^5.60.6",
"@types/js-cookie": "^3.0.6",
"@types/react-router-dom": "^5.3.3",
"@types/react-router-hash-link": "^2.4.9",
Expand All @@ -36,20 +39,16 @@
"react-tooltip": "^5.28.0"
},
"devDependencies": {
"@eslint/compat": "^1.2.3",
"@eslint/js": "^9.15.0",
"@types/eslint__js": "^8.42.3",
"@antfu/eslint-config": "^3.9.2",
"@eslint-react/eslint-plugin": "^1.16.1",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vitejs/plugin-react-swc": "^3.7.1",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-format": "^0.1.2",
"eslint-plugin-react-hooks": "5.1.0-beta-26f2496093-20240514",
"eslint-plugin-react-refresh": "^0.4.14",
"prettier": "3.3.3",
"typescript": "^5.6.3",
"typescript-eslint": "^8.15.0",
"vite": "^5.4.11",
Expand Down
Loading
Loading