Skip to content

Commit

Permalink
Merge branch 'master' into laravel10
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko authored Jul 6, 2023
2 parents 43d8f51 + 203a291 commit 26b4733
Show file tree
Hide file tree
Showing 286 changed files with 1,960 additions and 2,058 deletions.
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ APP_LOG_LEVEL=debug

# DOCS_URL=

# clockwork provides local development insights (at /__clockwork/)
# adds a slight performance overhead.
CLOCKWORK_ENABLE=true

DB_HOST=localhost
DB_DATABASE=osu
DB_USERNAME=osuweb
Expand Down Expand Up @@ -156,7 +160,7 @@ CLIENT_CHECK_VERSION=false

# SEARCH_MINIMUM_LENGTH=2

# BEATMAPS_DIFFICULTY_CACHE_SERVER_URL=http://localhost:5000
# BEATMAPS_DIFFICULTY_CACHE_SERVER_URL=http://localhost:5001
# BEATMAPSET_DISCUSSION_KUDOSU_PER_USER=10
# BEATMAPSET_GUEST_ADVANCED_SEARCH=0
# BEATMAPSET_REQUIRED_HYPE=5
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
with:
tools: composer:v2
php-version: '8.1'
coverage: none

- name: Get composer cache directory
id: composercache
Expand Down
56 changes: 15 additions & 41 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
tags:
- '*'

env:
PRODUCTION_TRACK: ${{ (github.ref_type == 'tag' && ((endsWith(github.ref_name, '-private-staging') && 'private-staging') || (!contains(github.ref_name, '-') && 'production'))) || (github.ref_type == 'branch' && github.ref_name == 'master' && 'staging') || '' }}

jobs:
push_to_registry:
runs-on: ubuntu-latest
Expand All @@ -28,7 +31,7 @@ jobs:
# on push event: tag using git sha, branch name and as latest-dev
tags: |
type=raw,value=latest,enable=${{ github.ref_type == 'tag' && !contains(github.ref_name, '-') }}
type=raw,value=latest-dev,enable=${{ github.ref_type == 'branch' }}
type=raw,value=latest-dev,enable=${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
type=raw,value=${{ github.ref_name }}
type=raw,value=${{ github.sha }},enable=${{ github.ref_type == 'branch' }}
flavor: |
Expand Down Expand Up @@ -57,16 +60,16 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

notify_pending_production_deploy:
if: ${{ github.ref_type == 'tag' }}
notify_pending_deploy:
if: ${{ github.ref_type == 'tag' && (!contains(github.ref_name, '-') || endsWith(github.ref_name, '-private-staging')) }}
runs-on: ubuntu-latest
needs:
- push_to_registry
steps:
-
name: Submit pending deployment notification
run: |
export TITLE="Pending osu-web Production Deployment: $GITHUB_REF_NAME"
export TITLE="Pending osu-web $PRODUCTION_TRACK Deployment: $GITHUB_REF_NAME"
export URL="https://github.com/ppy/osu-web/actions/runs/$GITHUB_RUN_ID"
export DESCRIPTION="Docker image was built for tag $GITHUB_REF_NAME and awaiting approval for production deployment:
[View Workflow Run]($URL)"
Expand All @@ -92,42 +95,12 @@ jobs:
-d "$BODY" \
"${{ secrets.DISCORD_INFRA_WEBHOOK_URL }}"
push_to_production:
if: ${{ github.ref_type == 'tag' }}
runs-on: ubuntu-latest
needs:
- push_to_registry
environment: production
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.KUBERNETES_CONFIG_REPO_ACCESS_TOKEN }}
repository: ppy/osu-kubernetes-config
event-type: osu-web-deploy
client-payload: '{ "dockerTag": "${{ github.ref_name }}" }'
-
name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ppy
SENTRY_PROJECT: osu-web
SENTRY_URL: https://sentry.ppy.sh/
with:
environment: production
version: osu-web@${{ github.ref_name }}

