diff --git a/.github/workflows/deploy-to-vm.yaml b/.github/workflows/deploy-to-vm.yaml new file mode 100644 index 0000000..10aa960 --- /dev/null +++ b/.github/workflows/deploy-to-vm.yaml @@ -0,0 +1,66 @@ +# Created with assistance from GPT-5.6 Terra High + +name: CI/CD - Deploy to VM + +on: + workflow_run: + workflows: ["CI/CD - Run lint and formatting checkout"] + types: [completed] + branches: + - main + +permissions: + contents: read + +concurrency: + group: production-deploy + cancel-in-progress: false + +jobs: + deploy: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: [self-hosted] + timeout-minutes: 10 + + env: + SITE_ROOT: /var/www/html/project1 + npm_config_cache: ${{ github.workspace }}/.npm-cache + TMPDIR: ${{ github.workspace }}/.tmp + + steps: + - name: Check out source + uses: actions/checkout@v4 + with: + ref: ${{ github.event.workflow_run.head_sha }} + + - name: Install dependencies + working-directory: vær + run: | + mkdir -p "$TMPDIR" + npm ci --no-audit --no-fund + + - name: Build app + working-directory: vær + run: npm run build + + - name: Deploy app to Apache + run: | + set -euo pipefail + + test -d "$SITE_ROOT" + test -f vær/dist/index.html + + rsync -a --delete --chmod=D755,F644 \ + vær/dist/ "$SITE_ROOT/" + + - name: Clean up job files + if: always() + run: | + set -euo pipefail + + # Removes the checkout, node_modules, dist, npm cache, and TMPDIR. + # Keeps the runner's own _work directory intact. + if [ -d "$GITHUB_WORKSPACE" ]; then + find "$GITHUB_WORKSPACE" -mindepth 1 -maxdepth 1 \ + -exec rm -rf -- {} + + fi diff --git a/.github/workflows/lint-and-format.yaml b/.github/workflows/lint-and-format.yaml new file mode 100644 index 0000000..b8d2c3c --- /dev/null +++ b/.github/workflows/lint-and-format.yaml @@ -0,0 +1,37 @@ +name: CI/CD - Run lint and formatting checkout + +on: + push: + branches: + - main + pull_request: + types: + - opened + +jobs: + deploy: + runs-on: [self-hosted] + timeout-minutes: 10 + + env: + SITE_ROOT: /var/www/html/project1 + npm_config_cache: ${{ github.workspace }}/.npm-cache + TMPDIR: ${{ github.workspace }}/.tmp + + steps: + - name: Check out source + uses: actions/checkout@v4 + + - name: Install dependencies + working-directory: vær + run: | + mkdir -p "$TMPDIR" + npm ci --no-audit --no-fund + + - name: Run Prettier check + working-directory: vær + run: npx exec prettier . --check + + - name: Run ESLint + working-directory: vær + run: npm run lint diff --git a/node_modules/.bin/prettier b/node_modules/.bin/prettier deleted file mode 100755 index a5a62ae..0000000 --- a/node_modules/.bin/prettier +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") - -case `uname` in - *CYGWIN*|*MINGW*|*MSYS*) - if command -v cygpath > /dev/null 2>&1; then - basedir=`cygpath -w "$basedir"` - fi - ;; -esac - -if [ -z "$NODE_PATH" ]; then - export NODE_PATH="/home/nico/prog/it2810/T09-Project-1/node_modules/.pnpm/prettier@3.9.6/node_modules/prettier/bin/node_modules:/home/nico/prog/it2810/T09-Project-1/node_modules/.pnpm/prettier@3.9.6/node_modules/prettier/node_modules:/home/nico/prog/it2810/T09-Project-1/node_modules/.pnpm/prettier@3.9.6/node_modules:/home/nico/prog/it2810/T09-Project-1/node_modules/.pnpm/node_modules" -else - export NODE_PATH="/home/nico/prog/it2810/T09-Project-1/node_modules/.pnpm/prettier@3.9.6/node_modules/prettier/bin/node_modules:/home/nico/prog/it2810/T09-Project-1/node_modules/.pnpm/prettier@3.9.6/node_modules/prettier/node_modules:/home/nico/prog/it2810/T09-Project-1/node_modules/.pnpm/prettier@3.9.6/node_modules:/home/nico/prog/it2810/T09-Project-1/node_modules/.pnpm/node_modules:$NODE_PATH" -fi -if [ -x "$basedir/node" ]; then - exec "$basedir/node" "$basedir/../prettier/bin/prettier.cjs" "$@" -else - exec node "$basedir/../prettier/bin/prettier.cjs" "$@" -fi diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json deleted file mode 100644 index 2a741c7..0000000 --- a/node_modules/.package-lock.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "T09-Project-1", - "lockfileVersion": 3, - "requires": true, - "packages": { - "node_modules/prettier": { - "version": "3.9.6", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.6.tgz", - "integrity": "sha512-OpN0zzVdiaiAhxpuuj5efpIS4sY9j7bY6uR5mnj5yPzGkdkjNKSJeUThPb60Jw29QuAZgA4o+/iB49kFiaBX6g==", - "dev": true, - "license": "MIT", - "bin": { - "prettier": "bin/prettier.cjs" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/prettier/prettier?sponsor=1" - } - } - } -} diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 052b542..0000000 --- a/package-lock.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "T09-Project-1", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "devDependencies": { - "prettier": "3.9.6" - } - }, - "node_modules/prettier": { - "version": "3.9.6", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.6.tgz", - "integrity": "sha512-OpN0zzVdiaiAhxpuuj5efpIS4sY9j7bY6uR5mnj5yPzGkdkjNKSJeUThPb60Jw29QuAZgA4o+/iB49kFiaBX6g==", - "dev": true, - "license": "MIT", - "bin": { - "prettier": "bin/prettier.cjs" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/prettier/prettier?sponsor=1" - } - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index 8dfd824..0000000 --- a/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "devDependencies": { - "prettier": "3.9.6" - } -} diff --git "a/v\303\246r/.prettierrc" "b/v\303\246r/.prettierrc" index 544b7b4..f6ca428 100644 --- "a/v\303\246r/.prettierrc" +++ "b/v\303\246r/.prettierrc" @@ -1,3 +1,6 @@ { - -} \ No newline at end of file + "trailingComma": "es5", + "tabWidth": 2, + "semi": false, + "singleQuote": false +} diff --git "a/v\303\246r/package-lock.json" "b/v\303\246r/package-lock.json" index 3b7ca00..f28570c 100644 --- "a/v\303\246r/package-lock.json" +++ "b/v\303\246r/package-lock.json" @@ -22,6 +22,7 @@ "eslint-plugin-react-hooks": "^7.1.1", "eslint-plugin-react-refresh": "^0.5.6", "globals": "^17.12.0", + "prettier": "^3.9.7", "typescript": "~6.0.2", "typescript-eslint": "^8.69.0", "vite": "^8.3.0" @@ -2404,6 +2405,22 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.7.tgz", + "integrity": "sha512-T3mF5P7HFzZVLDQuCUNtJj6WK1pcpLMweMNUVwGb01bLNkH9AkKxtZvmInw8K6bnn2O3d6/5RHl6zSHiBAD0Og==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", diff --git "a/v\303\246r/package.json" "b/v\303\246r/package.json" index cc694f8..1782863 100644 --- "a/v\303\246r/package.json" +++ "b/v\303\246r/package.json" @@ -24,6 +24,7 @@ "eslint-plugin-react-hooks": "^7.1.1", "eslint-plugin-react-refresh": "^0.5.6", "globals": "^17.12.0", + "prettier": "^3.9.7", "typescript": "~6.0.2", "typescript-eslint": "^8.69.0", "vite": "^8.3.0" diff --git "a/v\303\246r/src/hooks/useStorage.ts" "b/v\303\246r/src/hooks/useStorage.ts" index 7ff75a1..589e460 100644 --- "a/v\303\246r/src/hooks/useStorage.ts" +++ "b/v\303\246r/src/hooks/useStorage.ts" @@ -1,4 +1,4 @@ -import { useState, useEffect, useCallback } from "react"; +import { useState, useCallback } from "react"; import { getData, saveData } from "../services/storage"; import type {AppStorage} from "../services/storage"; diff --git "a/v\303\246r/vite.config.ts" "b/v\303\246r/vite.config.ts" index 9982072..fc089ba 100644 --- "a/v\303\246r/vite.config.ts" +++ "b/v\303\246r/vite.config.ts" @@ -4,4 +4,5 @@ import { defineConfig } from 'vite' // https://vite.dev/config/ export default defineConfig({ plugins: [react()], + base: "/project1", })