Skip to content

Commit

Permalink
feat(new-start): Refactored bundle (#1)
Browse files Browse the repository at this point in the history
* .

* .

* .

* it works propably

* readme updated

* removed secrets
  • Loading branch information
patrykbaszak authored Feb 14, 2024
1 parent c7745d9 commit e79353e
Show file tree
Hide file tree
Showing 37 changed files with 4,183 additions and 1,152 deletions.
21 changes: 19 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=local
APP_SECRET=mrUNGjJoBIWWDoHLuX9KDpYsAduxugyPtX4STBT2
APP_DEBUG=true
APP_SECRET=$ecretf0rt3st
###< symfony/framework-bundle ###
5 changes: 4 additions & 1 deletion .env.local.dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
APP_ENV=local
APP_DEBUG=true

# For debugging with xdebug and vscode
#
# XDEBUG_MODE=develop,debug
Expand All @@ -12,7 +15,7 @@
# "type": "php",
# "request": "launch",
# "port": 5902,
# "hostname": "localhost",
# "hostname": "0.0.0.0",
# "pathMappings": {
# "/app/": "${workspaceRoot}"
# }
Expand Down
6 changes: 6 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# define your env variables for the test env here
KERNEL_CLASS='PBaszak\ExtendedApiDoc\Tests\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
32 changes: 20 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
name: CI
name: Symfony Application Check

on: [push]
on: [push, pull_request]

jobs:
build-test:
runs-on: ubuntu-latest
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- uses: php-actions/composer@v6
- name: Running start.sh Script
run: bash start.sh

- name: PHPUnit Tests
uses: php-actions/phpunit@master
with:
configuration: phpunit.xml.dist
exclude_group: integration, performance
- name: Application Verification
run: docker exec php composer cache:clear

- name: Running PHPStan
run: docker exec php composer code:analyse

- name: Running PHP-CS-Fixer
run: docker exec php composer code:fix -- --dry-run --diff -vvv

- name: Running PHPUnit
run: docker exec php composer test:cc
19 changes: 9 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# directories
.vscode
node_modules
vendor
app

# files
.dockerfile_checksum
.env.local

###> symfony/framework-bundle ###
/.env.local
Expand All @@ -9,22 +18,12 @@
/vendor/
###< symfony/framework-bundle ###

/.vscode
/node_modules/
/.dockerfile_checksum

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
/.phpunit.cache/
###< phpunit/phpunit ###
86 changes: 86 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
stages:
- compile
- test
# - deploy

compile:
stage: compile
image: composer:latest
script:
- composer install
artifacts:
when: always
paths:
- vendor/
- var/cache/
expire_in: 10 minutes
only:
- merge_requests
- master
tags:
- docker

code:analyse:
stage: test
image: php:latest
script:
- vendor/bin/phpstan analyse src -c tools/phpstan/fpm-config.neon
only:
- merge_requests
- master
tags:
- docker
needs:
- job: compile
artifacts: true

code:cs-fixer:
stage: test
image: php:latest
script:
- vendor/bin/php-cs-fixer fix --dry-run --diff -vvv
only:
- merge_requests
- master
tags:
- docker
needs:
- job: compile
artifacts: true

code:test:
stage: test
image: php:latest
before_script:
- pecl install xdebug
- docker-php-ext-enable xdebug
- echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
script:
- vendor/bin/phpunit --do-not-cache-result --log-junit var/coverage/phpunit-report.xml --coverage-cobertura var/coverage/phpunit-coverage.xml --coverage-text --colors=never
only:
- merge_requests
- master
tags:
- docker
needs:
- job: compile
artifacts: true
artifacts:
when: always
reports:
junit: var/coverage/phpunit-report.xml
coverage_report:
coverage_format: cobertura
path: var/coverage/phpunit-coverage.xml
coverage: '/^\s*Lines:\s*\d+.\d+\%/'

# deploy:
# stage: deploy
# image: alpine
# script:
# - apk add curl
# - 'curl --header "Job-Token: $CI_JOB_TOKEN" --data tag=$CI_COMMIT_TAG "${CI_API_V4_URL}/projects/$CI_PROJECT_ID/packages/composer"'
# only:
# - tags
# tags:
# - docker
25 changes: 22 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,30 @@ FROM php:latest

RUN apt update \
&& apt-get update \
&& apt install -y git unzip
&& apt install -y git jq unzip

# install xdebug
## install xdebug extension
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug

# install composer
## install composer
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
RUN mkdir -p /.composer && chmod -R 777 /.composer

### Setup environment variables
COPY package.json composer.json .gi[t] /tmp/
WORKDIR /tmp
## define app version and store it in environment variable
RUN echo "APP_VERSION=$(jq -r '.version' '/tmp/package.json')" >> /etc/environment
RUN rm -rf /tmp/package.json
## define app commit sha and store it in environment variable
RUN echo "APP_COMMIT_SHA=$(git rev-parse HEAD)" >> /etc/environment
RUN echo "APP_COMMIT_SHA_SHORT=$(git rev-parse --short HEAD)" >> /etc/environment
RUN rm -rf .git
## define app name and store it in environment variable
RUN echo "APP_NAME=$(jq -r '.name' '/tmp/composer.json')" >> /etc/environment
RUN echo "APP_DESCRIPTION=\"$(jq -r '.description' '/tmp/composer.json')\"" >> /etc/environment
RUN echo "APP_TITLE=\"$(jq -r '.title' '/tmp/composer.json')\"" >> /etc/environment
RUN rm -rf /tmp/composer.json
WORKDIR /app
### End of environment variables setup
133 changes: 114 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,132 @@
# Extended Api Doc Bundle #
This package improves the Api Doc Bundle - adding the `#[QueryParameters]` attribute allows you to declare parameters in a separate class instead of in a controller, so you can use it for multiple controllers.

An extension for `nelmio/api-doc-bundle` that improves the sorting of endpoints by tags and provides minor stylistic corrections to the original Nelmio view.

## Installation

```sh

Required bundles:

```bash
composer require symfony/asset
composer require symfony/twig-bundle
composer require nelmio/api-doc-bundle
composer require pbaszak/extended-api-doc-bundle
```

Routing Registration:

- /api/doc
- /api/doc.json
- /api/doc.yaml

```yaml
# config/routes.yaml
extendend_api_doc:
resource: '@DocumentationBundle/Resources/routes/*'
...
extended_api_doc:
resource: '@ExtendedApiDocBundle/Resources/routes/*'
```
Setup metainfo:
```yaml
# config/packages/nelmio.yaml
# config/packages/nelmio_api_doc.yaml
parameters:
app_title: '%env(APP_TITLE)%'
app_description: '%env(APP_DESCRIPTION)%'
app_version: '%env(APP_VERSION)%'
app_commit_sha_short: '%env(APP_COMMIT_SHA_SHORT)%'

nelmio_api_doc:
documentation:
info:
title: API Service documentation
description: API Service description
version: '%env(APP_VERSION)%' # if You add APP_VERSION env to Your docker image in CD process
areas:
title: '%app_title%'
description: '%app_description%'
version: '%app_version% (%app_commit_sha_short%)'
areas: # to filter documented areas
path_patterns:
- ^/api(?!/doc(.json|.yaml)?$)
```
if `Symfony Security` is used:
```yaml
# config/packages/security.yaml
security:
# ...
access_control:
# ...
- { path: ^\/api\/doc(\.yaml|\.json)?$, methods: [GET], roles: PUBLIC_ACCESS }
# ...
## Usage
Just open `/api/doc` path on Your server and enjoy!

## Development

### How to start

Start local environment using this command:
```sh
bash start.sh
```

### How to use **Standard Version**

If You don't have node_modules directory run:
```sh
npm install
```

`Major`, `Minor`, `Patch` version update:
```sh
npm run version:major
# or
npm run version:minor
# or
npm run version:patch
```

Push tags:
```sh
npm run version:release
# or
npm run release
```

Check `package.json` for understand what commands do.

### How to use **PHPStan**

Main command:
```bash
docker exec php composer code:analyse
```
but, if You need to add errors to ignored:
```bash
docker exec php composer code:analyse:b
```

### How to use **PHP CS Fixer**

```bash
docker exec php composer code:fix
```

### How to use **XDebug** in **Visual Studio Code**

Create new file in Your project: `.vscode/launch.json`
```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for xDebug",
"type": "php",
"request": "launch",
"port": 5902,
"hostname": "0.0.0.0",
"pathMappings": {
"/app/": "${workspaceRoot}"
}
}
]
}
```

Uncomment environments in `.env.local`:
```env
XDEBUG_MODE=develop,debug
XDEBUG_CONFIG=" client_port=5902 idekey=VSCODE client_host=host.docker.internal discover_client_host=0 start_with_request=yes"
```

Type `Ctrl + Shift + D` and run `Listen for xDebug`.
Loading

0 comments on commit e79353e

Please sign in to comment.