push_to_staging:
if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
trigger_deploy:
if: ${{ (github.ref_type == 'tag' && (!contains(github.ref_name, '-') || endsWith(github.ref_name, '-private-staging'))) || (github.ref_type == 'branch' && github.ref_name == 'master') }}
runs-on: ubuntu-latest
needs:
- push_to_registry
environment: staging
environment: ${{ (github.ref_type == 'tag' && ((endsWith(github.ref_name, '-private-staging') && 'private-staging') || (!contains(github.ref_name, '-') && 'production'))) || 'staging' }}
steps:
-
name: Checkout
Expand All @@ -138,8 +111,9 @@ jobs:
with:
token: ${{ secrets.KUBERNETES_CONFIG_REPO_ACCESS_TOKEN }}
repository: ppy/osu-kubernetes-config
event-type: dev-ppy-sh-deploy
client-payload: '{ "values": { "image": { "tag": "${{ github.sha }}" } } }'
event-type: ${{ env.PRODUCTION_TRACK == 'staging' && 'dev-ppy-sh-deploy' || 'osu-web-deploy' }}
client-payload: |-
${{ env.PRODUCTION_TRACK == 'staging' && format('{{ "values": {{ "image": {{ "tag": "{0}" }} }} }}', github.sha) || format('{{ "dockerTag": "{0}", "productionTrack": "{1}" }}', github.ref_name, env.PRODUCTION_TRACK) }}
-
name: Create Sentry release
uses: getsentry/action-release@v1
Expand All @@ -149,5 +123,5 @@ jobs:
SENTRY_PROJECT: osu-web
SENTRY_URL: https://sentry.ppy.sh/
with:
environment: staging
version: osu-web@${{ github.sha }}
environment: ${{ env.PRODUCTION_TRACK }}
version: osu-web@${{ github.ref_type == 'branch' && github.sha || github.ref_type == 'tag' && github.ref_name }}
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ jobs:
extensions: redis, swoole
tools: composer:v2
php-version: ${{ matrix.php }}
coverage: none

- name: Get composer cache directory
id: composercache
Expand Down
24 changes: 12 additions & 12 deletions SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ There are a few different options to get started:
### Clone the git repository

```
$ git clone https://github.com/ppy/osu-web.git
git clone https://github.com/ppy/osu-web.git
```

### Configure .env file

```bash
# copy the example file and edit the settings, the important ones are APP_* and DB_*
$ cp .env.example .env
$ vi .env
cp .env.example .env
vi .env
```

### URL rewriting
Expand All @@ -41,14 +41,14 @@ Consult the [laravel documentation](https://laravel.com/docs/6.x/installation#we
### Initialize database

```bash
$ php artisan db:create
php artisan db:create
```

### Install packages and build assets

```bash
# will also install composer and yarn
$ ./build.sh
./build.sh
```

At this point you should be able to access the site via whatever webserver you configured.
Expand All @@ -65,7 +65,7 @@ At this point you should be able to access the site via whatever webserver you c
- Clone this repository.
- Set `GITHUB_TOKEN` environment variable (usually by `export GITHUB_TOKEN=ghs_...`).
- It'll be recorded to composer and app config so it doesn't need to be set again next time.
- Run `bin/docker_dev.sh`. Make sure the repository folder is owned by the user executing this command (must be non-root).
- Run `bin/docker_dev.sh`. Make sure the repository folder is owned by the user executing this command (must be non-root). The site will be hosted at http://localhost:8080/.
- Due to the nature of Docker (a container is killed when the command running in it finishes), the Yarn container will be run in watch mode.
- Do note that the supplied Elasticsearch container uses a high (1+ GB) amount of RAM. Ensure that your system (or virtual machine, if running on Windows/macOS) has a necessary amount of memory allocated (at least 2 GB). If you can't (or don't want to), you can comment out the relevant elasticsearch lines in `docker-compose.yml`.
- To run any of the below commands, make sure you are using the docker container: `docker compose run --rm php`.
Expand Down Expand Up @@ -217,7 +217,7 @@ p artisan tinker
In the repository directory:

```php
$ php artisan tinker
php artisan tinker
>>> (new App\Libraries\UserRegistration(["username" => "yourusername", "user_email" => "[email protected]", "password" => "yourpassword"]))->save();
```

Expand All @@ -227,25 +227,25 @@ Using Laravel's [Mix](https://laravel.com/docs/6.x/mix).

```bash
# build assets (should be done automatically if using docker)
$ yarn run development
yarn run development
```

Note that if you use the bundled docker compose setup, yarn/webpack will be already run in watch mode.

