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

(Added) Introduce .gitattributes for efficient package management #34

Merged
merged 3 commits into from
Mar 8, 2024

Conversation

MarjovanLier
Copy link
Owner

@MarjovanLier MarjovanLier commented Mar 8, 2024

User description

Summary

This merge request introduces a .gitattributes file to the project, aiming to streamline package management and deployment processes. By specifying files and directories that should be excluded from distribution archives, we reduce the package size for end-users and align with best practices for managing Composer packages. This change enhances the efficiency of installations using the --prefer-dist option in Composer, focusing on a leaner, more efficient delivery of the project's production environment.

Context and Background

To optimise our project's deployment and distribution process, it has become necessary to adopt strategies that minimise package size and remove unnecessary files from production environments. This improves the efficiency of deployments and secures the environment by reducing the attack surface.

Problem Description

Previously, our Composer packages included all files and directories in the repository, including tests, documentation, and configuration files for development tools. This resulted in bloated packages, increased deployment times, and potentially unnecessary exposure of development files in production environments.

Solution Description

The solution was to introduce a .gitattributes file to the repository. This file specifies which files and directories should be excluded from distribution archives created by Composer. The exclusion list includes:

  • Test directories to lighten the package for production use
  • Development-specific files (e.g., .gitignore, .github)
  • Configuration files for development tools (e.g., PHPUnit, PHPStan)

This approach aligns with industry best practices for Composer package management, ensuring that only the necessary files are included in production deployments.

List of Changes

  • chore: Add .gitattributes to exclude files from archives

Type

enhancement


Description

  • Introduced a .gitattributes file to streamline package management and deployment processes by excluding unnecessary files and directories from distribution archives.
  • The exclusions aim to reduce package size for end-users and align with best practices for managing Composer packages, enhancing the efficiency of installations using the --prefer-dist option.
  • Specific exclusions include test directories, development-specific files (e.g., .gitignore, .github), and configuration files for development tools (e.g., PHPUnit, PHPStan).

Changes walkthrough

Relevant files
Configuration changes
.gitattributes
Introduce .gitattributes for Efficient Package Management

.gitattributes

  • Introduced .gitattributes to exclude specific directories and files
    from distribution archives.
  • Exclusions include tests, docs, vendor directories, and various
    configuration and meta files.
  • +18/-0   

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Summary by CodeRabbit

    • Chores
      • Optimized archive exclusions with a new .gitattributes file for enhanced efficiency.

    - Exclude test directories, meta files, and configuration files
    - Reduce package size for end-users and simplify deployment
    - Align with best practices for managing Composer packages
    - Improve efficiency of installations using `--prefer-dist`
    
    Introduced a .gitattributes file to specify files and directories that should be excluded from distribution archives, including:
    
    - Tests, to lighten the package for production use
    - Development-specific files (.gitignore, .github, etc.)
    - Configuration files for development tools (PHPUnit, PHPStan, etc.)
    
    This change aims to reduce the package size for end-users, streamline the deployment process, and enhance the efficiency of installations using the `--prefer-dist` option in Composer. It aligns with best practices for managing Composer packages.
    @MarjovanLier MarjovanLier self-assigned this Mar 8, 2024
    Copy link

    coderabbitai bot commented Mar 8, 2024

    Walkthrough

    Walkthrough

    The recent update includes a new .gitattributes file that sets line endings to LF across the repository. This change standardizes line endings, ensuring consistency in how line breaks are handled in files, which can be particularly important when collaborating on projects across different platforms.

    Changes

    Files/Directories Updated Change Summary
    .gitattributes Line endings set to LF

    Tips

    Chat

    There are 3 ways to chat with CodeRabbit:

    • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
      • I pushed a fix in commit <commit_id>.
      • Generate unit-tests for this file.
      • Open a follow-up GitHub issue for this discussion.
    • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
      • @coderabbitai generate unit tests for this file.
      • @coderabbitai modularize this function.
    • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
      • @coderabbitai generate interesting stats about this repository and render them as a table.
      • @coderabbitai show all the console.log statements in this repository.
      • @coderabbitai read src/utils.ts and generate unit tests.
      • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

    Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

    CodeRabbit Commands (invoked as PR comments)

    • @coderabbitai pause to pause the reviews on a PR.
    • @coderabbitai resume to resume the paused reviews.
    • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
    • @coderabbitai resolve resolve all the CodeRabbit review comments.
    • @coderabbitai help to get help.

    Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

    CodeRabbit Configration File (.coderabbit.yaml)

    • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
    • The JSON schema for the configuration file is available here.
    • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

    CodeRabbit Discord Community

    Join our Discord Community to get help, request features, and share feedback.

    Copy link

    @sourcery-ai sourcery-ai bot left a comment

    Choose a reason for hiding this comment

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

    We have skipped reviewing this pull request. All of the files appear to be ones we're not sure how to review. We're working on it!

    @codiumai-pr-agent-pro codiumai-pr-agent-pro bot added the enhancement New feature or request label Mar 8, 2024
    Copy link
    Contributor

    codiumai-pr-agent-pro bot commented Mar 8, 2024

    PR Description updated to latest commit (c83c2ec)

    Copy link
    Contributor

    sweep-ai bot commented Mar 8, 2024

    Apply Sweep Rules to your PR?

    • Apply: All new business logic should have corresponding unit tests.
    • Apply: Refactor large functions to be more modular.
    • Apply: Add docstrings to all functions and file headers.

    This is an automated message generated by Sweep AI.

    Copy link
    Contributor

    Changelog updates:

    2024-03-08

    Added

    • Introduced a .gitattributes file to improve package management and deployment efficiency by excluding unnecessary files and directories from distribution archives.

    to commit the new content to the CHANGELOG.md file, please type:
    '/update_changelog --pr_update_changelog.push_changelog_changes=true'

    Copy link
    Contributor

    codiumai-pr-agent-pro bot commented Mar 8, 2024

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    Exclude composer.lock from exported archives for libraries.

    Consider adding a line to exclude composer.lock from the exported archives if your project
    is a library. This is a common practice to ensure that library consumers use their own
    composer.lock and get the latest versions of dependencies, according to their own
    project's requirements.

    .gitattributes [17-18]

     /phpmd.xml          export-ignore
     /qodana.*           export-ignore
    +/composer.lock      export-ignore
     
    Normalize text files' line endings across OSes.

    To ensure consistency and avoid potential issues with line endings across different
    operating systems, consider adding a rule for text files normalization. For example,

    text=auto will automatically normalize line endings to LF on checkin and convert them to
    CRLF when checked out on Windows.
    *

    .gitattributes [1-2]

    +* text=auto
     /tests              export-ignore
     
    Declare binary files explicitly to ensure correct Git handling.

    For projects that include binary files, it might be beneficial to explicitly declare them
    to ensure they are handled correctly during the Git operations. For instance, adding *.png
    binary can help Git understand how to treat PNG files in your repository.

    .gitattributes [1-2]

    +*.png binary
     /tests              export-ignore
     
    Enhancement
    Exclude Docker configuration files from exported archives.

    If your project includes Docker configurations or other container definitions, consider
    excluding those files (e.g., Dockerfile, .dockerignore, docker-compose.yml) from the
    exported archives. This can help keep the package lightweight, especially if these
    configurations are not needed by the end users.

    .gitattributes [17-18]

     /phpmd.xml          export-ignore
     /qodana.*           export-ignore
    +/Dockerfile         export-ignore
    +/.dockerignore      export-ignore
    +/docker-compose.yml export-ignore
     
    Performance
    Use Git LFS for large files not needed in production.

    If your project uses large files, especially those not needed in production (like design
    assets), consider using Git Large File Storage (LFS) and adding a rule here to manage
    those files. For example, *.psd filter=lfs diff=lfs merge=lfs -text would ensure Photoshop
    files are handled via LFS.

    .gitattributes [1-2]

    +*.psd filter=lfs diff=lfs merge=lfs -text
     /tests              export-ignore
     

    Copy link
    Contributor

    Auto-approved PR

    Copy link

    @coderabbitai coderabbitai bot left a comment

    Choose a reason for hiding this comment

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

    Review Status

    Actionable comments generated: 0

    Configuration used: .coderabbit.yaml

    Commits Files that changed from the base of the PR and between da78950 and c83c2ec.
    Files selected for processing (1)
    • .gitattributes (1 hunks)
    Files skipped from review due to trivial changes (1)
    • .gitattributes

    Copy link

    codecov bot commented Mar 8, 2024

    Codecov Report

    All modified and coverable lines are covered by tests ✅

    Project coverage is 98.75%. Comparing base (da78950) to head (c1f6172).

    Additional details and impacted files
    @@            Coverage Diff            @@
    ##               main      #34   +/-   ##
    =========================================
      Coverage     98.75%   98.75%           
      Complexity       26       26           
    =========================================
      Files             1        1           
      Lines            80       80           
    =========================================
      Hits             79       79           
      Misses            1        1           

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    Add '/composer.lock' to .gitattributes export-ignore. This ensures that consumers of the library use their own 'composer.lock' file and have the latest versions of dependencies based on their project's requirements.
    Configure Git to automatically convert line endings to LF on checkin and to CRLF on checkout for Windows. This ensures consistent line endings across different operating systems.
    
    Add the following rule to .gitattributes:
    
    *                   text=auto
    Copy link

    sonarcloud bot commented Mar 8, 2024

    Quality Gate Passed Quality Gate passed

    Issues
    0 New issues
    0 Accepted issues

    Measures
    0 Security Hotspots
    No data about Coverage
    No data about Duplication

    See analysis details on SonarCloud

    Copy link

    @coderabbitai coderabbitai bot left a comment

    Choose a reason for hiding this comment

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

    Review Status

    Actionable comments generated: 0

    Configuration used: .coderabbit.yaml

    Commits Files that changed from the base of the PR and between c83c2ec and c1f6172.
    Files selected for processing (1)
    • .gitattributes (1 hunks)
    Files skipped from review as they are similar to previous changes (1)
    • .gitattributes

    @MarjovanLier MarjovanLier merged commit db1fb61 into main Mar 8, 2024
    9 checks passed
    @MarjovanLier MarjovanLier deleted the Add-gitattributes branch March 8, 2024 19:44
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    enhancement New feature or request
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant