Skip to content

Commit

Permalink
Saab: adr template
Browse files Browse the repository at this point in the history
  • Loading branch information
trangle-tekos committed Oct 25, 2024
1 parent 78773b1 commit c700e27
Show file tree
Hide file tree
Showing 67 changed files with 13,758 additions and 1 deletion.
80 changes: 80 additions & 0 deletions .env.example.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# 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=dev
APP_SECRET=0af4e6f260c4d5b5e6529e327a785961
APP_DEFAULT_LOCALE=fr
###< symfony/framework-bundle ###

###> DB configs ###
DB_HOST={{database_host}}
DB_HOST_VERSION=mariadb-10.11.22
DB_PORT={{database_port}}
DB_USERNAME={{database_username}}
DB_PASSWORD={{database_password}}
DB_DATABASE={{database_name}}
DB_CHARSET=utf8mb4
###< DB configs ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml

DATABASE_URL="mysql://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}?serverVersion=${DB_HOST_VERSION}&charset=${DB_CHARSET}"

###< doctrine/doctrine-bundle ###

###> lexik/jwt-authentication-bundle ###
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
JWT_PASSPHRASE=
JWT_TOKEN_TTL=
###< lexik/jwt-authentication-bundle ###
XDEBUG_IDKEY=XDEBUG
XDEBUG_PORT=9003
XDEBUG_HOST=host.docker.internal
XDEBUG_TRIGGERVALUE=XDEBUG

PHP_PORT=9000

APP_NAME={{project_name}}
APP_PORT=8080
APP_DOMAIN=localhost
APP_PATH=/var/www/api
APP_TIMEZONE=UTC

UPLOADS_FOLDER_NAME=tmp

FRONT_PATH=/var/www/front
FRONT_PORT=3000
FRONT_DOMAIN=http://localhost
FRONT_RESET_PASSWORD_ROUTE=reset-password

###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
###< nelmio/cors-bundle ###

###> symfony/mailer ###
MAILER_SENDER="API"
MAILER_FROM="noreply@api-adr.com"
MAIL_HOST={{project_name}}-mail
MAIL_PORT=1025
MAILER_USERNAME=user
MAILER_PASSWORD=pass
MAILER_API_KEY=
MAILER_DSN="smtp://{MAILER_USERNAME}:{MAILER_PASSWORD}@${MAIL_HOST}:${MAIL_PORT}"
###< symfony/mailer ###
41 changes: 41 additions & 0 deletions .github/scripts/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
def read_file(file_path):
with open(file_path, 'r') as f:
content = f.readlines()
return content

def write_file(file_path, content):
with open(file_path, 'w') as f:
f.writelines(content)

def remove_comments(file_path, output_path):
lines = read_file(file_path)
filtered_lines = [line for line in lines if line.strip() and not line.strip().startswith('#')]
write_file(output_path, filtered_lines)

def replace_values_with_mapping(original_file_path, mapping_file_path):
original_content = read_file(original_file_path)
mapping_content = read_file(mapping_file_path)

mapping = {}
for line in mapping_content:
key, value = line.strip().split('=', 1)
mapping[key] = value

updated_content = []
for line in original_content:
key, value = line.strip().split('=', 1)
if key in mapping:
updated_content.append(f"{key}={mapping[key]}\n")
else:
updated_content.append(line)

write_file(original_file_path, updated_content)


original_file_path = '.env'
mapping_file_path = '.tmp.env'

remove_comments(".env.example", ".env")
replace_values_with_mapping(original_file_path, mapping_file_path)


47 changes: 47 additions & 0 deletions .github/scripts/unitest-report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import xml.etree.ElementTree as ET
import sys

xml_file_path = sys.argv[1]
output_file_path = sys.argv[2]

tree = ET.parse(xml_file_path)
root = tree.getroot()

with open(output_file_path, 'w') as output_file:
for testsuite in root.iter('testsuite'):
name = testsuite.get('name')
tests = int(testsuite.get('tests'))
assertions = int(testsuite.get('assertions'))
errors = int(testsuite.get('errors'))
warnings = int(testsuite.get('warnings'))
failures = int(testsuite.get('failures'))
skipped = int(testsuite.get('skipped'))
time = float(testsuite.get('time'))

output_file.write(f'\nTest Suite Name: {name}\n')
output_file.write(f'Total Tests: {tests}\n')
output_file.write(f'Total Assertions: {assertions}\n')
output_file.write(f'Errors: {errors}\n')
output_file.write(f'Warnings: {warnings}\n')
output_file.write(f'Failures: {failures}\n')
output_file.write(f'Skipped: {skipped}\n')
output_file.write('-' * 20)

testsuite = next(root.iter('testsuite'), None)

if testsuite:
name = testsuite.get('name')
tests = int(testsuite.get('tests'))
assertions = int(testsuite.get('assertions'))
errors = int(testsuite.get('errors'))
warnings = int(testsuite.get('warnings'))
failures = int(testsuite.get('failures'))
skipped = int(testsuite.get('skipped'))
time = float(testsuite.get('time'))

print(f'- Total Tests: {tests} \\')
print(f'Total Assertions: {assertions} \\')
print(f'Errors: {errors} \\')
print(f'Warnings: {warnings} \\')
print(f'Failures: {failures} \\')
print(f'Skipped: {skipped}')
15 changes: 15 additions & 0 deletions .github/scripts/unitest-threshold.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from bs4 import BeautifulSoup
import sys

report_file=sys.argv[1]

with open(report_file, 'r', encoding='utf-8') as file:
html_content = file.read()

report_content = BeautifulSoup(html_content, 'html.parser')

ratio = report_content.find('span', {'class': 'sr-only'})

if ratio:
value = ratio.text.split('%')[0]
print(value)
127 changes: 127 additions & 0 deletions .github/workflows/action-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Test
on:
workflow_call:
inputs:
UNIT_TEST_THRESHOLD:
required: true
type: string
secrets:
GIT_TOKEN:
required: true

jobs:
test:
runs-on: ubuntu-latest
name: Test
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set .env variables
run: |
cp .env.example .env
- name: Update auth.json
run: |
cat > auth.temp.json << EOF
{
"github-oauth": {
"github.com": "${{ secrets.GIT_TOKEN }}"
}
}
EOF
jq . auth.temp.json > auth.json
rm auth.temp.json
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install Python dependencies
run: |
pip install bs4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"

- name: Install php dependencies
uses: php-actions/composer@v6
with:
php_version: 8.2
php_extensions: gd intl bcmath curl xml zip mbstring mysqli iconv pdo_mysql
version: 2.x

- name: Run php mess detector
run: composer run-script phpmd

- name: Run php code sniffer
run: composer run-script phpcs

- name: Run php static analysis
run: composer run-script phpstan
continue-on-error: true

- name: Run php unit test
run: |
XDEBUG_MODE=coverage php bin/phpunit --coverage-html target/coverage --log-junit target/coverage/junit_report.xml
continue-on-error: true

- name: Create unitest report
if: success() || failure()
id: unitest-report
run: |
unitest_report=$(python .github/scripts/unitest-report.py target/coverage/junit_report.xml target/coverage/junit_report_convert.txt)
echo "#### Unit Test Report" >> target/coverage/unitest_summary.md
echo "$unitest_report" >> target/coverage/unitest_summary.md
echo "---" >> target/coverage/unitest_summary.md
- name: Archive code coverage results
id: artifact-upload-step
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: target
retention-days: 3

- name: Check code coverage
id: check-code-coverage
if: success() || failure()
run: |
ratio=$(python .github/scripts/unitest-threshold.py target/coverage/index.html)
comparison=$(echo "$ratio > ${{ inputs.UNIT_TEST_THRESHOLD }}" | bc -l)
echo "Current coverage: $ratio%"
echo "Coverage threshold: ${{ inputs.UNIT_TEST_THRESHOLD }}%"
echo "TEST_COVERAGE=$ratio" >> "$GITHUB_OUTPUT"
if [ "$comparison" -eq 1 ]; then
COVERAGE_STATUS=PASSED
echo "COVERAGE_STATUS=$COVERAGE_STATUS" >> "$GITHUB_OUTPUT"
else
COVERAGE_STATUS=FAILED
echo "COVERAGE_STATUS=$COVERAGE_STATUS" >> "$GITHUB_OUTPUT"
fi
coverage_report="#### Coverage Report
- Current coverage: $ratio% \\
Coverage threshold: ${{ inputs.UNIT_TEST_THRESHOLD }}% \\
Check coverage condition: **$COVERAGE_STATUS**
> **_Detail test report:_** ${{ steps.artifact-upload-step.outputs.artifact-url }}"
echo "$coverage_report" >> target/coverage/unitest_summary.md
cat target/coverage/unitest_summary.md >> $GITHUB_STEP_SUMMARY
- uses: mshick/add-pr-comment@v2
name: Add comment to Pull Request
if: github.event_name == 'pull_request'|| github.event_name == 'issue_comment'
with:
message-path: target/coverage/unitest_summary.md
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

###> symfony/framework-bundle ###
/.env
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###

###> squizlabs/php_codesniffer ###
/.phpcs-cache
/phpcs.xml
###< squizlabs/php_codesniffer ###

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###

###> phpstan/phpstan ###
phpstan.neon
###< phpstan/phpstan ###

###> lexik/jwt-authentication-bundle ###
/config/jwt/*.pem
###< lexik/jwt-authentication-bundle ###
Loading

0 comments on commit c700e27

Please sign in to comment.