Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add automation, linting and improve DX #174

Draft
wants to merge 48 commits into
base: 2.x
Choose a base branch
from
Draft

Conversation

lotyp
Copy link
Member

@lotyp lotyp commented Mar 27, 2024

feat: introduce self-documenting Makefile for package development

This update introduces a self-documenting Makefile as a single entry point for developers working on the package, streamlining the development process and enhancing usability.

feat: add pre-commit with multiple hooks for code quality assurance

Pre-commit has been added to the development workflow to automatically check and fix common issues before commits are made. The included hooks are:

  • trailing-whitespace: Removes trailing whitespace.
  • end-of-file-fixer: Ensures files end with a newline.
  • check-added-large-files: Prevents large files (>600KB) from being committed.
  • fix-encoding-pragma: Adjusts files to have a proper encoding pragma.
  • commitizen: Enforces conventional commit messages.

feat: implement commitizen for conventional commits

Commitizen has been integrated to facilitate the use of conventional commits, paving the way for an automated CHANGELOG.md via googleapis/release-please.

chore: reorganize CODE_OF_CONDUCT.md to .github directory

Moving CODE_OF_CONDUCT.md to the .github directory declutters the main folder and aligns with GitHub's best practices for repository organization.

feat: streamline environment setup with .env example and Makefile

Added .env.example and integrated .env building through Makefile, leveraging Docker to expedite environment setup for developers.

feat: add .yamllint.yaml for YAML file linting

Introduced a .yamllint.yaml configuration file to lint YAML files, enhancing code quality and consistency.

feat: replace StyleCI with local wayofdev/cs-fixer-config for PHP linting

Switched from cloud-based StyleCI to a local solution using wayofdev/cs-fixer-config, a php-cs-fixer wrapper package. This allows developers to perform PHP linting locally via Makefile, reducing reliance on cloud-based CI systems.

feat: update docker-compose for enhanced development and testing

Updated docker-compose.yaml to support PHP 8.2 and various database servers directly through Makefile and in tests, enabling developers to avoid local PHP installations.

@lotyp
Copy link
Member Author

lotyp commented Mar 27, 2024

Simplified Dev Workflow with make

This PR introduces a streamlined dev workflow using the make command. Running make locally sets up dev environment in a snap:

  1. make env: Creates the .env file from .env.example.
  2. make prepare: Sets up the .build/php-cs-fixer directory for caching.
  3. make install: Runs composer install using Docker with wayofdev/php-dev:8.2-cli-alpine-latest.
  4. make hooks: Installs pre-commit git hooks for linting and commitizen.
  5. make up: Starts the Docker environment with all the necessary databases.

No more manual setup or inconsistencies across dev environments! Check out the asciicast to see make in action:

asciicast

Added make help command

This command prints available actions on this repository:

asciicast

Let's make our dev lives easier with this addition!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduced a .build directory to consolidate psalm, php-cs-fixer, and phpunit cache files into a single location. This change declutters the local development environment and enables GitHub Actions to efficiently cache the .build folder, streamlining the workflow.

.editorconfig Outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Removed duplicated settings.
  • Added .yaml extension.
  • Makefile should contain only TABS

.env.example Outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Developer now can edit .env.example using editor and then generate local .env for testing purposes. This can be done by:

  1. Editing .env.example file
  2. Executing make env command to create environment file for testing and local development purposes

.gitattributes Outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Production composer package, that is bundled by GitHub, should only contain production files, LICENCE.md, README.md and CHANGELOG.md. All other files should be considered as development-only.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved CODE_OF_CONDUCT.md to .github directory as per best-practices of github.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Introducing wayofdev/php-cs-fixer-config

This package serves as a comprehensive wrapper around php-cs-fixer, offering a standardized configuration for PHP projects. Designed to streamline coding standards across various packages, it facilitates code review and maintenance, enhancing project quality and developer experience.

