Skip to content

Commit b55d2c1

Browse files
Merge pull request appwrite#3316 from appwrite/ci-introduce-linter
ci: introduce linter
2 parents e1d005b + 24ed82c commit b55d2c1

File tree

8 files changed

+1035
-2239
lines changed

8 files changed

+1035
-2239
lines changed

.github/workflows/linter.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: "Linter"
2+
3+
on: [pull_request]
4+
jobs:
5+
tests:
6+
name: Linter
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v2
12+
with:
13+
# We must fetch at least the immediate parents so that if this is
14+
# a pull request then we can checkout the head.
15+
fetch-depth: 2
16+
17+
# If this run was triggered by a pull request event, then checkout
18+
# the head of the pull request instead of the merge commit.
19+
- run: git checkout HEAD^2
20+
if: ${{ github.event_name == 'pull_request' }}
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: '8.0'
26+
27+
- name: Install dependencies
28+
uses: php-actions/composer@v6
29+
with:
30+
php_version: '8.0'
31+
args: --profile --ignore-platform-reqs
32+
33+
- name: Run Linter
34+
run: ./vendor/bin/phpcs -p || true

CONTRIBUTING.md

Lines changed: 101 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ Help us keep Appwrite open and inclusive. Please read and follow our [Code of Co
1212

1313
## Submit a Pull Request 🚀
1414

15-
Branch naming convention is as following
15+
Branch naming convention is as following
1616

1717
`TYPE-ISSUE_ID-DESCRIPTION`
1818

1919
example:
20+
2021
```
2122
doc-548-submit-a-pull-request-section-to-contribution-guide
2223
```
@@ -29,32 +30,55 @@ When `TYPE` can be:
2930
- **fix** - a bug fix
3031
- **refactor** - code change that neither fixes a bug nor adds a feature
3132

32-
**All PRs must include a commit message with the changes description!**
33+
**All PRs must include a commit message with the changes description!**
3334

3435
For the initial start, fork the project and use git clone command to download the repository to your computer. A standard procedure for working on an issue would be to:
3536

3637
1. `git pull`, before creating a new branch, pull the changes from upstream. Your master needs to be up to date.
38+
3739
```
3840
$ git pull
3941
```
42+
4043
2. Create new branch from `master` like: `doc-548-submit-a-pull-request-section-to-contribution-guide`<br/>
44+
4145
```
4246
$ git checkout -b [name_of_your_new_branch]
4347
```
48+
4449
3. Work - commit - repeat ( be sure to be in your branch )
4550

46-
4. Push changes to GitHub
51+
4. Before you push your changes, make sure your code follows the `PSR12` coding standards , which is the standard Appwrite follows currently. You can easily do this by running the formatter.
52+
53+
```bash
54+
./vendor/bin/phpcbf <your file path>
55+
```
56+
57+
Now, go a step further by running the linter by the following command to manually fix the issues the formatter wasn't able to fix.
58+
59+
```bash
60+
./vendor/bin/phpcs <your file path>
61+
```
62+
63+
This will give you a list of errors for you to rectify , if there is an instance you need more information on the errors being displayed you can pass in additional command line arguments. More list of available arguments can be found [here](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage). A very useful command line argument is `--report=diff`. This will give you the expected changes by the linter for easy fixing of formatting issues.
64+
65+
```bash
66+
./vendor/bin/phpcs --report=diff <your file path>
67+
```
68+
69+
5. Push changes to GitHub
70+
4771
```
4872
$ git push origin [name_of_your_new_branch]
4973
```
5074

51-
5. Submit your changes for review
52-
If you go to your repository on GitHub, you'll see a `Compare & pull request` button. Click on that button.
53-
6. Start a Pull Request
54-
Now submit the pull request and click on `Create pull request`.
55-
7. Get a code review approval/reject
56-
8. After approval, merge your PR
57-
9. GitHub will automatically delete the branch after the merge is done. (they can still be restored).
75+
6. Submit your changes for review
76+
If you go to your repository on GitHub, you'll see a `Compare & pull request` button. Click on that button.
77+
7. Start a Pull Request
78+
Now submit the pull request and click on `Create pull request`.
79+
8. Get a code review approval/reject
80+
9. After approval, merge your PR
81+
10. GitHub will automatically delete the branch after the merge is done. (they can still be restored).
5882

5983
## Setup From Source
6084

@@ -90,18 +114,20 @@ Appwrite uses an internal micro-framework called Litespeed.js to build simple UI
90114

91115
After finishing the installation process, you can start writing and editing code.
92116

93-
94117
#### Advanced Topics
118+
95119
We love to create issues that are good for beginners and label them as `good first issue` or `hacktoberfest`, but some more advanced topics might require extra knowledge. Below is a list of links you can use to learn more about some of the more advance topics that will help you master the Appwrite codebase.
96120

97121
##### Tools and Libs
122+
98123
- [Docker](https://www.docker.com/get-started)
99-
- [PHP FIG](https://www.php-fig.org/) - [PSR-1](https://www.php-fig.org/psr/psr-1/) and [PSR-4](https://www.php-fig.org/psr/psr-4/)
124+
- [PHP FIG](https://www.php-fig.org/) - [PSR-12](https://www.php-fig.org/psr/psr-12/)
100125
- [PHP Swoole](https://www.swoole.co.uk/)
101126

102127
Learn more at our [Technology Stack](#technology-stack) section.
103128

104129
##### Network and Protocols
130+
105131
- [OSI Model](https://en.wikipedia.org/wiki/OSI_model)
106132
- [TCP vs UDP](https://www.guru99.com/tcp-vs-udp-understanding-the-difference.html#:~:text=TCP%20is%20a%20connection%2Doriented,speed%20of%20UDP%20is%20faster&text=TCP%20does%20error%20checking%20and,but%20it%20discards%20erroneous%20packets.)
107133
- [HTTP](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol)
@@ -110,10 +136,12 @@ Learn more at our [Technology Stack](#technology-stack) section.
110136
- [gRPC](https://en.wikipedia.org/wiki/GRPC)
111137

112138
##### Architecture
139+
113140
- [Microservices vs Monolithic](https://www.mulesoft.com/resources/api/microservices-vs-monolithic#:~:text=Microservices%20architecture%20vs%20monolithic%20architecture&text=A%20monolithic%20application%20is%20built%20as%20a%20single%20unit.&text=To%20make%20any%20alterations%20to,formally%20with%20business%2Doriented%20APIs.)
114141
- [MVVM](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel) - Appwrite console architecture
115142

116143
##### Security
144+
117145
- [Appwrite Auth and ACL](https://github.com/appwrite/appwrite/blob/0.7.x/docs/specs/authentication.drawio.svg)
118146
- [OAuth](https://en.wikipedia.org/wiki/OAuth)
119147
- [Encryption](https://medium.com/searchencrypt/what-is-encryption-how-does-it-work-e8f20e340537#:~:text=Encryption%20is%20a%20process%20that,%2C%20or%20decrypt%2C%20the%20information.)
@@ -124,8 +152,8 @@ Learn more at our [Technology Stack](#technology-stack) section.
124152
Appwrite's current structure is a combination of both [Monolithic](https://en.wikipedia.org/wiki/Monolithic_application) and [Microservice](https://en.wikipedia.org/wiki/Microservices) architectures, but our final goal, as we grow, is to be using only microservices.
125153

126154
---
127-
![Appwrite](docs/specs/overview.drawio.svg)
128-
---
155+
156+
## ![Appwrite](docs/specs/overview.drawio.svg)
129157

130158
### File Structure
131159

@@ -204,15 +232,15 @@ Appwrite stack is combined from a variety of open-source technologies and tools.
204232

205233
### Other Technologies
206234

207-
* Redis - for managing cache and in-memory data (currently, we do not use Redis for persistent data)
208-
* MariaDB - for database storage and queries
209-
* InfluxDB - for managing stats and time-series based data
210-
* Statsd - for sending data over UDP protocol (using Telegraf)
211-
* ClamAV - for validating and scanning storage files
212-
* Imagemagick - for manipulating and managing image media files.
213-
* Webp - for better compression of images on supporting clients
214-
* SMTP - for sending email messages and alerts
215-
* Resque - for managing data queues and scheduled tasks over a Redis server
235+
- Redis - for managing cache and in-memory data (currently, we do not use Redis for persistent data)
236+
- MariaDB - for database storage and queries
237+
- InfluxDB - for managing stats and time-series based data
238+
- Statsd - for sending data over UDP protocol (using Telegraf)
239+
- ClamAV - for validating and scanning storage files
240+
- Imagemagick - for manipulating and managing image media files.
241+
- Webp - for better compression of images on supporting clients
242+
- SMTP - for sending email messages and alerts
243+
- Resque - for managing data queues and scheduled tasks over a Redis server
216244

217245
## Package Managers
218246

@@ -224,7 +252,7 @@ Appwrite uses [PHP's Composer](https://getcomposer.org/) for managing dependenci
224252

225253
## Coding Standards
226254

227-
Appwrite is following the [PHP-FIG standards](https://www.php-fig.org/). Currently, we are using both PSR-0 and PSR-4 for coding standards and autoloading standards. Soon we will also review the project for support with PSR-12 (Extended Coding Style).
255+
Appwrite is following the [PHP-FIG standards](https://www.php-fig.org/). Currently, we are using both PSR-0 and PSR-12 for coding standards and autoloading standards.
228256

229257
We use prettier for our JS coding standards and auto-formatting our code.
230258

@@ -236,14 +264,14 @@ We wish Appwrite will be as easy to set up and in a single, localhost, and easy
236264

237265
When contributing code, please take into account the following considerations:
238266

239-
* Response Time
240-
* Throughput
241-
* Requests per Seconds
242-
* Network Usage
243-
* Memory Usage
244-
* Browser Rendering
245-
* Background Jobs
246-
* Task Execution Time
267+
- Response Time
268+
- Throughput
269+
- Requests per Seconds
270+
- Network Usage
271+
- Memory Usage
272+
- Browser Rendering
273+
- Background Jobs
274+
- Task Execution Time
247275

248276
## Security & Privacy
249277

@@ -280,6 +308,7 @@ Before running the command, make sure you have proper write permissions to the A
280308
```bash
281309
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x -t appwrite/appwrite:dev --push .
282310
```
311+
283312
**Build Functions Runtimes**
284313

285314
The Runtimes for all supported cloud functions (multicore builds) can be found at the [open-runtimes/open-runtimes](https://github.com/open-runtimes/open-runtimes) repository.
@@ -299,11 +328,11 @@ For generating a new console SDK follow the next steps:
299328

300329
Things to remember when releasing SDKs
301330

302-
* Update the Changelogs in **docs/sdks** (right now only Dart and Flutter are using these)
303-
* Update **GETTING_STARTED.md** in **docs/sdks** for each SDKs if any changes in the related APIs in there
304-
* Update SDK versions as required on **app/config/platforms.php**
305-
* Generate SDKs using the command `php app/cli.php sdks` and follow the instructions
306-
* Release new tags on GitHub repository for each SDKs
331+
- Update the Changelogs in **docs/sdks** (right now only Dart and Flutter are using these)
332+
- Update **GETTING_STARTED.md** in **docs/sdks** for each SDKs if any changes in the related APIs in there
333+
- Update SDK versions as required on **app/config/platforms.php**
334+
- Generate SDKs using the command `php app/cli.php sdks` and follow the instructions
335+
- Release new tags on GitHub repository for each SDKs
307336

308337
## Debug
309338

@@ -315,13 +344,13 @@ First, you need to create an init file. Duplicate **dev/yasd_init.php.stub** fil
315344

316345
```json
317346
{
318-
"name": "Listen for Xdebug",
319-
"type": "php",
320-
"request": "launch",
321-
"port": 9005,
322-
"pathMappings": {
323-
"/usr/src/code": "${workspaceRoot}"
324-
},
347+
"name": "Listen for Xdebug",
348+
"type": "php",
349+
"request": "launch",
350+
"port": 9005,
351+
"pathMappings": {
352+
"/usr/src/code": "${workspaceRoot}"
353+
}
325354
}
326355
```
327356

@@ -354,65 +383,62 @@ To run end-2-end tests for a spcific service use:
354383
```bash
355384
docker-compose exec appwrite test /usr/src/code/tests/e2e/Services/[ServiceName]
356385
```
386+
357387
## Benchmarking
358388

359389
You can use WRK Docker image to benchmark the server performance. Benchmarking is extremely useful when you want to compare how the server behaves before and after a change has been applied. Replace [APPWRITE_HOSTNAME_OR_IP] with your Appwrite server hostname or IP. Note that localhost is not accessible from inside the WRK container.
360390

361391
```
362-
Options:
363-
-c, --connections <N> Connections to keep open
364-
-d, --duration <T> Duration of test
365-
-t, --threads <N> Number of threads to use
366-
367-
-s, --script <S> Load Lua script file
368-
-H, --header <H> Add header to request
369-
--latency Print latency statistics
370-
--timeout <T> Socket/request timeout
371-
-v, --version Print version details
372-
```
392+
Options:
393+
-c, --connections <N> Connections to keep open
394+
-d, --duration <T> Duration of test
395+
-t, --threads <N> Number of threads to use
396+
397+
-s, --script <S> Load Lua script file
398+
-H, --header <H> Add header to request
399+
--latency Print latency statistics
400+
--timeout <T> Socket/request timeout
401+
-v, --version Print version details
402+
```
373403

374404
```bash
375405
docker run --rm skandyla/wrk -t3 -c100 -d30 https://[APPWRITE_HOSTNAME_OR_IP]
376406
```
377407

378-
## Code Maintenance
408+
## Code Maintenance
379409

380410
We use some automation tools to help us keep a healthy codebase.
381411

382-
Improve PHP execution time by using [fully-qualified function calls](https://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/):
412+
**Run Formatter:**
383413

384414
```bash
385-
php-cs-fixer fix src/ --rules=native_function_invocation --allow-risky=yes
415+
# Run on all files
416+
./vendor/bin/phpcbf
417+
# Run on single file or folder
418+
./vendor/bin/phpcbf <your file path>
386419
```
387420

388-
Coding Standards:
421+
**Run Linter:**
389422

390423
```bash
391-
php-cs-fixer fix app/controllers --rules='{"braces": {"allow_single_line_closure": true}}'
392-
```
393-
394-
```bash
395-
php-cs-fixer fix src --rules='{"braces": {"allow_single_line_closure": true}}'
396-
```
397-
398-
Static Code Analysis:
399-
400-
```bash
401-
docker-compose exec appwrite /usr/src/code/vendor/bin/psalm
424+
# Run on all files
425+
./vendor/bin/phpcs
426+
# Run on single file or folder
427+
./vendor/bin/phpcs <your file path>
402428
```
403429

404430
## Tutorials
405431

406432
From time to time, our team will add tutorials that will help contributors find their way in the Appwrite source code. Below is a list of currently available tutorials:
407433

408-
* [Adding Support for a New OAuth2 Provider](./docs/tutorials/add-oauth2-provider.md)
409-
* [Appwrite Environment Variables](./docs/tutorials/environment-variables.md)
410-
* [Running in Production](./docs/tutorials/running-in-production.md)
411-
* [Adding Storage Adapter](./docs/tutorials/add-storage-adapter.md)
434+
- [Adding Support for a New OAuth2 Provider](./docs/tutorials/add-oauth2-provider.md)
435+
- [Appwrite Environment Variables](./docs/tutorials/environment-variables.md)
436+
- [Running in Production](./docs/tutorials/running-in-production.md)
437+
- [Adding Storage Adapter](./docs/tutorials/add-storage-adapter.md)
412438

413439
## Other Ways to Help
414440

415-
Pull requests are great, but there are many other areas where you can help Appwrite.
441+
Pull requests are great, but there are many other areas where you can help Appwrite.
416442

417443
### Blogging & Speaking
418444

@@ -437,4 +463,3 @@ Submitting documentation updates, enhancements, designs, or bug fixes. Spelling
437463
### Helping Someone
438464

439465
Searching for Appwrite on Discord, GitHub, or StackOverflow and helping someone else who needs help. You can also help by teaching others how to contribute to Appwrite's repo!
440-

app/config/scopes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,3 @@
7171
'description' => 'Access to read your project\'s health status',
7272
],
7373
];
74-

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@
7575
"appwrite/sdk-generator": "0.18.8",
7676
"phpunit/phpunit": "9.5.20",
7777
"swoole/ide-helper": "4.8.9",
78-
"textalk/websocket": "1.5.7",
79-
"vimeo/psalm": "4.13.1"
78+
"textalk/websocket": "1.5.7"
8079
},
8180
"provide": {
8281
"ext-phpiredis": "*"

0 commit comments

Comments
 (0)