## Reset the database + seeding sample data

```
$ php artisan migrate:fresh --seed
php artisan migrate:fresh --seed
```

Run the above command to rebuild the database and seed with sample data. In order for the seeder to seed beatmaps, you must enter a valid osu! API key as the value of the `OSU_API_KEY` property in the `.env` configuration file, as the seeder obtains beatmap data from the osu! API. The key can be obtained from [the "Legacy API" section of your account settings page](https://osu.ppy.sh/home/account/edit#legacy-api).
Run the above command to rebuild the database and populate it with sample data. In order for the seeder to seed beatmaps, you must enter a valid osu! API key as the value of the `OSU_API_KEY` property in the `.env` configuration file, as the seeder obtains beatmap data from the osu! API. The key can be obtained from [the "Legacy API" section of your account settings page](https://osu.ppy.sh/home/account/edit#legacy-api).

## Continuous asset generation while developing

To continuously generate assets as you make changes to files (less, coffeescript) you can run `webpack` in `watch` mode.

```
$ yarn run watch
yarn run watch
```

## Email
Expand Down Expand Up @@ -349,7 +349,7 @@ docker compose run --rm php test js
# Documentation

```bash
$ php artisan scribe:generate
php artisan scribe:generate
```

Documentation will be generated in the `docs` folder in both html and markdown formats.
70 changes: 70 additions & 0 deletions app/Http/Controllers/EventsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Models\Event;

/**
* @group Events
*/
class EventsController extends Controller
{
public function __construct()
{
$this->middleware('require-scopes:public', ['only' => ['index']]);

parent::__construct();
}

/**
* Get Events
*
* Returns a collection of [Event](#event)s in order of creation time.
*
* ---
*
* ### Response Format
*
* Field | Type
* ------------- | ----
* cursor_string | [CursorString](#cursorstring)
* events | [Event](#event)[]
*
* @queryParam cursor_string Parameter for pagination. No-example
* @queryParam sort Sorting option. Valid values are `id_desc` (default) and `id_asc`. No-example
*
* @response {
* events: [
* {
* created_at: "2022-12-08T02:02:51+00:00",
* id: 57,
* type: "achievement",
* achievement: { ... },
* user: { ... }
* },
* ...
* ],
* cursor_string: "eyJldmVudF9pZCI6OH0"
* }
*/
public function index()
{
$params = request()->all();
$cursorHelper = Event::makeDbCursorHelper(get_string($params['sort'] ?? null));

[$events, $hasMore] = Event
::cursorSort($cursorHelper, cursor_from_params($params))
->limit(50)
->getWithHasMore();

return [
'events' => json_collection($events, 'Event'),
...cursor_for_response($cursorHelper->next($events, $hasMore)),
];
}
}
47 changes: 31 additions & 16 deletions app/Http/Controllers/FriendsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\UserRelation;
use App\Transformers\UserCompactTransformer;
use Auth;
use Exception;

class FriendsController extends Controller
{
Expand Down Expand Up @@ -73,22 +74,36 @@ public function store()
abort(422);
}

$existingRelation = $currentUser->relations()->where('zebra_id', $targetId)->first();
$updateCount = false;

if ($existingRelation === null) {
UserRelation::create([
'user_id' => $currentUser->user_id,
'zebra_id' => $targetId,
'friend' => true,
]);
$updateCount = true;
} elseif (!$existingRelation->friend) {
$existingRelation->update([
'friend' => true,
'foe' => false,
]);
$updateCount = true;
while (true) {
$existingRelation = $currentUser->relations()->where('zebra_id', $targetId)->first();
$updateCount = false;

if ($existingRelation === null) {
try {
UserRelation::create([
'user_id' => $currentUser->user_id,
'zebra_id' => $targetId,
'friend' => true,
]);
$updateCount = true;
} catch (Exception $e) {
if (is_sql_unique_exception($e)) {
// redo the loop with what should be a non-null
// $existingRelation on the next one
continue;
}

throw $e;
}
} elseif (!$existingRelation->friend) {
$existingRelation->update([
'friend' => true,
'foe' => false,
]);
$updateCount = true;
}

break;
}

if ($updateCount) {
Expand Down
Loading

0 comments on commit 26b4733

Please sign in to comment.