Skip to content

Commit

Permalink
Merge branch 'main' into chore/cafeteria-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasjungmann authored Mar 8, 2024
2 parents acfce6b + 1b5634e commit a64106a
Show file tree
Hide file tree
Showing 133 changed files with 6,403 additions and 8,385 deletions.
27 changes: 0 additions & 27 deletions .github/dependabot.yml

This file was deleted.

83 changes: 83 additions & 0 deletions .github/workflows/client_update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Trigger Client Update

on:
push:
branches:
- 'main'
paths:
- 'server/api/tumdev/campus_backend.proto'

workflow_dispatch:

jobs:
deploy:
runs-on: macos-latest

steps:
- name: Fetch Changes
uses: actions/checkout@v4
with:
fetch-depth: 0 # Checkout everything to get access to the tags
ref: main
repository: TUM-Dev/Campus-Backend
token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Dart
uses: dart-lang/setup-dart@v1

- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Create Needed Information
run: |
echo "LATEST_TAG=$(git describe --tags --always --abbrev=0)" >> $GITHUB_ENV
echo "REPOSITORY=TUM-Dev/Campus-Flutter" >> $GITHUB_ENV
echo "FOLDER=bin/\$REPOSITORY" >> $GITHUB_ENV
echo "BRANCH_NAME=chore/update-protos-to-\$LATEST_TAG" >> $GITHUB_ENV
- name: Clone Repository
run: git clone --depth=1 --branch=main https://runner:${{ secrets.CAMPUS_FLUTTER_TOKEN }}@github.com/${{ env.REPOSITORY }} ${{ env.FOLDER }}

- name: Update Proto Files
run: |
cd ${{ env.FOLDER }}
git checkout -b ${{ env.BRANCH_NAME }}
# Update the script files to the latest version.
dart pub global activate protoc_plugin
export PATH="$PATH:$HOME/.pub-cache/bin"
curl -o protos/tumdev/campus_backend.proto https://raw.githubusercontent.com/TUM-Dev/Campus-Backend/main/server/api/tumdev/campus_backend.proto
protoc --dart_out=grpc:lib/base/networking/apis -I./protos google/protobuf/timestamp.proto google/protobuf/empty.proto protos/tumdev/campus_backend.proto
- name: Commit Changes
id: commit
run: |
# Commit the changes and push the feature branch to origin
cd ${{ env.FOLDER }}
git add .
git commit -m "chore: update scripts to ${{ env.LATEST_TAG }}"
git push origin ${{ env.BRANCH_NAME }}
continue-on-error: true

- name: Create Pull Request
if: steps.commit.outcome == 'success'
run: |
# Store the PAT in a file that can be accessed by the
# GitHub CLI.
cd ${{ env.FOLDER }}
echo "${{ secrets.CAMPUS_FLUTTER_TOKEN }}" > token.txt
# Authorize GitHub CLI for the current repository and
# create a pull-requests containing the updates.
gh auth login --with-token < token.txt
gh pr create \
--body "" \
--title "Chore: Update Protos to ${{ env.LATEST_TAG }}" \
--head "${{ env.BRANCH_NAME }}" \
--base "main"
- name: Error Message
if: steps.commit.outcome != 'success'
run: echo "No Changes made to Proto Files!"
10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: false
- name: golangci-lint-server
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: v1.54
working-directory: server
args: --timeout=30m
- name: golangci-lint-client
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: v1.54
working-directory: client
args: --timeout=30m
- run: go install golang.org/x/tools/cmd/goimports@latest
- run: bash server/api/installBuf.bash
- name: pre-commit
uses: pre-commit/[email protected].0
- uses: ls-lint/action@v2.0.1
uses: pre-commit/[email protected].1
- uses: ls-lint/action@v2.2.2
with:
config: .ls-lint.yaml
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache-dependency-path: |
Expand Down
91 changes: 91 additions & 0 deletions .github/workflows/test_migration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Migration Test
on:
pull_request:
branches: [ main ]
concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true
jobs:
test_migrations:
runs-on: ubuntu-latest
services:
auto_mariadb:
image: bitnami/mariadb:latest
ports:
- 3306:3306
env:
MARIADB_ROOT_PASSWORD: super_secret_passw0rd
MARIADB_DATABASE: campus_db
manual_mariadb:
image: bitnami/mariadb:latest
ports:
- 3300:3306
env:
MARIADB_ROOT_PASSWORD: super_secret_passw0rd
MARIADB_DATABASE: campus_db
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache-dependency-path: |
server/go.sum
- name: run manual migrations
run: go run main.go
working-directory: ./server
env:
CI_EXIT_AFTER_MIGRATION: "true"
CI_AUTO_MIGRATION: "false"
DB_DSN: root:super_secret_passw0rd@tcp(localhost:3306)/campus_db?charset=utf8mb4&parseTime=True&loc=Local
ENVIRONMENT: dev
- name: run auto migrations
run: go run main.go
working-directory: ./server
env:
CI_EXIT_AFTER_MIGRATION: "true"
CI_AUTO_MIGRATION: "true"
DB_DSN: root:super_secret_passw0rd@tcp(localhost:3300)/campus_db?charset=utf8mb4&parseTime=True&loc=Local
ENVIRONMENT: dev
- uses: ariga/setup-atlas@master
- name: export diff the migrations
id: diff_migrations
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) &&
echo "local_to_auto<<$EOF" >> $GITHUB_OUTPUT &&
atlas schema diff --from "maria://root:super_secret_passw0rd@localhost:3306/campus_db" --to "maria://root:super_secret_passw0rd@localhost:3300/campus_db" --format '{{ sql . " " }}' >> $GITHUB_OUTPUT &&
echo "$EOF" >> $GITHUB_OUTPUT
echo "auto_to_local<<$EOF" >> $GITHUB_OUTPUT &&
atlas schema diff --from "maria://root:super_secret_passw0rd@localhost:3306/campus_db" --to "maria://root:super_secret_passw0rd@localhost:3300/campus_db" --format '{{ sql . " " }}' >> $GITHUB_OUTPUT &&
echo "$EOF" >> $GITHUB_OUTPUT
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: "${{ github.event.number }}"
body-includes: Found the following differences in the sql schema
comment-author: github-actions[bot]
- name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: "${{ github.event.number }}"
comment-id: "${{ steps.fc.outputs.comment-id }}"
body: |
:eyes: Found the following differences in the sql schema:
<details>
<summary>Needed get from <b>local</b> to <b>auto</b> migration state</summary>
```sql
${{ steps.diff_migrations.outputs.local_to_auto }}
```
</details>
<details>
<summary>Needed from <b>auto</b> to <b>local</b> migration state</summary>
```sql
${{ steps.diff_migrations.outputs.auto_to_local }}
```
</details>
edit-mode: replace
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -10,7 +10,7 @@ repos:
exclude: deployment/.*
- id: check-added-large-files
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.0
rev: v0.5.1
hooks:
- id: go-fmt
- id: go-imports
Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,13 @@ The docker compose will start the server and a mariadb instance.
The server will be available at `localhost:50051` and the mariadb instance at `localhost:3306`.
Additionally, docker creates the volume `campus-db-data` to persist the data of the mariadb instances.

### Setting up the Database
The mariadb schema can be installed by executing the following command inside the mariadb container:
```bash
mysql --user=root --password=secret_root_password campus_db < /entrypoint/schema.sql
```

### Environment Variables
The following environment variables need to be set for the server to work properly:
* [REQUIRED] `DB_NAME`: The name of the database to use.
* [REQUIRED] `DB_ROOT_PASSWORD`: The password of the root user.
* [OPTIONAL] `DB_PORT`: The port of the database server. Defaults to `3306`.
* [OPTIONAL] `SENTRY_DSN`: The Sentry [Data Source Name](https://sentry-docs-git-patch-1.sentry.dev/product/sentry-basics/dsn-explainer/) for reporting issues and crashes.
* [OPTIONAL] `OMDB_API_KEY`: The key to get more information for tu-film movies from [omdbapi](https://omdbapi.com/). See [omdbapi](https://omdbapi.com/apikey.aspx) for a key.
* **[iOS Push Notification Service [OPTIONAL]](#ios-push-notifications-service)**:
* [REQUIRED] `APNS_KEY_ID`: The key ID of the APNs key => APNs Key needs to be downloaded from the Apple Developer Portal the name of the file also contains the key ID.
* [REQUIRED] `APNS_TEAM_ID`: The team ID of the iOS app can be found in AppStoreConnect.
Expand Down
16 changes: 8 additions & 8 deletions client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ go 1.21
require (
github.com/TUM-Dev/Campus-Backend/server v0.0.0-20231009133538-1a7f37e5f27c
github.com/sirupsen/logrus v1.9.3
google.golang.org/grpc v1.58.2
google.golang.org/grpc v1.62.0
)

require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/protobuf v1.31.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)
40 changes: 20 additions & 20 deletions client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ github.com/TUM-Dev/Campus-Backend/server v0.0.0-20231009133538-1a7f37e5f27c/go.m
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE=
github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ=
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -21,26 +21,26 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb h1:XFBgcDwm7irdHTbz4Zk2h7Mh+eis4nfJEFQFYzJzuIA=
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4=
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb h1:lK0oleSc7IQsUxO3U5TjL9DWlsxpEBemh+zpB7IqhWI=
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb h1:Isk1sSH7bovx8Rti2wZK0UZF6oraBDK74uoyLEEVFN0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I=
google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 h1:KAeGQVN3M9nD0/bQXnr/ClcEMJ968gUXJQ9pwfSynuQ=
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80/go.mod h1:cc8bqMqtv9gMOr0zHg2Vzff5ULhhL2IXP4sbcn32Dro=
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 h1:Lj5rbfG876hIAYFjqiJnPHfhXbv+nzTWfm04Fg/XSVU=
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80/go.mod h1:4jWUdICTdgc3Ibxmr8nAJiiLHwQBY0UI0XZcEMaFKaA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
11 changes: 4 additions & 7 deletions client/local/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,14 @@ func storeImage(path string, i []byte) (string, error) {
}
}

out, errFile := os.Create(imgPath)
if errFile != nil {
log.WithError(errFile).Error("Unable to create the new testfile")
out, err := os.Create(imgPath)
if err != nil {
log.WithError(err).Error("Unable to create the new testfile")
}
defer func(out *os.File) {
if err := out.Close(); err != nil {
log.WithError(err).Error("File was not closed successfully")
}
}(out)
var opts jpeg.Options
opts.Quality = 100
errFile = jpeg.Encode(out, img, &opts)
return imgPath, errFile
return imgPath, jpeg.Encode(out, img, &jpeg.Options{Quality: 100})
}
Loading

0 comments on commit a64106a

Please sign in to comment.