ci(gitlabci): add easy-coding-standard check for code-style + fix quality scripts

This commit is contained in:
Yassine Doghri 2021-05-20 11:02:08 +00:00
parent aa1612342e
commit 6802bee0db
No known key found for this signature in database
GPG Key ID: 3E7F89498B960C9F
8 changed files with 59 additions and 51 deletions

View File

@ -13,74 +13,62 @@ cache:
before_script:
- apt-get update -y
# Install git (the php image doesn't have it) which is required by composer
# Install git which is required by composer (the php image doesn't have it)
- apt-get install git -y
- apt-get install -y libicu-dev
# Install intl PHP extension
# Install intl PHP extension for tests
- docker-php-ext-install intl
# install rsync for file transfers
- apt-get install rsync -y
# install wget to download archives
- apt-get install wget
# Install composer
- apt-get install zip unzip
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php
- php -r "unlink('composer-setup.php');"
# Install NodeJS for NPM
- curl -sL https://deb.nodesource.com/setup_12.x | bash -
- curl -sL https://deb.nodesource.com/setup_lts.x | bash -
- apt-get update && apt-get install -y nodejs
# Install all php and js dependencies
# Install all php dependencies
- php composer.phar install --prefer-dist --no-ansi --no-interaction --no-progress --ignore-platform-reqs
- npm install
tests:
stage: quality
script:
- composer test
# run phpunit without code coverage
# TODO: add code coverage
- vendor/bin/phpunit --no-coverage
analysis:
code-style:
stage: quality
script:
# run phpstan
- composer analyse
- vendor/bin/ecs check --ansi
static-analysis:
stage: quality
script:
- vendor/bin/phpstan analyse --ansi
code-review:
stage: quality
script:
- composer rector
- vendor/bin/rector process --dry-run --ansi
bundle_app:
stage: bundle
script:
# delete installed git hooks because captainhooks (dev dependency) will be removed
- rm -rf ./.git/hooks
# make scripts/bundle.sh executable
- chmod +x ./scripts/bundle-prepare.sh
- chmod +x ./scripts/bundle.sh
# remove dev dependencies using the --no-dev option
- php composer.phar install --no-dev --prefer-dist --no-ansi --no-interaction --no-progress --ignore-platform-reqs
# build all UI assets
- npm run build
# download GeoLite2-City archive and extract it to writable/uploads
- wget -c "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=$MAXMIND_LICENCE_KEY&suffix=tar.gz" -O - | tar -xz -C ./writable/uploads/
# rename extracted archives' folders
- mv ./writable/uploads/GeoLite2-City* ./writable/uploads/GeoLite2-City
# create bundle folder: uses .rsync-filter (-F) file to copy only needed files
- rsync -aF --progress . ./castopod-host
# bundle castopod-host with commit ref as version
- ./scripts/bundle-prepare.sh
- ./scripts/bundle.sh ${CI_COMMIT_REF_SLUG}_${CI_COMMIT_SHORT_SHA}
artifacts:
name: "castopod-host-${CI_COMMIT_REF_SLUG}_${CI_COMMIT_SHORT_SHA}"
paths:
- castopod-host
- castopod-host-${CI_COMMIT_REF_SLUG}_${CI_COMMIT_SHORT_SHA}
except:
- main
- beta
@ -89,12 +77,13 @@ bundle_app:
release_app:
stage: release
script:
# install required packages for prepare-release.sh script
- apt-get install jq -y
- apt-get install zip -y
# make release scripts executable
- chmod +x ./scripts/bundle-prepare.sh
- chmod +x ./scripts/bundle.sh
- chmod +x ./scripts/package.sh
# make scripts/prepare-release.sh executable
- chmod +x ./scripts/prepare-release.sh
# prepare bundle before release, both bundle and package scripts will be run by semantic-release
- ./scripts/bundle-prepare.sh
# IMPORTANT: delete local git tags before release to prevent eventual script failure (ie. tag already exists)
- git tag | xargs git tag -d

View File

@ -11,7 +11,7 @@
[
"@semantic-release/exec",
{
"prepareCmd": "./scripts/prepare-release.sh ${nextRelease.version}"
"prepareCmd": "./scripts/bundle.sh ${nextRelease.version} && ./scripts/package.sh"
}
],
"@semantic-release/npm",

View File

@ -7,7 +7,7 @@
FROM php:8.0-fpm
LABEL maintainer="Yassine Doghri<yassine@podlibre.org>"
LABEL maintainer="Yassine Doghri <yassine@doghri.fr>"
COPY . /castopod-host
WORKDIR /castopod-host
@ -38,7 +38,7 @@ RUN apt-get update && apt-get install -y \
&& docker-php-ext-install intl
RUN docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install gd
&& docker-php-ext-install gd
RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \

View File

@ -17,7 +17,7 @@
'class' => 'form-input mb-4',
'value' => old(
'hostname',
host_url( === null) ? config('App')->baseURL : host_url(),
host_url() === null ? config('App')->baseURL : host_url(),
),
'required' => 'required',
]) ?>

View File

@ -1,11 +1,8 @@
<?php
use CodeIgniter\Pager\PagerRenderer;
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*
* @var PagerRenderer $pager
*/
$pager->setSurroundCount(2);

12
scripts/bundle-prepare.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
# delete possibly installed git hooks because captainhooks (dev dependency)
# isn't included in the production dependencies
rm -rf ./.git/hooks
# install only dev dependencies using the --no-dev option
php composer.phar install --no-dev --prefer-dist --no-ansi --no-interaction --no-progress --ignore-platform-reqs
# install js dependencies and build all production UI assets
npm install
npm run build

View File

@ -4,20 +4,23 @@ VERSION=$1
COMPOSER_VERSION=$(echo "$VERSION" | perl -pe 's/(?<=[alpha|beta])\.//g')
# replace composer.json version using jq
apt-get install jq -y
echo "$( jq '.version = "'$COMPOSER_VERSION'"' composer.json )" > composer.json
# replace CP_VERSION constant in app/config/constants
sed -i "s/^defined('CP_VERSION').*/defined('CP_VERSION') || define('CP_VERSION', '$VERSION');/" ./app/Config/Constants.php
# install wget to download archives
apt-get install wget
# download GeoLite2-City archive and extract it to writable/uploads
wget -c "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=$MAXMIND_LICENCE_KEY&suffix=tar.gz" -O - | tar -xz -C ./writable/uploads/
# rename extracted archives' folders
mv ./writable/uploads/GeoLite2-City* ./writable/uploads/GeoLite2-City
# install rsync for file transfers
apt-get install rsync -y
# create castopo-host folder bundle: uses .rsync-filter (-F) file to copy only needed files
rsync -aF --progress . ./castopod-host
# create zip and tar.gz packages for release upload
zip -r castopod-host-$VERSION.zip castopod-host
tar -zcvf castopod-host-$VERSION.tar.gz castopod-host

7
scripts/package.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
apt-get install zip -y
# create zip and tar.gz packages for release upload
zip -r castopod-host-$VERSION.zip castopod-host
tar -zcvf castopod-host-$VERSION.tar.gz castopod-host