upddate actions and node versions on ci #179
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD for Symfony | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
concurrency: production_environment | |
jobs: | |
tests: | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: mariadb:10.3 | |
env: | |
MYSQL_ROOT_PASSWORD: root | |
MYSQL_DATABASE: symfony | |
ports: | |
- 3306/tcp | |
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
strategy: | |
fail-fast: true | |
matrix: | |
php-versions: ['8.1'] | |
steps: | |
# —— Setup GitHub actions 🐙 ————————————————————————————————————————————— | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup PHP, extensions and composer with shivammathur/setup-php | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php-versions }} | |
extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, dom, filter, gd, iconv, json | |
env: | |
update: true | |
- name: Start mysql service | |
run: sudo service mysql start | |
- name: Setup problem matchers for PHPUnit | |
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" | |
- name: Check PHP Version | |
run: php -v | |
# —— Composer 🧙️ ————————————————————————————————————————————————————————— | |
- name: Validate composer.json and composer.lock | |
run: composer validate -d app | |
- name: Check outdated packages | |
run: composer outdated --direct -d app | |
- name: Get composer cache directory | |
id: composer-cache | |
run: echo "::set-output name=dir::$(composer config cache-files-dir -d app)" | |
- name: Cache composer dependencies | |
uses: actions/cache@v1 | |
with: | |
path: ${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: ${{ runner.os }}-composer- | |
- name: Install Composer dependencies | |
env: | |
DATABASE_URL: mysql://root:root@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony?serverVersion=mariadb-10.5.12 | |
run: composer install --no-progress --prefer-dist --optimize-autoloader -d app | |
## —— Yarn 🐱 ———————————————————————————————————————————————————————————— | |
- name: Yarn setup | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 16 | |
- run: | | |
cd app | |
yarn install | |
- name: Yarn build | |
run: | | |
cd app | |
yarn run encore production | |
## —— PHPStan ✅ ——————————————————————————————————————————————————————————— | |
- name: Run static analysis with PHPStan | |
env: | |
DATABASE_URL: mysql://root:root@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony?serverVersion=mariadb-10.5.12 | |
run: ./app/vendor/bin/phpstan analyse -c app/phpstan.neon | |
## —— Doctrine 🐱 ———————————————————————————————————————————————————————————— | |
- name: Run Doctrine migrations and load fixtures | |
env: | |
DATABASE_URL: mysql://root:root@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony?serverVersion=mariadb-10.5.12 | |
run: | | |
cd app | |
php bin/console doctrine:schema:update --force || echo "No migration found or schema update failed" | |
php bin/console doctrine:migrations:migrate || echo "No migration found or migration failed" | |
php bin/console doctrine:fixtures:load --append -n || echo "No fixture found or fixtures load failed" | |
## —— Tests ✅ ——————————————————————————————————————————————————————————— | |
- name: Run tests | |
env: | |
APP_ENV: test | |
APP_SECRET: '' | |
DATABASE_URL: mysql://root:root@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony?serverVersion=mariadb-10.5.12 | |
run: | | |
cd app | |
php bin/phpunit -v | |
deploy: | |
name: Deploy to prod | |
runs-on: ubuntu-latest | |
needs: tests | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- run: echo "Build job was a success on main, deploying..." | |
- uses: actions/checkout@v4 | |
- name: Setup PHP and Deployer | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: 8.1 | |
tools: deployer:v7.3.0 | |
- name: Setup SSH connection | |
uses: webfactory/ssh-agent@v0.8.0 | |
with: | |
ssh-private-key: ${{ secrets.PRIVATE_KEY }} | |
- name: Deploy to Production | |
run: | | |
echo '${{ secrets.KNOWN_HOSTS }}' >> ~/.ssh/known_hosts | |
cd app | |
deployer deploy -v |