From f6dfb72cdcf98917c9e076e2804a20eccd71ee6b Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 11 Dec 2024 21:24:37 +0100 Subject: [PATCH 1/6] Basic GitHub Actions workflow --- .github/workflows/build.yml | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..04c5ac2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,42 @@ +name: Test and Build the Application +on: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout the code + uses: actions/checkout@v4 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.11.1" + - name: Install dependencies + run: npm install + - name: Run tests + run: npm test + build: + runs-on: ubuntu-latest + needs: test + steps: + - name: Checkout the code + uses: actions/checkout@v4 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.11.1" + - name: Install dependencies + run: npm install + - name: Build the application + run: npm run build + - name: Upload artifacts + if: success() + uses: actions/upload-artifact@v4 + with: + name: dist-files + path: dist From bfe1864df0e84256b246b217db0705a6032a6e2b Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 11 Dec 2024 21:26:37 +0100 Subject: [PATCH 2/6] Add Caching Action for Dependencies and Update Workflow --- .github/actions/cached-deps/action.yml | 28 ++++++++++++++++++++++++++ .github/workflows/build.yml | 13 ++++++++---- .vscode/settings.json | 4 ++++ 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 .github/actions/cached-deps/action.yml diff --git a/.github/actions/cached-deps/action.yml b/.github/actions/cached-deps/action.yml new file mode 100644 index 0000000..fc14f5c --- /dev/null +++ b/.github/actions/cached-deps/action.yml @@ -0,0 +1,28 @@ +name: "Get & Cache Dependencies" +description: "Get the dependencies (via npm) and cache them for later use." +inputs: + caching: + description: "Whether to cache the dependencies or not." + required: false + default: "true" +outputs: + used-cache: + description: "Whether the cache was used or not." + value: ${{ steps.install.outputs.cache }} +runs: + using: "composite" + steps: + - name: Cache dependencies + uses: actions/cache@v4 + if: inputs.caching == 'true' + id: cache + with: + path: node_modules + key: deps-node-modules-${{ hashFiles('**/package-lock.json') }} + - name: Install dependencies + id: install + if: steps.cache.outputs.cache-hit != 'true' || inputs.caching != 'true' + shell: bash + run: | + npm ci + echo "cache='${{ inputs.caching }}'" >> $GITHUB_OUTPUT diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 04c5ac2..fa14d33 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,8 +16,10 @@ jobs: uses: actions/setup-node@v4 with: node-version: "20.11.1" - - name: Install dependencies - run: npm install + - name: Load & cache dependencies + uses: ./.github/actions/cached-deps + with: + caching: "false" - name: Run tests run: npm test build: @@ -30,8 +32,11 @@ jobs: uses: actions/setup-node@v4 with: node-version: "20.11.1" - - name: Install dependencies - run: npm install + - name: Load & cache dependencies + uses: ./.github/actions/cached-deps + id: chached-deps + - name: Output information + run: echo "Cache used? ${{ steps.chached-deps.outputs.used-cache }}" - name: Build the application run: npm run build - name: Upload artifacts diff --git a/.vscode/settings.json b/.vscode/settings.json index 08d85ce..71c165c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,10 @@ "material-icon-theme.files.associations": { ".tool-versions": "nodejs_alt" }, + "material-icon-theme.folders.associations": { + "actions": "gh-workflows", + "cached-deps": "temp" + }, "tailwindCSS.experimental.classRegex": [ ["[cC]lasses\\s*\\+?=\\s*([^;]*);", "'([^']*)'"], ["[cC]lasses\\s*\\+?=\\s*([^;]*);", "\"([^\"]*)\""], From 68f910d8e79449206bcf5ae6b5a2f936a7fa1104 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 12 Dec 2024 08:02:12 +0100 Subject: [PATCH 3/6] Mock Firebase Dependencies --- src/pages/AuthenticationPage.test.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/AuthenticationPage.test.tsx b/src/pages/AuthenticationPage.test.tsx index c8c8ee5..ac918b2 100644 --- a/src/pages/AuthenticationPage.test.tsx +++ b/src/pages/AuthenticationPage.test.tsx @@ -2,6 +2,9 @@ import { render, screen } from "@testing-library/react"; import AuthenticationPage from "./AuthenticationPage"; +vi.mock("firebase/auth"); +vi.mock("@/utils/firebase"); + test("should render the sign in form", function () { render(); expect(screen.getByRole("heading", { name: /sign in/i })).toBeInTheDocument(); From 27a7d790d4e86dfd0015c2bf19a1f6abd408acd8 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 12 Dec 2024 08:12:43 +0100 Subject: [PATCH 4/6] Add Lint and Report Job Introduce a Lint Error to Trigger the Report Job --- .github/workflows/build.yml | 22 ++++++++++++++++++++ .husky/pre-commit | 2 +- package.json | 2 +- src/components/authentication/SignUpForm.tsx | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa14d33..98663a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,6 +7,19 @@ on: branches: - main jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout the code + uses: actions/checkout@v4 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.11.1" + - name: Load & cache dependencies + uses: ./.github/actions/cached-deps + - name: Run the linter + run: npm run lint test: runs-on: ubuntu-latest steps: @@ -45,3 +58,12 @@ jobs: with: name: dist-files path: dist + report: + runs-on: ubuntu-latest + needs: [lint, build] + if: failure() + steps: + - name: Output information + run: | + echo "Something went wrong!" + echo "${{ toJson(github)}}" diff --git a/.husky/pre-commit b/.husky/pre-commit index ea4bd58..af05b91 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,3 +1,3 @@ # .husky/pre-commit -prettier $(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') --write --ignore-unknown +#prettier $(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') --write --ignore-unknown git update-index --again diff --git a/package.json b/package.json index 4a6c974..f4d1701 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "tsc -b && vite build", "test": "vitest", "format": "prettier --write .", - "lint": "eslint .", + "lint": "eslint . --max-warnings=0", "preview": "vite preview", "prepare": "husky" }, diff --git a/src/components/authentication/SignUpForm.tsx b/src/components/authentication/SignUpForm.tsx index ae750b8..d45b8b2 100644 --- a/src/components/authentication/SignUpForm.tsx +++ b/src/components/authentication/SignUpForm.tsx @@ -25,7 +25,7 @@ export default function SignUpForm() { } async function handleSubmit(event: FormEvent) { - event.preventDefault(); + event.preventDefault() if (formFields.password !== formFields.confirmPassword) { return alert("Passwords do not match"); From 0815dc8bd9e2d945ce4c621e1efd47e8c0fd6d37 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 12 Dec 2024 08:34:35 +0100 Subject: [PATCH 5/6] Update Caching Action and Linting Configuration --- .github/actions/cached-deps/action.yml | 10 ++++++---- .github/workflows/build.yml | 2 +- .husky/pre-commit | 2 +- package.json | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/actions/cached-deps/action.yml b/.github/actions/cached-deps/action.yml index fc14f5c..6f3c9da 100644 --- a/.github/actions/cached-deps/action.yml +++ b/.github/actions/cached-deps/action.yml @@ -8,7 +8,7 @@ inputs: outputs: used-cache: description: "Whether the cache was used or not." - value: ${{ steps.install.outputs.cache }} + value: ${{ steps.set-output.outputs.used-cache }} runs: using: "composite" steps: @@ -23,6 +23,8 @@ runs: id: install if: steps.cache.outputs.cache-hit != 'true' || inputs.caching != 'true' shell: bash - run: | - npm ci - echo "cache='${{ inputs.caching }}'" >> $GITHUB_OUTPUT + run: npm ci + - name: Set output + id: set-output + shell: bash + run: echo "used-cache='${{ steps.cache.outputs.cache-hit }}'" >> $GITHUB_OUTPUT diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 98663a0..a32f72d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: - name: Load & cache dependencies uses: ./.github/actions/cached-deps - name: Run the linter - run: npm run lint + run: npm run lint -- --max-warnings=0 test: runs-on: ubuntu-latest steps: diff --git a/.husky/pre-commit b/.husky/pre-commit index af05b91..ea4bd58 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,3 +1,3 @@ # .husky/pre-commit -#prettier $(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') --write --ignore-unknown +prettier $(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') --write --ignore-unknown git update-index --again diff --git a/package.json b/package.json index f4d1701..4a6c974 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "tsc -b && vite build", "test": "vitest", "format": "prettier --write .", - "lint": "eslint . --max-warnings=0", + "lint": "eslint .", "preview": "vite preview", "prepare": "husky" }, From a738d4ff8b5d31484daad4b5943f0986d707db6d Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 14 Dec 2024 13:04:51 +0100 Subject: [PATCH 6/6] Cleanup --- .github/workflows/build.yml | 4 ---- src/components/authentication/SignUpForm.tsx | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a32f72d..6086d2d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,8 +31,6 @@ jobs: node-version: "20.11.1" - name: Load & cache dependencies uses: ./.github/actions/cached-deps - with: - caching: "false" - name: Run tests run: npm test build: @@ -48,8 +46,6 @@ jobs: - name: Load & cache dependencies uses: ./.github/actions/cached-deps id: chached-deps - - name: Output information - run: echo "Cache used? ${{ steps.chached-deps.outputs.used-cache }}" - name: Build the application run: npm run build - name: Upload artifacts diff --git a/src/components/authentication/SignUpForm.tsx b/src/components/authentication/SignUpForm.tsx index d45b8b2..ae750b8 100644 --- a/src/components/authentication/SignUpForm.tsx +++ b/src/components/authentication/SignUpForm.tsx @@ -25,7 +25,7 @@ export default function SignUpForm() { } async function handleSubmit(event: FormEvent) { - event.preventDefault() + event.preventDefault(); if (formFields.password !== formFields.confirmPassword) { return alert("Passwords do not match");