Key Features:

  • Standardized Configuration: Implements a battle-tested rule set optimized for PHP, promoting code quality and maintainability.
  • Efficiency Improvements: Features optimizations that boost PHP execution speed, contributing to better performance.
  • Namespace Optimization: Refactors usage of functions within classes from local \ prefix (e.g., \strlen) to the class header, enhancing code readability and maintainability.

Example:

<?php

declare(strict_types=1);

namespace WayOfDev\Cycle\Bridge\Laravel\Console\Commands\Migrations;

use Cycle\Migrations\Config\MigrationConfig;
use Cycle\Migrations\Migrator;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;

use function array_merge;
use function call_user_func_array;

abstract class AbstractCommand extends Command
{

Enhanced Developer Flexibility:

  • Local & CI Integration: Enables developers to run linting processes locally, bypassing the need for cloud-based services like StyleCI. This flexibility supports a more efficient development workflow and integrates seamlessly with CI/CD pipelines, including GitHub Actions.
  • GitHub Actions Ready: The configuration is designed for easy integration with GitHub Actions, allowing automated code style checks in your CI/CD pipeline, ensuring code quality with every commit.

Configuration Highlights:

The configuration extends the Symfony rule set with customized overrides for a tailored coding standard. Key adjustments include:

  • Import Ordering: Specifies the order of imports (class, function, const) to maintain consistency.
  • Spacing and Alignment: Enforces specific spacing (e.g., one space for concatenation) and left alignment for PHPDoc comments.
  • Method and Class Element Ordering: Allows for a customized order of class elements, including methods and properties, without enforcing a specific sorting algorithm.
  • PHP Version-Specific Features: Adopts modern PHP syntax and features, encouraging the use of short list syntax, static lambdas, and null coalescing operators.
  • Risky Rules: Includes rules that are considered risky but are allowed to ensure forward compatibility and adherence to modern PHP standards.
  • Optimizations for PHP Native Functions: Encourages the use of namespaced PHP native functions to improve performance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've integrated the pre-commit framework into our repository to enhance code quality and efficiency. This tool runs checks locally before a pull request is made, aiming to:

  • Improve Code Quality: It automatically identifies common issues early, ensuring adherence to coding standards.
  • Save Reviewer Time: By addressing issues upfront, it reduces the need for detailed reviews on minor, easily fixable problems.
  • Streamline Development: It offers immediate feedback, helping developers align with project standards more efficiently.

The adoption of pre-commit is a strategic move to maintain high code standards while optimizing the review process.

.yamllint.yaml Outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added yamllint to our repository for YAML file validation. It ensures:

  • Quality: Checks syntax and formatting, ensuring YAML files meet our standards.
  • Efficiency: Automates common issue detection, saving time in reviews.
  • Consistency: Helps maintain uniformity across all YAML files.

This integration streamlines development by automating YAML checks, enhancing code quality and consistency.

phpunit.xml Outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tools should save cache in single .build folder, it declutters space in root directory and also allows to perform github ci cache, when running github actions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've dockerized this repository, enabling:

  • Simplicity: Run the local environment with just Docker installed, no complex setup required.
  • Compatibility: Avoids the need for installing a specific PHP version on your PC.

This change simplifies development, ensuring a consistent environment for all contributors.

composer.json Outdated
"vimeo/psalm": "^5.18"
"vimeo/psalm": "^5.23",
"roave/security-advisories": "dev-latest",
"wayofdev/cs-fixer-config": "^1.2"
},
"autoload-dev": {
"psr-4": {
"Cycle\\Database\\Tests\\": "tests/Database"
}
},
"scripts": {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate commands for local tool-chain.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added github action to automatically generate changelog PR's from developer commits.

Note
If we want to enable automatic merges, secrets.GITHUB_TOKEN should be changed to dedicated token, specially created for such purposes

psalm.xml Outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added https://github.com/psalm/psalm-plugin-phpunit plugin to support Psalm in PHPUnit

@lotyp lotyp added DX type: feature New feature. labels Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant