Giter VIP home page Giter VIP logo

szepeviktor / byte-level-care Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 1.0 254 KB

Living with zero problems while developing your web application

Home Page: https://github.com/szepeviktor

License: MIT License

PHP 1.98% JavaScript 0.38% SCSS 0.05% Dockerfile 2.24% Shell 2.86% YAML 92.49%
ci continuous-delivery continuous-deployment continuous-integration github-actions tech-debt technical-debt workflow application web-application

byte-level-care's Introduction

Byte-level care

theories Tweet

Note

Currently there are 14 GitHub Actions workflows in this repository.

How to live with zero problems through Total Control.

  • Analyze service providers before you choose one
  • Monitor your service providers
  • Collaborate closely with your service providers
  • Know every piece of software on your server and its author; uninstall anything that is not needed
  • Monitor every process on your server with functional tests, not just pings
  • Run QA tools on every byte of your git repositories
  • Know your dependencies (packages) and their authors
  • Deploy 100% automatically
  • Run production environments without human intervention
  • Be conservative with software versions when upgrading

See Special infrastructure for web applications

Support my work

Please consider supporting my work if you benefit from this knowledge.

Sponsor

Thank you!


Back-end Coverage Status License PHP Version Packagist stats Latest version PHPStan enabled

CI

How to design and implement continuous integration.

You find a complete CI workflow in this repository.

  • Run in a premade container or install OS packages
  • Display environment information
  • Set access credentials
  • Version control
    • Git committer
    • Commit message
    • PR title
  • Cache OS and programming language library packages
  • Check programming language and framework version compatibility
  • Check package management configuration (validate & normalize)
  • Check outdated packages and known security vulnerabilities
  • Build code
  • Configure application
  • 0️⃣ Byte-level
    • Check execute file mode bit
    • Look for non-ASCII characters (non-English alphabets, whitespace characters, control characters)
  • 1️⃣ Syntax errors
    • Check source code for syntax errors
    • Check template files for syntax errors
  • 2️⃣ Run unit and functional tests
  • 3️⃣ Static Analysis
    • Run static analysis: PHPStan
    • Magic Number Detector
    • Copy-Paste Detector
  • 4️⃣ Coding Standards
    • Check coding style
    • Adhere to EditorConfig
  • Measure code coverage
  • Check route methods (controllers of routes)
  • Check list of distributed files
  • Check spelling: Typos
  • Custom checks and warnings
  • Display logs in CI output or upload logs as artifacts
  • Start CD by SSH-ing to own server (restrict,command in authorized_keys and DenyUsers in sshd.conf)
  • Wipe sensitive data

CD

How to design and implement continuous delivery.

  • Possible constrains:
    • successful tests
    • do not run on PR-s
    • our repo
    • specific branch
    • tag in commit message [deploy:prod]
    • deploy head commit only
    • optional manual start (GitLab manual actions)
  • Do not run as root user
  • Keep deploy configuration in a file
  • Log every output to a file, log start and finish to syslog
  • Limit execution time of time-consuming steps (timeout)
  • Optionally back up project files before starting to deploy
  • Create a bot user on the server for git access with SSH key (@companybot)
  • List changes in current project files
  • Check for maintenance mode, Turn on maintenance mode php artisan down covering static resource, page, AJAX and API requests
  • Clear caches (configuration, routes, application, template etc.)
  • Wait for to finish and disable cron jobs and background workers after clearing caches (email piped to a program)
  • Identify git repository and branch
  • Checkout by commit hash (not by branch HEAD)
  • At least lint the source code
  • Don't deploy testing packages
  • Enable production optimizations in package manager
  • Build code
  • Run database migrations
  • Turn off maintenance mode
  • Populate caches (application, OPcache, wp rewrite flush)
  • Run at least 1 basic functional or unit test (e.g. log in or display dashboard)
  • Check HTML output
  • Special sudo configuration for reloading PHP-FPM or Cachetool
  • Alert on failure
  • "Was down for X seconds"
  • Send email, Slack, Trello or Google Hangouts notification

Static analysis with PHPStan

  • Extensions
  • phpstan/phpstan-strict-rules
  • phpstan/phpstan-deprecation-rules
  • dave-liddament/sarb
  • ekino/phpstan-banned-code
  • tomasvotruba/type-coverage
  • pepakriz/phpstan-exception-rules
  • canvural/larastan-strict-rules
  • schlndh/maria-stan
  • Starred repositories

byte-level-care's People

Contributors

dependabot[bot] avatar guspan-tanadi avatar szepeviktor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

guspan-tanadi

byte-level-care's Issues

Convert reusable-integrity.yml to a shell script

#!/bin/bash

cat <<"EOF" >reusable-integrity.sh
#!/bin/bash -x
set -e
export GIT_PAGER=""
mkdir -p ./tmp
GITHUB_STEP_SUMMARY="./tmp/github-summary.md"

EOF
yq -r '."jobs".*."steps"[] | select(."run") | ."run"' reusable-integrity.yml >>reusable-integrity.sh
sed -i -e "s#\${{ inputs\.executables }}#$(yq -r '."on"."workflow_call"."inputs"."executables"."default"' reusable-integrity.yml)#g" reusable-integrity.sh
sed -i -e "s#\${{ inputs\.export-excludes }}#$(yq -r '."on"."workflow_call"."inputs"."export-excludes"."default"' reusable-integrity.yml)#g" reusable-integrity.sh
sed -i -e "s#\${{ inputs\.exported-paths }}#$(yq -r '."on"."workflow_call"."inputs"."exported-paths"."default"' reusable-integrity.yml)#g" reusable-integrity.sh
sed -i -e "s#\${{ inputs\.not-printable-ascii-paths }}#src/ tests/#g" reusable-integrity.sh
sed -i -e "s#\${{ runner\.temp }}#./tmp#g" reusable-integrity.sh
sed -i -e "s#test -f \.editorconfig#&\\neclint#g" reusable-integrity.sh
chmod +x reusable-integrity.sh

Review $this usage

git grep -n -e '\$this[^-]' --and --not -e 'new [A-Z][A-Za-z]\+(\$this)' -- app/

Declare strict types

        -
            name: "Declare strict types"
            run: |
                echo "::group::Install slevomat/coding-standard"
                composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer false
                composer require --no-scripts --dev slevomat/coding-standard
                echo "::endgroup::"
                composer exec -- phpcbf --standard=vendor/slevomat/coding-standard/SlevomatCodingStandard \
                    --sniffs=SlevomatCodingStandard.TypeHints.DeclareStrictTypes src/ \
                    || test "$?" = 1 && exit 0

https://github.com/szepeviktor/byte-level-care/blob/master/.github/workflows/back-end.yml#L96

Make Markdown tables full-width (478)

<table>
    <tr>
        <th scope="row" valign="top" align="left">Left column<br><img width="478" height="1"></th>
        <th scope="row" valign="top" align="left">
            Right column<br>
            <a href="https://github.github.com/gfm/">GFM</a><br>
            <img width="478" height="1">
        </th>
    </tr>
<table>
Left column
Right column
GFM

Add composer-installer alternative

https://github.com/ergebnis/.github/blob/main/actions/composer/install/run.sh

name: "Shared Install Dependencies"

inputs:
  dependencies:
    type: "string"
    default: "highest"
    required: true

runs:
  using: "composite"

  steps:
    - name: "Install lowest dependencies"
      if: ${{ inputs.dependencies == 'lowest' }}
      shell: "bash"
      run: "composer update --prefer-lowest --no-interaction --no-progress"

    - name: "Install highest dependencies"
      if: ${{ inputs.dependencies == 'highest' }}
      shell: "bash"
      run: "composer update --no-interaction --no-progress"

    - name: "Install locked dependencies"
      if: ${{ inputs.dependencies == 'locked' }}
      shell: "bash"
      run: |
        test -f composer.lock
        composer install --no-interaction --no-progress

    - name: "Install development dependencies"
      if: ${{ inputs.dependencies == 'development' }}
      shell: "bash"
      run: |
          composer config --no-interaction -- minimum-stability dev
          composer update --no-interaction --no-progress

Tools to test and add

Check Front Matter

        -
            name: "Remove document contents"
            run: |
                git ls-files --cached -z -- 'docs/**.md' \
                   | xargs --null --max-args=1 -- sed -i -e 'N;P;/---\n$/Q;D'
        -
            name: "Check Front Matter"
            run: |
                git ls-files --cached -z -- 'docs/**.md' \
                   | xargs --null --max-args=1 -- python -m yamllint --strict

Simple push from workflow

  commit:
    permissions:
      contents: write
    steps:
    - uses: actions/checkout@v4
    - name: Commit changes
      run: |
        if git diff --quiet; then
          echo "No changes."
          exit 0
        fi
        git config user.name "${{ github.actor }}" # or GitHub Actions
        # https://api.github.com/users/github-actions%5Bbot%5D
        git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
        git add -- files
        git commit -m "update"
        git push

Highlight Markdown blockquotes

> [!NOTE]  
> Highlights information that users should take into account, even when skimming.

> [!TIP]
> Optional information to help a user be more successful.

> [!IMPORTANT]  
> Crucial information necessary for users to succeed.

> [!WARNING]  
> Critical content demanding immediate user attention due to potential risks.

> [!CAUTION]
> Negative potential consequences of an action.

Note

Highlights information that users should take into account, even when skimming.

Tip

Optional information to help a user be more successful.

Important

Crucial information necessary for users to succeed.

Warning

Critical content demanding immediate user attention due to potential risks.

Caution

Negative potential consequences of an action.

GitHub Community

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.