hi-folks / gh-actions-yaml-generator Goto Github PK
View Code? Open in Web Editor NEWGhygen is a GitHub Actions configurator for your PHP / Laravel project.
Home Page: https://ghygen.hi-folks.dev/
Ghygen is a GitHub Actions configurator for your PHP / Laravel project.
Home Page: https://ghygen.hi-folks.dev/
Hi, great project.
Exploring the project, I think it may be a good idea to add a new composer view for the following data.
$data = [];
$data["title"] = "Ghygen is a GitHub Actions configurator for your Laravel Application.";
$data["description"] = "Setup Database Service, use multiple PHP version, use multiple Laravel versions, build frontend, cache packages, execute Browser, Functional, and Unit tests…";
Something like $view->with(compact('data'))
. Passing the data to the views configurator.index
, configurator.about
, dashboard.index
.
If you like the idea, I can make these changes to participate in the Hacktoberfest challenge.
Getting this error generating the YAML file.
Indentation problem at line 10 (near " pull_request:").
master,develop,fix/**,fixes/**,features/**
master
homestead
name: Test Laravel Github action
on:
push:
branches:
- master
- develop
- fix/**
- fixes/**
- features/**
pull_request:
branches:
- master
jobs:
laravel-tests:
runs-on: ubuntu-latest
# Service container Mysql mysql
services:
# Label used to access the service container
mysql:
# Docker Hub image (also with version)
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: homestead
## map the "external" 33306 port with the "internal" 3306
ports:
- 33306:3306
# Set health checks to wait until mysql database has started (it takes some seconds to start)
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: [ '8.0','7.4' ]
steps:
- uses: actions/checkout@v2
- name: Install PHP versions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Get Composer Cache Directory 2
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
id: actions-cache
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Cache PHP dependencies
uses: actions/cache@v2
id: vendor-cache
with:
path: vendor
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
if: steps.vendor-cache.outputs.cache-hit != 'true'
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Run Migrations
# Set environment
env:
DB_CONNECTION: mysql
DB_DATABASE: homestead
DB_PORT: 33306
DB_USER: root
run: php artisan migrate
- name: Create Database
run: |
mkdir -p database
touch database/database.sqlite
- name: Execute tests (Unit and Feature tests) via PHPUnit
# Set environment
env:
DB_CONNECTION: mysql
DB_DATABASE: homestead
DB_PORT: 33306
DB_USER: root
run: vendor/bin/phpunit --testdox
- name: Execute Code Sniffer via phpcs
run: |
composer require --dev squizlabs/php_codesniffer
vendor/bin/phpcs --standard=PSR12 app
Some input could raise some suggestions or hints. Probably they are not error.
For example: if the user want to execute browser tests, maybe it is useful to enable node and compile the frontend, or you want to run migrations only if you have a mysql service up and running in your CICD workflow.
In these cases, the Yaml file is generated but a kind of feedbacks are returned to the user.
"friendly" checks:
Cache node_modules directory instead of downloaded packages.
- name: Cache node_modules directory
uses: actions/cache@v2
id: node_modules-cache
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
- name: Install NPM packages
if: steps.node_modules-cache.outputs.cache-hit != 'true'
run: npm ci
Make "key generate" for laravel otional (think about laravel packages or php projects)
Requesting this as I'm using Laravel's Parallel testing which creates/requires multiple databases. This would likely require one of two things:
Thoughts?
As discussed briefly with my friend @AlessandroMinoccheri at PHPDay2022 event, it would be nice to add "Symfony staff". Something like "Laravel Stuff".
This is just a placeholder as a reminder.
For now, I'm going to start investigate which steps are needed and are specific for a Symfony application.
We have some options to select to execute phpstan, phpunit and phpcs.
Now if the user selects those options, it is created also the directive for installing them.
If the target application has alreasdy those tools in the composer.json and they are locked to some old version some conflicts during installation could be raised.
So : add 3 options:
Add as
Today, we have some option when to execute the workflow according to the GitHub Actions documentation: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows.
We have:
Add the option for scheduled events
In the traits BaseWorkflow, add two attributes:
Add option for deploy with forge
https://forge.laravel.com/docs/1.0/accounts/source-control.html#using-deployment-triggers
Make copy . env optional (think about Laravel Packages without .env)
So avoid to include these lines (if the user doesn't want .env file):
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
Run php artisan migrate
php artisan migrate
shell: /usr/bin/bash -e {0}
env:
DB_CONNECTION: mysql
DB_DATABASE: db_test_laravel
DB_PORT: 33306
DB_USER: root
DB_PASSWORD: DB_PASSWORD
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = db_test_laravel and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:692
688▕ // If an exception occurs when attempting to run a query, we'll format the error
689▕ // message to include the bindings with SQL, which will make this exception a
690▕ // lot more helpful to the developer instead of just the database's errors.
691▕ catch (Exception $e) {
➜ 692▕ throw new QueryException(
693▕ $query, $this->prepareBindings($bindings), $e
694▕ );
695▕ }
696▕ }
+36 vendor frames
37 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
Error: Process completed with exit code 1.
Not sure where to start with this?
With
php artisan ghygen:generate
add "--save=filename.yml" option
This option, instead of showing the YAML result in the standard output, it save it on the file defined.
If file exists, the command display a warning and stop the execution
With the option, avoid showing the YAML result in the standard output.
Perform following checks that raise errors:
Adding Psalm option in Code Quality section.
Today in "Select Code Analysis Tool" , we have:
Now we have
https://github.com/Hi-Folks/gh-actions-yaml-generator/blob/main/ghygen-github-actions-yaml-generator-laravel.png
as cover image.
Any suggestion for the new cover ?
Allow the user to select the level of the stability for the Laravel dependency:
prefer-lowest
prefer-stable
add dependency stability into matrix:
dependency-stability: [prefer-lowest, prefer-stable]
name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}}
composer update --${{ matrix.dependency-stability }}
When the user clicks on "Generate Yaml file" button:
Considerations:
$json = json_encode($array);
Add Laravel Matrix in order to use some specific version of Laravel.
Follow this great article to understand the right directive to use for use the Matrix :
https://freek.dev/1546-using-github-actions-to-run-the-tests-of-laravel-projects-and-packages
Step to implement:
laravel: [8.*, 7.* ]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 7.*
testbench: 5.*
name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.operating-system}}
- name: Install Laravel Dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-stability }} --prefer-dist --no-interaction --no-suggest
Add Laravel 9 option in the form.
File: app/Traits/Form/LaravelStuff.php
in
$this->matrixTestbenchDependencies = [
"8.*" => "6.*",
"7.*" => "5.*",
"6.*" => "4.*"
];
add version 9.* for Laravel and 7.* for Testbench orchestra dependency.
As requested in #45 "Feature Request" allow the user to select if and which database use in the workflow.
Now the current option is mysql service (yes or not).
Add a select:
Create Template for common use cases:
Hi,
I am not sure if you are looking for deployment options for this generator but I made the Ploi Deploy Action that triggers the Ploi.io webhook or API and deploys your application to the server.
Let me know if you need more information 😄
At least 1 "on events" needs to be selected.
add select for code static analysis tool to use.
With this issue allow selection between phpstan or larastan. In this way in the future we colud add also psalm.
We spoke on Twitter briefly in the week after you pointed out this generator. I was thinking it might be a cool idea if instead of needing to select things via a form that could automate a lot of the option selections using just the info from composer.json?
Detect the PHP version(s), Laravel version etc. and which PHP tools are involved and then just provide a set of appropriate actions to tick. At that point I'd probably even be happy to pay for it as a service if it saved me the time of having to work out which things I could have in my pipeline without the research.
Just a thought anyways.
In resources/templates/json/laravelpackage.json file are stored default values for Laravel Package template.
I see that in case of Laravel package usually, composer.lock file is ignored.
So, we need to change default value in resources/templates/json/laravelpackage.json,
FROM:
"stepCacheVendors": true,
"stepCachePackages": true,
TO:
"stepCacheVendors": false,
"stepCachePackages": false,
Using the latest version, tried generating a YAML file..
Error
Reference "" does not exist at line 1 (near "- *").
There was some error during validation. Take a look about your data in the form:
Reference "" does not exist at line 1 (near "- *").
Renders out this YAML file:
name: Template - Laravel application (Mysql)
on:
push:
branches:
- master
- staging
- testing
- production
- develop
- features/**
- updates/**
- update/**
- fix/**
- patch/**
pull_request:
branches:
- *
jobs:
laravel-tests:
runs-on: ubuntu-latest
# Service container Mysql mysql
services:
# Label used to access the service container
mysql:
# Docker Hub image (also with version)
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: homestead
## map the "external" 33306 port with the "internal" 3306
ports:
- 33306:3306
# Set health checks to wait until mysql database has started (it takes some seconds to start)
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: [ '8.0','7.4' ]
dependency-stability: [ prefer-stable ]
name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}}
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '15.x'
- name: Cache node_modules directory
uses: actions/cache@v2
id: node_modules-cache
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}
- name: Install NPM packages
if: steps.node_modules-cache.outputs.cache-hit != 'true'
run: npm ci
- name: Build frontend
run: npm run development
- name: Install PHP versions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Get Composer Cache Directory 2
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
id: actions-cache
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Cache PHP dependencies
uses: actions/cache@v2
id: vendor-cache
with:
path: vendor
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
if: steps.vendor-cache.outputs.cache-hit != 'true'
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Run Migrations
# Set environment
env:
DB_CONNECTION: mysql
DB_DATABASE: homestead
DB_PORT: 33306
DB_USER: root
DB_PASSWORD: secret
run: php artisan migrate
- name: Show dir
run: pwd
- name: PHP Version
run: php --version
# Code quality
- name: Execute tests (Unit and Feature tests) via PHPUnit
# Set environment
env:
DB_CONNECTION: mysql
DB_DATABASE: homestead
DB_PORT: 33306
DB_USER: root
DB_PASSWORD: secret
run: vendor/bin/phpunit --testdox
- name: Execute Code Sniffer via phpcs
run: |
composer require --dev squizlabs/php_codesniffer
vendor/bin/phpcs --standard=PSR12 app
- name: Execute Code Static Analysis (PHP Stan + Larastan)
run: |
composer require --dev nunomaduro/larastan
vendor/bin/phpstan analyse app -c ./vendor/nunomaduro/larastan/extension.neon --level=4 --no-progress
- name: Browser Test - upgrade and start Chrome Driver
run: |
composer require --dev laravel/dusk
php artisan dusk:chrome-driver --detect
./vendor/laravel/dusk/bin/chromedriver-linux > /dev/null 2>&1 &
- name: Run Dusk Tests
run: |
php artisan serve > /dev/null 2>&1 &
chmod -R 0755 vendor/laravel/dusk/bin/
php artisan migrate
php artisan dusk
# Set environment
env:
DB_CONNECTION: mysql
DB_DATABASE: homestead
DB_PORT: 33306
DB_USER: root
DB_PASSWORD: secret
In code quality section, for Psalm Code static analysis tool, add checkbox to create and upoad Sarif report
- name: Execute Code Static Analysis (PSALM)
run: |
vendor/bin/psalm --report=result.sarif
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v1
with:
# Path to SARIF file relative to the root of the repository
sarif_file: result.sarif
Now when phpcs and phpstan are executed, app/ directory is used (hardcoded).
Allow the user to change the directory (think about the laravel package where the source code is in src/ and not app/
Replace Requirements section in CONTRIBUTING.md file with:
## Open a Pull Request
In order to maintain consistency in the source code we are following PSR12 coding standard, and using PHP stan for static code analysis.
You can use the command:
make allcheck
to launch
- **[PSR-12 Coding Standard](https://www.php-fig.org/psr/psr-12/)**, under the hood is used [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer);
- **PHPstan** with [level 5](https://phpstan.org/user-guide/rule-levels)
- **Phpunit** to execute all tests from ./tests/*
I suggest to launch *make allchecks* before to commit or before to create PR.
If you want to work on a PR, I suggest you to creating a new branch starting from **develop branch**, and use it also when you will submit your new **P**ull **R**equest on the original repository.
If you want to contribute with an high quality PR, I suggest you to focus not just on the source code but also:
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
For the code quality process, we are now using:
For launching the tools, we are using Makefile.
I would like to migrate:
I want to keep Makefile for deploying processes, but for executing code quality tools, I would like to move into composer scripts.
Remember to adjust also the GitHub actions workflow (launching the tools via composer run
for consistency
Create a public Dashboard in order to show:
For Mysql service, select password:
In order to execute browser tests in the CICD workflow add a step to execute Dusk.
https://laravel.com/docs/8.x/dusk
Today we have Ploi integration for Deploy Laravel application.
Following this instructions:
https://docs.vapor.build/1.0/projects/deployments.html#deploying-from-ci
Add deploy to Vapor fuctionality:
- name: Require Vapor CLI
run: composer global require laravel/vapor-cli
- name: Deploy Environment
run: vapor deploy
env:
VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
Parameter: API token "from secret"
In command ghygen:generate , detect phpstan.neon file.
If exists, use it for phpstan execution in the workflow.
If it exists, set $stepPhpstanUseNeon as true
In Laravel Stuff section add a checkbox in order to execute migrations.
Things to do:
Now there is an option to activate and execute Phpunit in the workflow.
In the same way, add an option to allow the user to select Pest instead of Phpunit.
Add an option with phpstan selection, for using phpstan.neon instead of hardcoded value (like the level).
In file app/Traits/Form/CodeQuality.php:
in resources/views/livewire/form/code-quality.blade.php
in resources/views/yaml/code_quality.blade.php add the case
@if ($stepToolStaticAnalysis == 'phpstan')
for the
vendor/bin/phpstan analyse {{ $stepDirStaticAnalysis }} --level=4 --no-progress
in order to produce something like
- name: Execute Code Static Analysis (PHP Stan)
run: |
vendor/bin/phpstan analyse src --level=4 --no-progress
with the option "use phpstan.neon":
- name: Execute Code Static Analysis (PHP Stan)
run: |
vendor/bin/phpstan analyse -c phpstan.neon --no-progress
Upgrade the Laravel application to Laravel 9:
https://laravel.com/docs/9.x/upgrade
Upgrade to:
Using the actions https://github.com/marketplace/actions/the-php-security-checker , add a job in theGithHub Actions workflow for executing security check.
on:
push:
branches:
- main
- develop
- features/**
on:
schedule:
- cron: '30 7,17 * * *'
steps:
- uses: actions/checkout@v2
- uses: symfonycorp/security-checker-action@v2
We love the idea of the project to generate the yml file, it would be interesting to add support for other types of banks besides MySQL.
Thnks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.