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

ci: workflow formatting stuff, and custom pre-commit hooks #19

Merged
merged 12 commits into from
Jan 31, 2024
39 changes: 30 additions & 9 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI (Linting, Testing, Building)
name: CI (Formatting/Linting, Testing, Building)

on:
push:
Expand All @@ -8,7 +8,7 @@ on:

jobs:
lint:
name: Lint
name: Format
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -28,17 +28,37 @@ 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
run: |
task build
cd client
npm install
npm run format
npm run check
- name: Format Backend
run: |
task build
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
- name: Lint Backend
run: |
task build
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
Expand Down Expand Up @@ -87,6 +107,7 @@ jobs:

- name: Run Go tests
run: |
task build
task test-all

build:
Expand Down
13 changes: 10 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ 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']
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:
- id: commitizen
stages: [commit-msg]
- id: commitizen-branch
stages: [push]
3 changes: 1 addition & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ tasks:
npm install
cd ../backend
go mod tidy
go install .

format:
- |
Expand Down Expand Up @@ -48,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
2 changes: 1 addition & 1 deletion backend/schema/files/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ func (pg *PgModel) UploadFileRoute(c *gin.Context) {
}

c.JSON(http.StatusOK, file)
}
}
4 changes: 2 additions & 2 deletions backend/schema/files/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -68,4 +68,4 @@ func UploadFile(pool *pgx.Conn, file models.File, data *multipart.FileHeader, re
}

return nil
}
}
6 changes: 3 additions & 3 deletions client/components/DocPickerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | null>(null);

const pickDocument = async () => {
Expand All @@ -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);
Expand All @@ -31,4 +31,4 @@ export default function DocPickerButton(){
{pickedDocument && <Text>Picked Document: {pickedDocument}</Text>}
</View>
);
};
}
3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions client/types/declaration.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module "*.svg" {
import React from "react";
import { SvgProps } from "react-native-svg";
const content: React.FC<SvgProps>;
export default content;
}
declare module '*.svg' {
import React from 'react';
import { SvgProps } from 'react-native-svg';
const content: React.FC<SvgProps>;
export default content;
}
2 changes: 1 addition & 1 deletion client/types/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export interface File {
upload_date: string;
file_size: number;
task_id: number;
}
}
8 changes: 8 additions & 0 deletions cz.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading