From 4c79b3870198257e03435be24f23601de844d24d Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Tue, 30 Jan 2024 17:46:48 -0500 Subject: [PATCH 01/11] ci: workflow formatting stuff, and custom pre-commit hooks --- .github/workflows/CI.yml | 22 +++++++++++++--------- .pre-commit-config.yaml | 14 ++++++++++++-- client/types/declaration.d.ts | 12 ++++++------ scripts/format.sh | 2 ++ scripts/test.sh | 2 ++ 5 files changed, 35 insertions(+), 17 deletions(-) create mode 100755 scripts/format.sh create mode 100755 scripts/test.sh diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4ca54da..843f519 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,4 +1,4 @@ -name: CI (Linting, Testing, Building) +name: CI (Formatting, Testing, Building) on: push: @@ -8,7 +8,7 @@ on: jobs: lint: - name: Lint + name: Format runs-on: ubuntu-latest strategy: matrix: @@ -28,17 +28,20 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: Lint Go code - run: | - cd backend - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - golangci-lint run ./... + - name: Install Task + uses: arduino/setup-task@v1 + with: + version: 3.x + repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Format Frontend + - name: Format run: | + task build cd client - npm install npm run format + cd ../backend + go fmt + go vet test: name: Test @@ -87,6 +90,7 @@ jobs: - name: Run Go tests run: | + task build task test-all build: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5805b47..902e195 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,8 +8,18 @@ repos: - id: end-of-file-fixer exclude: 'backend/docs/' - id: trailing-whitespace - - id: no-commit-to-branch - args: ['--branch', 'main'] + - repo: local + hooks: + - id: test + language: script + name: Run Tests + entry: ./scripts/test.sh + - repo: local + hooks: + - id: format + language: script + name: Run Format + entry: ./scripts/format.sh - repo: https://github.com/commitizen-tools/commitizen rev: v3.13.0 hooks: diff --git a/client/types/declaration.d.ts b/client/types/declaration.d.ts index 9038ebf..fed8d16 100644 --- a/client/types/declaration.d.ts +++ b/client/types/declaration.d.ts @@ -1,6 +1,6 @@ -declare module "*.svg" { - import React from "react"; - import { SvgProps } from "react-native-svg"; - const content: React.FC; - export default content; - } +declare module '*.svg' { + import React from 'react'; + import { SvgProps } from 'react-native-svg'; + const content: React.FC; + export default content; +} diff --git a/scripts/format.sh b/scripts/format.sh new file mode 100755 index 0000000..9c923b4 --- /dev/null +++ b/scripts/format.sh @@ -0,0 +1,2 @@ +#!/bin/bash +task format diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..1711eee --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,2 @@ +#!/bin/bash +task test-all From cfea049e0d46aafbeb85e9a9f560cecf09e11041 Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Tue, 30 Jan 2024 17:54:20 -0500 Subject: [PATCH 02/11] ci: pls work --- Taskfile.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Taskfile.yaml b/Taskfile.yaml index 394fb79..1be3b40 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -7,7 +7,6 @@ tasks: npm install cd ../backend go mod tidy - go install . format: - | From 9135781e1b3a4576286220a73faf90b0d9f16c75 Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Tue, 30 Jan 2024 18:19:00 -0500 Subject: [PATCH 03/11] ci: remove script files for inline bash :O --- .pre-commit-config.yaml | 8 ++++---- scripts/format.sh | 2 -- scripts/test.sh | 2 -- 3 files changed, 4 insertions(+), 8 deletions(-) delete mode 100755 scripts/format.sh delete mode 100755 scripts/test.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 902e195..1ced75e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,15 +11,15 @@ repos: - repo: local hooks: - id: test - language: script + language: python name: Run Tests - entry: ./scripts/test.sh + entry: bash -c 'task test-all' - repo: local hooks: - id: format - language: script + language: python name: Run Format - entry: ./scripts/format.sh + entry: bash -c 'task format' - repo: https://github.com/commitizen-tools/commitizen rev: v3.13.0 hooks: diff --git a/scripts/format.sh b/scripts/format.sh deleted file mode 100755 index 9c923b4..0000000 --- a/scripts/format.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -task format diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100755 index 1711eee..0000000 --- a/scripts/test.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -task test-all From 632f82bd32fefde3ccc96e9b3a38a67dfc71462a Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Tue, 30 Jan 2024 22:01:40 -0500 Subject: [PATCH 04/11] ci: missing hook to stop from pushing to main --- .pre-commit-config.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1ced75e..ac025b8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,6 +8,8 @@ repos: - id: end-of-file-fixer exclude: 'backend/docs/' - id: trailing-whitespace + - id: no-commit-to-branch + args: ['--branch', 'main'] - repo: local hooks: - id: test From 9bfc61bc1c81c03a0a9e97fccf841b94a0981640 Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Wed, 31 Jan 2024 12:33:30 -0500 Subject: [PATCH 05/11] ci: pls work --- .github/workflows/CI.yml | 34 +++++++++++++++++++++------ backend/schema/files/routes.go | 2 +- backend/schema/files/transactions.go | 4 ++-- client/components/DocPickerButton.tsx | 6 ++--- client/types/file.ts | 2 +- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 843f519..544516b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,4 +1,4 @@ -name: CI (Formatting, Testing, Building) +name: CI (Formatting/Linting, Testing, Building) on: push: @@ -34,14 +34,34 @@ jobs: version: 3.x repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Format + - name: Format Frontend run: | - task build cd client - npm run format - cd ../backend - go fmt - go vet + fe_format_output=$(npm run format) + if [[ -n "$fe_format_output" ]]; then + echo "$fe_format_output" + echo "::error::Formatting issues found" + exit 1 + fi + - name: Format Backend + run: | + cd backend + be_format_output=$(go fmt ./...) + if [[ -n "$be_format_output" ]]; then + echo "$be_format_output" + echo "::error::Formatting issues found" + exit 1 + fi + be_lint_output=$(go vet) + - name: Lint Backend + run: | + cd backend + be_lint_output=$(go vet ./...) + if [[ -n "$be_lint_output" ]]; then + echo "$be_lint_output" + echo "::error::Linting issues found" + exit 1 + fi test: name: Test diff --git a/backend/schema/files/routes.go b/backend/schema/files/routes.go index 13a4cc3..bfae7aa 100644 --- a/backend/schema/files/routes.go +++ b/backend/schema/files/routes.go @@ -65,4 +65,4 @@ func (pg *PgModel) UploadFileRoute(c *gin.Context) { } c.JSON(http.StatusOK, file) -} \ No newline at end of file +} diff --git a/backend/schema/files/transactions.go b/backend/schema/files/transactions.go index a90586a..72ad0ef 100644 --- a/backend/schema/files/transactions.go +++ b/backend/schema/files/transactions.go @@ -49,7 +49,7 @@ func UploadFile(pool *pgx.Conn, file models.File, data *multipart.FileHeader, re fmt.Println(err.Error()) return err } - + uploader := s3manager.NewUploader(sess) _, err = uploader.Upload(&s3manager.UploadInput{ Bucket: aws.String(AWS_BUCKET_NAME), @@ -68,4 +68,4 @@ func UploadFile(pool *pgx.Conn, file models.File, data *multipart.FileHeader, re } return nil -} \ No newline at end of file +} diff --git a/client/components/DocPickerButton.tsx b/client/components/DocPickerButton.tsx index fc6d1cc..bc9295b 100644 --- a/client/components/DocPickerButton.tsx +++ b/client/components/DocPickerButton.tsx @@ -3,7 +3,7 @@ import { View, Button, Text } from 'react-native'; import * as DocumentPicker from 'expo-document-picker'; import { uploadFile } from '../services/file'; -export default function DocPickerButton(){ +export default function DocPickerButton() { const [pickedDocument, setPickedDocument] = useState(null); const pickDocument = async () => { @@ -18,7 +18,7 @@ export default function DocPickerButton(){ // TODO get userID and groupID const userID = 0; const groupID = 0; - await uploadFile(result.assets[0], userID, groupID) + await uploadFile(result.assets[0], userID, groupID); } } catch (err) { console.log('err', err); @@ -31,4 +31,4 @@ export default function DocPickerButton(){ {pickedDocument && Picked Document: {pickedDocument}} ); -}; \ No newline at end of file +} diff --git a/client/types/file.ts b/client/types/file.ts index 4240241..88d7b8e 100644 --- a/client/types/file.ts +++ b/client/types/file.ts @@ -6,4 +6,4 @@ export interface File { upload_date: string; file_size: number; task_id: number; -} \ No newline at end of file +} From 272a29c2fa0bd733893d340f4ac9107a0197e733 Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Wed, 31 Jan 2024 12:35:20 -0500 Subject: [PATCH 06/11] ci: fix format ci failing on fe --- .github/workflows/CI.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 544516b..32921a4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -36,6 +36,7 @@ jobs: - name: Format Frontend run: | + task build cd client fe_format_output=$(npm run format) if [[ -n "$fe_format_output" ]]; then @@ -45,6 +46,7 @@ jobs: fi - name: Format Backend run: | + task build cd backend be_format_output=$(go fmt ./...) if [[ -n "$be_format_output" ]]; then @@ -55,6 +57,7 @@ jobs: be_lint_output=$(go vet) - name: Lint Backend run: | + task build cd backend be_lint_output=$(go vet ./...) if [[ -n "$be_lint_output" ]]; then From e623dfbfd3bc951ff1a0390ae1ace88b6fefb7aa Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Wed, 31 Jan 2024 13:07:30 -0500 Subject: [PATCH 07/11] ci: an effort to fix workflow and pre-commit --- .github/workflows/CI.yml | 5 +++-- .pre-commit-config.yaml | 9 ++------- Taskfile.yaml | 2 +- cz.yaml | 8 ++++++++ 4 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 cz.yaml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 32921a4..1df020f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -38,8 +38,9 @@ jobs: run: | task build cd client - fe_format_output=$(npm run format) - if [[ -n "$fe_format_output" ]]; then + fe_format_output=$(npx prettier . --check) + if [[ "$fe_format_output" == "Checking formatting..." + "\n" + + "All matched files use Prettier code style!" ]]; then echo "$fe_format_output" echo "::error::Formatting issues found" exit 1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ac025b8..7d1da6e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,12 +10,6 @@ repos: - id: trailing-whitespace - id: no-commit-to-branch args: ['--branch', 'main'] - - repo: local - hooks: - - id: test - language: python - name: Run Tests - entry: bash -c 'task test-all' - repo: local hooks: - id: format @@ -26,4 +20,5 @@ repos: rev: v3.13.0 hooks: - id: commitizen - stages: [commit-msg] + - id: commitizen-branch + stages: [push] diff --git a/Taskfile.yaml b/Taskfile.yaml index 1be3b40..9464db8 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -47,5 +47,5 @@ tasks: pre-commit: - | - pre-commit install + pre-commit install --hook-type commit-msg --hook-type pre-push --hook-type pre-commit pre-commit run --all-files diff --git a/cz.yaml b/cz.yaml new file mode 100644 index 0000000..b823e32 --- /dev/null +++ b/cz.yaml @@ -0,0 +1,8 @@ +--- +commitizen: + major_version_zero: true + name: cz_conventional_commits + tag_format: $version + update_changelog_on_bump: true + version: 0.0.1 + version_scheme: semver From 03d21625962885f29d43ec75603806b180c5e2d4 Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Wed, 31 Jan 2024 13:24:03 -0500 Subject: [PATCH 08/11] ci: fix prettier? --- .github/workflows/CI.yml | 8 +------- client/package.json | 3 ++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 1df020f..19af49f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -38,13 +38,7 @@ jobs: run: | task build cd client - fe_format_output=$(npx prettier . --check) - if [[ "$fe_format_output" == "Checking formatting..." + "\n" + - "All matched files use Prettier code style!" ]]; then - echo "$fe_format_output" - echo "::error::Formatting issues found" - exit 1 - fi + npm run check - name: Format Backend run: | task build diff --git a/client/package.json b/client/package.json index 70dab8c..1833c88 100644 --- a/client/package.json +++ b/client/package.json @@ -8,7 +8,8 @@ "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web", - "format": "prettier --write ." + "format": "prettier --write .", + "check": "prettier --check ." }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.5.1", From 689ce3dd81273a774c0ae00905429f9e6a054613 Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Wed, 31 Jan 2024 13:28:37 -0500 Subject: [PATCH 09/11] ci: fail ci? --- .pre-commit-config.yaml | 10 ++-------- .prettierrc | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7d1da6e..784dc64 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,16 +6,10 @@ repos: - id: check-added-large-files - id: check-merge-conflict - id: end-of-file-fixer - exclude: 'backend/docs/' + exclude: "backend/docs/" - id: trailing-whitespace - id: no-commit-to-branch - args: ['--branch', 'main'] - - repo: local - hooks: - - id: format - language: python - name: Run Format - entry: bash -c 'task format' + args: ["--branch", "main"] - repo: https://github.com/commitizen-tools/commitizen rev: v3.13.0 hooks: diff --git a/.prettierrc b/.prettierrc index 77991e0..0929e22 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,7 +1,7 @@ { "semi": true, "trailingComma": "none", - "singleQuote": true, + "singleQuote": false, "printWidth": 80, "tabWidth": 2, "endOfLine": "auto", From 171e4deda5210d30655324a4b5d5db82dadc22e8 Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Wed, 31 Jan 2024 13:30:46 -0500 Subject: [PATCH 10/11] ci: now format ci should workgit add . :O --- .pre-commit-config.yaml | 6 ++++++ .prettierrc | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 784dc64..ded1a6f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,6 +10,12 @@ repos: - id: trailing-whitespace - id: no-commit-to-branch args: ["--branch", "main"] + - repo: local + hooks: + - id: format + language: python + name: Run Format + entry: bash -c 'task format' - repo: https://github.com/commitizen-tools/commitizen rev: v3.13.0 hooks: diff --git a/.prettierrc b/.prettierrc index 0929e22..77991e0 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,7 +1,7 @@ { "semi": true, "trailingComma": "none", - "singleQuote": false, + "singleQuote": true, "printWidth": 80, "tabWidth": 2, "endOfLine": "auto", From a1ea75fc7b494999cefe90ca641e3d1c4ef53aaf Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Wed, 31 Jan 2024 13:36:25 -0500 Subject: [PATCH 11/11] ci: remove extra vet --- .github/workflows/CI.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 19af49f..50c64a2 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -49,7 +49,6 @@ jobs: echo "::error::Formatting issues found" exit 1 fi - be_lint_output=$(go vet) - name: Lint Backend run: | task build