diff --git a/.editorconfig b/.editorconfig index 50dc6257..55de6f89 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,3 +16,6 @@ end_of_line = crlf [*.md] trim_trailing_whitespace = false + +[Makefile] +indent_style = tab diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..148f1607 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# https://docs.docker.com/compose/reference/envvars/#compose_project_name +# With custom namespace provided, it will be used to prefix all services +# in Docker network for current project +COMPOSE_PROJECT_NAME=trap + +XDEBUG_MODE=coverage diff --git a/.gitattributes b/.gitattributes index 009223be..81cbf861 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,12 +1,19 @@ * text=auto -/.github export-ignore -/tests export-ignore -/.* export-ignore -/phpunit.xml* export-ignore -/phpstan.* export-ignore -/psalm.* export-ignore -/infection.* export-ignore -/codecov.* export-ignore +.github export-ignore +.phive export-ignore +tests export-ignore +.* export-ignore +box.json.dist export-ignore +composer.lock export-ignore +docker-compose.yaml export-ignore +Makefile export-ignore +phpunit.xml* export-ignore +phpstan.* export-ignore +psalm.* export-ignore +psalm-baseline.xml export-ignore +infection.* export-ignore +codecov.* export-ignore *.http binary +*.gpg binary diff --git a/.github/.commitlint.config.mjs b/.github/.commitlint.config.mjs new file mode 100644 index 00000000..8b68c159 --- /dev/null +++ b/.github/.commitlint.config.mjs @@ -0,0 +1,45 @@ +// More info: https://github.com/wayofdev/npm-shareable-configs/blob/master/packages/commitlint-config/src/index.js +const automaticCommitPattern = /^chore\(release\):.*\[skip ci]/ + +export default { + extends: ['@commitlint/config-conventional'], + /* + This resolves a linting conflict between commitlint's body-max-line-length + due to @semantic-release/git putting release notes in the commit body + https://github.com/semantic-release/git/issues/331 + */ + ignores: [(commitMessage) => automaticCommitPattern.test(commitMessage)], + rules: { + 'body-leading-blank': [1, 'always'], + 'body-max-line-length': [2, 'always', 120], + 'footer-leading-blank': [1, 'always'], + 'footer-max-line-length': [2, 'always', 120], + 'header-max-length': [2, 'always', 100], + 'scope-case': [2, 'always', 'lower-case'], + 'subject-case': [2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case']], + 'subject-empty': [2, 'never'], + 'subject-full-stop': [2, 'never', '.'], + 'type-case': [2, 'always', 'lower-case'], + 'type-empty': [2, 'never'], + 'type-enum': [ + 2, + 'always', + [ + 'feat', // New feature + 'fix', // Bug fix + 'perf', // Performance improvement + 'docs', // Documentation changes + 'style', // Code style update (formatting, missing semi colons, etc) + 'deps', // Dependency updates + 'refactor', // Code refactoring + 'ci', // Continuous integration changes + 'test', // Adding missing tests + 'tests', // Adding missing tests + 'revert', // Revert to a previous commit + 'build', // Changes that affect the build system + 'chore', // Other changes that don't modify src or test files + 'security', // Security improvements + ], + ], + }, +} diff --git a/.github/.cz.config.js b/.github/.cz.config.js new file mode 100644 index 00000000..5f951c6c --- /dev/null +++ b/.github/.cz.config.js @@ -0,0 +1,65 @@ +// @see https://cz-git.qbb.sh/config/#configure-template +module.exports = { + alias: { fd: 'docs: fix typos' }, + messages: { + type: 'Select the type of change that you\'re committing:', + scope: 'Denote the SCOPE of this change (optional):', + customScope: 'Denote the SCOPE of this change:', + subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n', + body: 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n', + breaking: 'List any BREAKING CHANGES (optional). Use "|" to break new line:\n', + footerPrefixesSelect: 'Select the ISSUES type of changeList by this change (optional):', + customFooterPrefix: 'Input ISSUES prefix:', + footer: 'List any ISSUES by this change. E.g.: #31, #34:\n', + generatingByAI: 'Generating your AI commit subject...', + generatedSelectByAI: 'Select suitable subject by AI generated:', + confirmCommit: 'Are you sure you want to proceed with the commit above?' + }, + types: [ + { value: 'feat', name: 'feat: A new feature', emoji: ':sparkles:' }, + { value: 'fix', name: 'fix: A bug fix', emoji: ':bug:' }, + { value: 'perf', name: 'perf: A code change that improves performance', emoji: ':zap:' }, + { value: 'docs', name: 'docs: Documentation only changes', emoji: ':memo:' }, + { value: 'style', name: 'style: Changes that do not affect the meaning of the code', emoji: ':lipstick:' }, + { value: 'deps', name: 'deps: A dependency update', emoji: ':package:' }, + { value: 'refactor', name: 'refactor: A code change that neither fixes a bug nor adds a feature', emoji: ':recycle:' }, + { value: 'ci', name: 'ci: Changes to our CI configuration files and scripts', emoji: ':ferris_wheel:' }, + { value: 'test', name: 'test: Adding missing tests or correcting existing tests', emoji: ':white_check_mark:' }, + { value: 'revert', name: 'revert: Reverts a previous commit', emoji: ':rewind:' }, + { value: 'build', name: 'build: Changes that affect the build system or external dependencies', emoji: ':package:' }, + { value: 'chore', name: 'chore: Other changes that don\'t modify src or test files', emoji: ':hammer:' }, + { value: 'security', name: 'security: A code change that fixes a security issue', emoji: ':lock:' } + ], + useEmoji: false, + emojiAlign: 'center', + useAI: false, + aiNumber: 1, + themeColorCode: '', + scopes: [], + allowCustomScopes: true, + allowEmptyScopes: true, + customScopesAlign: 'bottom', + customScopesAlias: 'custom', + emptyScopesAlias: 'empty', + upperCaseSubject: false, + markBreakingChangeMode: false, + allowBreakingChanges: ['feat', 'fix'], + breaklineNumber: 100, + breaklineChar: '|', + skipQuestions: [], + issuePrefixes: [{ value: 'closed', name: 'closed: ISSUES has been processed' }], + customIssuePrefixAlign: 'top', + emptyIssuePrefixAlias: 'skip', + customIssuePrefixAlias: 'custom', + allowCustomIssuePrefix: true, + allowEmptyIssuePrefix: true, + confirmColorize: true, + maxHeaderLength: Infinity, + maxSubjectLength: Infinity, + minSubjectLength: 0, + scopeOverrides: undefined, + defaultBody: '', + defaultIssues: '', + defaultScope: '', + defaultSubject: '' +} diff --git a/.github/.release-please-config.json b/.github/.release-please-config.json new file mode 100644 index 00000000..afcbefa3 --- /dev/null +++ b/.github/.release-please-config.json @@ -0,0 +1,77 @@ +{ + "release-type": "php", + "packages": { + ".": { + "package-name": "trap", + "changelog-path": "/CHANGELOG.md" + } + }, + "include-component-in-tag": false, + "changelog-sections": [ + { + "type": "feat", + "section": "Features", + "hidden": false + }, + { + "type": "fix", + "section": "Bug Fixes", + "hidden": false + }, + { + "type": "perf", + "section": "Performance Improvements", + "hidden": false + }, + { + "type": "docs", + "section": "Documentation", + "hidden": false + }, + { + "type": "deps", + "section": "Dependencies", + "hidden": false + }, + { + "type": "refactor", + "section": "Code Refactoring", + "hidden": false + }, + { + "type": "test", + "section": "Tests", + "hidden": true + }, + { + "type": "tests", + "section": "Tests", + "hidden": true + }, + { + "type": "build", + "section": "Build System", + "hidden": true + }, + { + "type": "ci", + "section": "Continuous Integration", + "hidden": true + }, + { + "type": "chore", + "section": "Miscellaneous", + "hidden": true + }, + { + "type": "style", + "section": "Styles", + "hidden": true + }, + { + "type": "revert", + "section": "Reverts", + "hidden": true + } + ] +} diff --git a/.github/.yamllint.yaml b/.github/.yamllint.yaml new file mode 100644 index 00000000..40909417 --- /dev/null +++ b/.github/.yamllint.yaml @@ -0,0 +1,56 @@ +--- + +extends: default + +ignore: | + .build/ + vendor/ + bin/ + +rules: + braces: + # Defaults + # min-spaces-inside: 0 + # max-spaces-inside: 0 + + # Keep 0 min-spaces to not error on empty {} collection definitions + min-spaces-inside: 0 + + # Allow one space inside braces to improve code readability + max-spaces-inside: 1 + + brackets: + # Defaults + # min-spaces-inside: 0 + # max-spaces-inside: 0 + + # Keep 0 min-spaces to not error on empty [] collection definitions + min-spaces-inside: 0 + + # Allow one space inside braces to improve code readability + max-spaces-inside: 1 + + colons: + # Defaults + # min-spaces-before: 0 + # max-spaces-after: 1 + + # Allow multiple spaces after a colon to allow indentation of YAML + # dictionary values + max-spaces-after: -1 + + commas: + # Defaults + # max-spaces-after: 1 + + # Allow multiple spaces after a comma to allow indentation of YAML + # dictionary values + max-spaces-after: -1 + + comments: + require-starting-space: true + min-spaces-from-content: 1 + + line-length: disable + +... diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index d86a3eab..0c47a2f6 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,5 @@ +--- + # These are supported funding model platforms patreon: roxblnfk diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 00000000..a11ab09d --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,24 @@ +--- + +# this file is for the labeler workflow job +# Documentation https://github.com/marketplace/actions/labeler + +"bug": + - head-branch: ['^bug', '^fix', 'bug', 'fix'] + +"enhancement": + - head-branch: ['^feature', '^feat', 'feature'] + +"documentation": + - changed-files: + - any-glob-to-any-file: ['.github/*.md', './*.md'] + +"maintenance": + - changed-files: + - any-glob-to-any-file: ['.github/**/*'] + +"tests": + - changed-files: + - any-glob-to-any-file: ['tests/**/*', 'phpunit*', 'psalm*'] + +... diff --git a/.github/phar/keys.asc.gpg b/.github/phar/keys.asc.gpg new file mode 100644 index 00000000..fde9a21b Binary files /dev/null and b/.github/phar/keys.asc.gpg differ diff --git a/.github/workflows/apply-labels.yml b/.github/workflows/apply-labels.yml new file mode 100644 index 00000000..f2b6f59b --- /dev/null +++ b/.github/workflows/apply-labels.yml @@ -0,0 +1,23 @@ +--- + +# This workflow will triage pull requests and apply a label based on the +# paths that are modified in the pull request. +# +# To use this workflow, you will need to set up a .github/labeler.yml +# file with configuration. For more information, see: +# https://github.com/actions/labeler/blob/master/README.md + +on: # yamllint disable-line rule:truthy + pull_request: + +name: ๐Ÿท๏ธ Add labels + +jobs: + label: + uses: wayofdev/gh-actions/.github/workflows/apply-labels.yml@v3.1.0 + with: + os: ubuntu-latest + secrets: + token: ${{ secrets.GITHUB_TOKEN }} + +... diff --git a/.github/workflows/build-phar-release.yml b/.github/workflows/build-phar-release.yml new file mode 100644 index 00000000..bc483416 --- /dev/null +++ b/.github/workflows/build-phar-release.yml @@ -0,0 +1,143 @@ +--- + +on: # yamllint disable-line rule:truthy + release: + types: + - published + +name: ๐Ÿ“ฆ Build PHAR release + +jobs: + build-release: + runs-on: ubuntu-latest + timeout-minutes: 4 + strategy: + matrix: + php-version: + - '8.2' + dependencies: + - locked + env: + TRAP_PHAR: ".build/phar/trap.phar" + TRAP_PHAR_SIGNATURE: ".build/phar/trap.phar.asc" + GPG_KEYS: ".build/phar/keys.asc" + GPG_KEYS_ENCRYPTED: ".github/phar/keys.asc.gpg" + steps: + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.5 + + - name: ๐Ÿ› ๏ธ Setup PHP + uses: shivammathur/setup-php@2.30.4 + with: + php-version: ${{ matrix.php-version }} + extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets + ini-values: error_reporting=E_ALL + coverage: none + tools: phive + + - name: ๐Ÿ› ๏ธ Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: ๐Ÿค– Validate composer.json and composer.lock + run: composer validate --ansi --strict + + - name: ๐Ÿ” Get composer cache directory + uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0 + + - name: โ™ป๏ธ Restore cached dependencies installed with composer + uses: actions/cache@v4.0.2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} + restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- + + - name: ๐Ÿ“ฅ Install "${{ matrix.dependencies }}" dependencies with composer + uses: wayofdev/gh-actions/actions/composer/install@v3.1.0 + with: + dependencies: ${{ matrix.dependencies }} + + - name: ๐Ÿ“ฅ Install dependencies with phive + uses: wayofdev/gh-actions/actions/phive/install@v3.1.0 + with: + phive-home: '.phive' + trust-gpg-keys: '0xC00543248C87FB13,0x033E5F8D801A2F8D,0x2DF45277AEF09A2F' + + - name: ๐Ÿ” Validate configuration for box-project/box + run: .phive/box validate box.json.dist --ansi + + - name: ๐Ÿค– Compile trap.phar with box-project/box + run: .phive/box compile --ansi + + - name: ๐Ÿ’ฅ Show info about trap.phar with box-project/box + run: .phive/box info ${{ env.TRAP_PHAR }} --ansi + + - name: ๐Ÿค” Run trap.phar help command + run: ${{ env.TRAP_PHAR }} --help + + - name: ๐Ÿ” Show gpg version + run: gpg --version + + - name: ๐Ÿ”‘ Decrypt keys.asc.gpg with gpg + run: gpg --batch --output ${{ env.GPG_KEYS }} --passphrase "${{ secrets.GPG_DECRYPT_PASSPHRASE }}" --yes --decrypt ${{ env.GPG_KEYS_ENCRYPTED }} + + - name: ๐Ÿ“ฅ Import keys from keys.asc with gpg + run: gpg --batch --import ${{ env.GPG_KEYS }} + + - name: ๐Ÿ” Sign trap.phar with gpg + run: gpg --armor --local-user "${{ secrets.GPG_LOCAL_USER }}" --output ${{ env.TRAP_PHAR_SIGNATURE }} --passphrase "${{ secrets.GPG_KEY_PASSPHRASE }}" --pinentry-mode loopback --yes --detach-sig ${{ env.TRAP_PHAR }} + + - name: โŽ Remove decrypted keys.asc + run: rm ${{ env.GPG_KEYS }} + + - name: ๐Ÿ“ค Upload release assets + uses: actions/github-script@v7.0.1 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + script: | + const fs = require("fs"); + + const files = [ + { + name: "trap.phar", + path: process.env.TRAP_PHAR, + }, + { + name: "trap.phar.asc", + path: process.env.TRAP_PHAR_SIGNATURE, + }, + ]; + + for (const file of files) { + try { + await github.rest.repos.uploadReleaseAsset({ + data: fs.readFileSync(file.path), + name: file.name, + origin: process.env.RELEASE_UPLOAD_URL, + owner: context.repo.owner, + release_id: process.env.RELEASE_ID, + repo: context.repo.repo, + }); + } catch (error) { + core.setFailed(error.message); + } + } + + notify-discord: + runs-on: ubuntu-latest + timeout-minutes: 4 + steps: + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.5 + + - name: โœ‰๏ธ Notify Discord about release + uses: SethCohen/github-releases-to-discord@v1.15.0 + with: + webhook_url: ${{ secrets.DISCORD_WEBHOOK_URL }} + color: '2105893' + username: 'Buggregator Trap release' + avatar_url: 'https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png' + content: '||@here||' + footer_title: 'Changelog' + footer_icon_url: 'https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png' + footer_timestamp: true diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml new file mode 100644 index 00000000..c47afa07 --- /dev/null +++ b/.github/workflows/coding-standards.yml @@ -0,0 +1,196 @@ +--- + +on: # yamllint disable-line rule:truthy + pull_request: + branches: + - master + push: + branches: + - master + +name: ๐Ÿงน Fix PHP coding standards + +jobs: + commit-linting: + timeout-minutes: 4 + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + steps: + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.6 + + - name: ๐Ÿง Lint commits using "commitlint" + uses: wagoid/commitlint-github-action@v6.0.1 + with: + configFile: ${{ github.workspace }}/.github/.commitlint.config.mjs + failOnWarnings: false + failOnErrors: false + helpURL: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint' + + yaml-linting: + timeout-minutes: 4 + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + steps: + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.6 + + - name: ๐Ÿง Lint YAML files + uses: ibiqlik/action-yamllint@v3.1.1 + with: + config_file: .github/.yamllint.yaml + file_or_dir: '.' + strict: true + + markdown-linting: + timeout-minutes: 4 + runs-on: ubuntu-latest + concurrency: + cancel-in-progress: true + group: markdown-linting-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + steps: + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.6 + + - name: ๐Ÿง Lint Markdown files + uses: DavidAnson/markdownlint-cli2-action@v16.0.0 + with: + globs: | + **/*.md + !CHANGELOG.md + + composer-linting: + timeout-minutes: 4 + runs-on: ${{ matrix.os }} + concurrency: + cancel-in-progress: true + group: composer-linting-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + strategy: + matrix: + os: + - ubuntu-latest + php-version: + - '8.1' + dependencies: + - locked + permissions: + contents: write + steps: + - name: ๐Ÿ› ๏ธ Setup PHP + uses: shivammathur/setup-php@2.30.4 + with: + php-version: ${{ matrix.php-version }} + extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, phar, sockets + ini-values: error_reporting=E_ALL + coverage: none + tools: phive + + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.6 + + - name: ๐Ÿ› ๏ธ Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: ๐Ÿค– Validate composer.json and composer.lock + run: composer validate --ansi --strict + + - name: ๐Ÿ” Get composer cache directory + uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0 + + - name: โ™ป๏ธ Restore cached dependencies installed with composer + uses: actions/cache@v4.0.2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} + restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- + + - name: ๐Ÿ“ฅ Install "${{ matrix.dependencies }}" dependencies with composer + uses: wayofdev/gh-actions/actions/composer/install@v3.1.0 + with: + dependencies: ${{ matrix.dependencies }} + + - name: ๐Ÿ“ฅ Install dependencies with phive + uses: wayofdev/gh-actions/actions/phive/install@v3.1.0 + with: + phive-home: '.phive' + trust-gpg-keys: '0xC00543248C87FB13,0x033E5F8D801A2F8D,0x2DF45277AEF09A2F' + + - name: ๐Ÿ” Run ergebnis/composer-normalize + run: .phive/composer-normalize --ansi --dry-run + + coding-standards: + timeout-minutes: 4 + runs-on: ${{ matrix.os }} + concurrency: + cancel-in-progress: true + group: coding-standards-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + strategy: + matrix: + os: + - ubuntu-latest + php-version: + - '8.1' + dependencies: + - locked + permissions: + contents: write + steps: + - name: โš™๏ธ Set git to use LF line endings + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: ๐Ÿ› ๏ธ Setup PHP + uses: shivammathur/setup-php@2.30.4 + with: + php-version: ${{ matrix.php-version }} + extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets + ini-values: error_reporting=E_ALL + coverage: none + + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.6 + + - name: ๐Ÿ› ๏ธ Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: ๐Ÿค– Validate composer.json and composer.lock + run: composer validate --ansi --strict + + - name: ๐Ÿ” Get composer cache directory + uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0 + + - name: โ™ป๏ธ Restore cached dependencies installed with composer + uses: actions/cache@v4.0.2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} + restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- + + - name: ๐Ÿ“ฅ Install "${{ matrix.dependencies }}" dependencies with composer + uses: wayofdev/gh-actions/actions/composer/install@v3.1.0 + with: + dependencies: ${{ matrix.dependencies }} + + - name: ๐Ÿ› ๏ธ Prepare environment + run: make prepare + + - name: ๐Ÿšจ Run coding standards task + run: composer cs:fix + env: + PHP_CS_FIXER_IGNORE_ENV: true + + - name: ๐Ÿ“ค Commit and push changed files back to GitHub + uses: stefanzweifel/git-auto-commit-action@v5.0.1 + with: + commit_message: 'style(php-cs-fixer): lint php files and fix coding standards' + branch: ${{ github.head_ref }} + commit_author: 'github-actions ' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 00000000..a110b80b --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,27 @@ +--- + +# https://github.com/wayofdev/gh-actions/blob/master/.github/workflows/create-release.yml +# https://github.com/google-github-actions/release-please-action#release-types-supported +# https://github.com/googleapis/release-please/blob/main/docs/customizing.md + +on: # yamllint disable-line rule:truthy + push: + branches: + - master + +name: ๐Ÿ“ฆ Create release + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: ๐ŸŽ‰ Create release + uses: googleapis/release-please-action@v4.1.1 + id: release + with: + token: ${{ secrets.TRAP_RELEASE_TOKEN }} + config-file: .github/.release-please-config.json + manifest-file: resources/version.json + target-branch: master + +... diff --git a/.github/workflows/github-releases-to-discord.yml b/.github/workflows/github-releases-to-discord.yml deleted file mode 100644 index acf95707..00000000 --- a/.github/workflows/github-releases-to-discord.yml +++ /dev/null @@ -1,21 +0,0 @@ -on: - release: - types: [published] - -jobs: - github-releases-to-discord: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Github Releases To Discord - uses: SethCohen/github-releases-to-discord@v1.13.1 - with: - webhook_url: ${{ secrets.DISCORD_WEBHOOK_URL }} - color: "2105893" - username: "Buggregator Trap release" - avatar_url: "https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png" - content: "||@here||" - footer_title: "Changelog" - footer_icon_url: "https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png" - footer_timestamp: true diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml deleted file mode 100644 index d2b754ee..00000000 --- a/.github/workflows/psalm.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Psalm - -on: - pull_request: - paths-ignore: - - 'docs/**' - - 'bin/**' - - 'resources/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - '.editorconfig' - - 'psalm.xml' - - push: - paths-ignore: - - 'docs/**' - - 'bin/**' - - 'resources/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - '.editorconfig' - - 'psalm.xml' - -jobs: - psalm: - name: Psalm Validation (PHP ${{ matrix.php }}, OS ${{ matrix.os }}) - runs-on: ${{ matrix.os }} - continue-on-error: true - strategy: - fail-fast: false - matrix: - php: [8.2] - os: [ubuntu-latest] - steps: - - name: Set up PHP ${{ matrix.php }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom - - - name: Check Out Code - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - - name: Get Composer Cache Directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache Dependencies - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: php-${{ matrix.php }}-${{ runner.os }}-composer- - - - name: Install Composer Dependencies - run: composer install --prefer-dist --no-interaction - - - name: Run Tests - run: vendor/bin/psalm diff --git a/.github/workflows/run-test-suite.yml b/.github/workflows/run-test-suite.yml deleted file mode 100644 index 3ee86004..00000000 --- a/.github/workflows/run-test-suite.yml +++ /dev/null @@ -1,112 +0,0 @@ -name: Unit - -on: - workflow_call: - inputs: - test-suite: - required: true - type: string - fail-fast: - required: false - type: boolean - default: true - test-timeout: - required: false - type: number - default: 15 - - pull_request: - paths-ignore: - - 'docs/**' - - 'bin/**' - - 'resources/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - '.editorconfig' - - 'psalm.xml' - - push: - paths-ignore: - - 'docs/**' - - 'bin/**' - - 'resources/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - '.editorconfig' - - 'psalm.xml' - -jobs: - test: - name: (PHP ${{ matrix.php }}, ${{ matrix.os }}, ${{ matrix.dependencies }} deps - runs-on: ${{ matrix.os }} - timeout-minutes: ${{ matrix.timeout-minutes }} - env: { GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' } - strategy: - fail-fast: ${{ inputs.fail-fast }} - matrix: - php: [ 8.1, 8.2 ] - os: [ ubuntu-latest, windows-latest ] - dependencies: [ lowest , highest ] - timeout-minutes: [ '${{ inputs.test-timeout }}' ] - exclude: - - os: windows-latest - php: 8.2 - include: - - os: ubuntu-latest - php: 8.3 - dependencies: highest - timeout-minutes: 40 - steps: - - name: Set Git To Use LF - run: | - git config --global core.autocrlf false - git config --global core.eol lf - - - name: Setup PHP ${{ matrix.php }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - tools: composer:v2 - extensions: sockets, curl - - - name: Check Out Code - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Get Composer Cache Directory - id: composer-cache - run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache Composer Dependencies - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: php-${{ matrix.php }}-${{ matrix.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - php-${{ matrix.php }}-${{ matrix.os }}-composer- - - - name: Install lowest dependencies from composer.json - if: matrix.dependencies == 'lowest' - run: composer update --no-interaction --no-progress --prefer-lowest - - - name: Validate lowest dependencies - if: matrix.dependencies == 'lowest' - env: - COMPOSER_POOL_OPTIMIZER: 0 - run: vendor/bin/validate-prefer-lowest - - - name: Install highest dependencies from composer.json - if: matrix.dependencies == 'highest' - run: composer update --no-interaction --no-progress - - - name: Run tests - run: vendor/bin/phpunit --testsuite=${{ inputs.test-suite }} --testdox diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 3adb5889..7c92c9d6 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -1,65 +1,59 @@ -name: Security +--- -on: - pull_request: - paths-ignore: - - 'docs/**' - - 'bin/**' - - 'resources/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - '.editorconfig' - - 'psalm.xml' +name: ๐Ÿ” Security analysis +on: # yamllint disable-line rule:truthy + pull_request: push: - paths-ignore: - - 'docs/**' - - 'bin/**' - - 'resources/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - '.editorconfig' - - 'psalm.xml' jobs: - security: - name: Security Checks (PHP ${{ matrix.php }}, OS ${{ matrix.os }}) + security-analysis: + timeout-minutes: 4 runs-on: ${{ matrix.os }} + concurrency: + cancel-in-progress: true + group: security-analysis-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} strategy: - fail-fast: false + fail-fast: true matrix: - # Note: This workflow requires only the LATEST version of PHP - php: [ 8.2 ] - os: [ ubuntu-latest ] + os: + - ubuntu-latest + php-version: + - '8.2' + dependencies: + - locked steps: - - name: Set up PHP ${{ matrix.php }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom, sockets, grpc, curl + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.5 - - name: Check Out Code - uses: actions/checkout@v4 + - name: ๐Ÿ› ๏ธ Setup PHP + uses: shivammathur/setup-php@2.30.4 with: - fetch-depth: 1 + php-version: ${{ matrix.php-version }} + extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets + ini-values: error_reporting=E_ALL + coverage: none - - name: Get Composer Cache Directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: ๐Ÿ› ๏ธ Setup problem matchers + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" - - name: Cache Dependencies - uses: actions/cache@v3 + - name: ๐Ÿค– Validate composer.json and composer.lock + run: composer validate --ansi --strict + + - name: ๐Ÿ” Get composer cache directory + uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0 + + - name: โ™ป๏ธ Restore cached dependencies installed with composer + uses: actions/cache@v4.0.2 with: - path: ${{ steps.composer-cache.outputs.dir }} - key: php-${{ matrix.php }}-${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: php-${{ matrix.php }}-${{ runner.os }}-composer- + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} + restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- - - name: Install Composer Dependencies - run: composer install --prefer-dist --no-interaction + - name: ๐Ÿ“ฅ Install "${{ matrix.dependencies }}" dependencies + uses: wayofdev/gh-actions/actions/composer/install@v3.1.0 + with: + dependencies: ${{ matrix.dependencies }} - - name: Verify - run: composer require --dev roave/security-advisories:dev-latest + - name: ๐Ÿ› Check installed packages for security vulnerability advisories + run: composer audit --ansi diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 00000000..fcfaba9c --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,72 @@ +--- + +on: # yamllint disable-line rule:truthy + pull_request: + paths: + - 'src/**' + - 'tests/**' + - 'bin/trap' + - '.php-cs-fixer.dist.php' + push: + paths: + - 'src/**' + - 'tests/**' + - 'bin/trap' + - '.php-cs-fixer.dist.php' + +name: ๐Ÿ” Static analysis + +jobs: + static-analysis: + timeout-minutes: 4 + runs-on: ${{ matrix.os }} + concurrency: + cancel-in-progress: true + group: static-analysis-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + strategy: + fail-fast: true + matrix: + os: + - ubuntu-latest + php-version: + - '8.2' + dependencies: + - locked + steps: + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.5 + + - name: ๐Ÿ› ๏ธ Setup PHP + uses: shivammathur/setup-php@2.30.4 + with: + php-version: ${{ matrix.php-version }} + extensions: none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets, opcache, pcntl, posix + ini-values: error_reporting=E_ALL + coverage: none + + - name: ๐Ÿ› ๏ธ Setup problem matchers + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: ๐Ÿค– Validate composer.json and composer.lock + run: composer validate --ansi --strict + + - name: ๐Ÿ” Get composer cache directory + uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0 + + - name: โ™ป๏ธ Restore cached dependencies installed with composer + uses: actions/cache@v4.0.2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} + restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- + + - name: ๐Ÿ“ฅ Install "${{ matrix.dependencies }}" dependencies + uses: wayofdev/gh-actions/actions/composer/install@v3.1.0 + with: + dependencies: ${{ matrix.dependencies }} + + - name: ๐Ÿ” Run static analysis using vimeo/psalm + run: composer psalm:ci + + - name: ๐Ÿ” Run static analysis using phpstan/phpstan + run: composer stan:ci diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index d8e8773b..0f9d82a5 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -1,11 +1,206 @@ -name: Testing +--- -on: [push, pull_request] +name: ๐Ÿงช Unit testing + +on: # yamllint disable-line rule:truthy + pull_request: + branches: + - master + push: + branches: + - master jobs: - unit: - name: Unit Testing - uses: ./.github/workflows/run-test-suite.yml - with: - fail-fast: false - test-suite: Unit + code-coverage: + timeout-minutes: 4 + runs-on: ${{ matrix.os }} + concurrency: + cancel-in-progress: true + group: code-coverage-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ matrix.php-version }}-${{ matrix.dependencies }} + strategy: + fail-fast: true + matrix: + os: + - ubuntu-latest + php-version: + - '8.2' + dependencies: + - locked + steps: + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.5 + + - name: ๐Ÿ› ๏ธ Setup PHP + uses: shivammathur/setup-php@2.30.4 + with: + php-version: ${{ matrix.php-version }} + extensions: none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets, opcache, pcntl, posix + ini-values: error_reporting=E_ALL + coverage: xdebug + + - name: ๐Ÿ› ๏ธ Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: ๐Ÿค– Validate composer.json and composer.lock + run: composer validate --ansi --strict + + - name: ๐Ÿ” Get composer cache directory + uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0 + + - name: โ™ป๏ธ Restore cached dependencies installed with composer + uses: actions/cache@v4.0.2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} + restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- + + - name: ๐Ÿ“ฅ Install "${{ matrix.dependencies }}" dependencies + uses: wayofdev/gh-actions/actions/composer/install@v3.1.0 + with: + dependencies: ${{ matrix.dependencies }} + + - name: ๐Ÿงช Collect code coverage with Xdebug and pestphp/pest + run: composer test:cc + + - name: ๐Ÿ“ค Upload code coverage report to Codecov + uses: codecov/codecov-action@v4.3.0 + with: + files: .build/phpunit/logs/clover.xml + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + + testing: + timeout-minutes: 4 + runs-on: ${{ matrix.os }} + concurrency: + cancel-in-progress: true + group: testing-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ matrix.php-version }}-${{ matrix.dependencies }} + strategy: + fail-fast: true + matrix: + os: + - ubuntu-latest + php-version: + - '8.1' + - '8.2' + - '8.3' + dependencies: + - lowest + - locked + - highest + steps: + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.5 + + - name: ๐Ÿ› ๏ธ Setup PHP + uses: shivammathur/setup-php@2.30.4 + with: + php-version: ${{ matrix.php-version }} + extensions: none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets, opcache, pcntl, posix + ini-values: error_reporting=E_ALL + coverage: xdebug + + - name: ๐Ÿ› ๏ธ Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: ๐Ÿค– Validate composer.json and composer.lock + run: composer validate --ansi --strict + + - name: ๐Ÿ” Get composer cache directory + uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0 + + - name: โ™ป๏ธ Restore cached dependencies installed with composer + uses: actions/cache@v4.0.2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} + restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- + + - name: โš™๏ธ Remove platform configuration with composer + if: matrix.dependencies != 'locked' + run: composer config platform.php --ansi --unset + + - name: ๐Ÿ“ฅ Install "${{ matrix.dependencies }}" dependencies + uses: wayofdev/gh-actions/actions/composer/install@v3.1.0 + with: + dependencies: ${{ matrix.dependencies }} + + - name: ๐Ÿงช Run unit tests using pestphp/pest + run: composer test + + - name: ๐Ÿงช Run tests that require separate process using phpunit/phpunit + run: composer test:sep + + compile-phar: + timeout-minutes: 4 + runs-on: ${{ matrix.os }} + concurrency: + cancel-in-progress: true + group: compile-phar-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ matrix.php-version }}-${{ matrix.dependencies }} + strategy: + fail-fast: true + matrix: + os: + - ubuntu-latest + php-version: + - '8.2' + dependencies: + - locked + env: + TRAP_PHAR: ".build/phar/trap.phar" + TRAP_PHAR_SIGNATURE: ".build/phar/trap.phar.asc" + steps: + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.5 + with: + fetch-depth: 0 + + - name: ๐Ÿ› ๏ธ Setup PHP + uses: shivammathur/setup-php@2.30.4 + with: + php-version: ${{ matrix.php-version }} + extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets + ini-values: 'error_reporting=E_ALL, memory_limit=-1, phar.readonly=0' + coverage: none + tools: phive + + - name: ๐Ÿ› ๏ธ Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: ๐Ÿ” Get composer cache directory + uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0 + + - name: โ™ป๏ธ Restore cached dependencies installed with composer + uses: actions/cache@v4.0.2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} + restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- + + - name: ๐Ÿ“ฅ Install "${{ matrix.dependencies }}" dependencies with composer + uses: wayofdev/gh-actions/actions/composer/install@v3.1.0 + with: + dependencies: ${{ matrix.dependencies }} + + - name: ๐Ÿ“ฅ Install dependencies with phive + uses: wayofdev/gh-actions/actions/phive/install@v3.1.0 + with: + phive-home: '.phive' + trust-gpg-keys: '0xC00543248C87FB13,0x033E5F8D801A2F8D,0x2DF45277AEF09A2F' + + - name: ๐Ÿ” Validate configuration for box-project/box + run: .phive/box validate box.json.dist --ansi + + - name: ๐Ÿค– Compile trap.phar with box-project/box + run: .phive/box compile --ansi + + - name: ๐Ÿ’ฅ Show info about trap.phar with box-project/box + run: .phive/box info ${{ env.TRAP_PHAR }} --ansi + + - name: ๐Ÿค” Run trap.phar help command + run: ${{ env.TRAP_PHAR }} --help diff --git a/.gitignore b/.gitignore index 4a5884fa..a333a058 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ /.*/ +!/.phive/ !/.github/ +!/.phar/ /runtime/ /vendor/ -/composer.lock /.env *.log diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 00000000..77f382df --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://raw.githubusercontent.com/DavidAnson/markdownlint/main/schema/markdownlint-config-schema.json", + "line-length": false, + "no-inline-html": false, + "first-line-h1": false, + "no-duplicate-heading": false +} diff --git a/.phive/.gitignore b/.phive/.gitignore new file mode 100644 index 00000000..71d2e19d --- /dev/null +++ b/.phive/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!phars.xml diff --git a/.phive/phars.xml b/.phive/phars.xml new file mode 100644 index 00000000..13cfd4e6 --- /dev/null +++ b/.phive/phars.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..56f76207 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,22 @@ +inDir(__DIR__ . '/bin') + ->inDir(__DIR__ . '/src') + ->inDir(__DIR__ . '/tests') + ->exclude([ + __DIR__ . '/src/Test/Proto', + ]) + ->addFiles([__FILE__]) + ->getConfig(); + +$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php-cs-fixer.cache'); + +return $config; diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..d4ad27e3 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,55 @@ +# Changelog + +## [1.7.3](https://github.com/buggregator/trap/compare/v1.7.2...v1.7.3) (2024-05-24) + + +### Bug Fixes + +* remove unnecessary escape symbols from action file for phar building ([b6c628b](https://github.com/buggregator/trap/commit/b6c628b62f7a831a9ccca7c3b62a5834f2aa5453)) + +## [1.7.2](https://github.com/buggregator/trap/compare/v1.7.1...v1.7.2) (2024-05-24) + + +### Bug Fixes + +* fixed path to keys.asc.gpg to sign phar ([7c80552](https://github.com/buggregator/trap/commit/7c80552635d0703e2cbd15bde3a76eedc5adcb08)) + +## [1.7.1](https://github.com/buggregator/trap/compare/v1.7.0...v1.7.1) (2024-05-24) + + +### Bug Fixes + +* update release-token ([#94](https://github.com/buggregator/trap/issues/94)) ([51f187b](https://github.com/buggregator/trap/commit/51f187b743941093a33d86daba2ba5c815dd62de)) + +## [1.7.0](https://github.com/buggregator/trap/compare/1.6.0...v1.7.0) (2024-05-24) + + +### Features + +* add box-project/box, composer-require-checker and composer-normalize PHARs ([d86a1e0](https://github.com/buggregator/trap/commit/d86a1e04d5512f32adfa643d0ac43f3c888aa64a)) +* add docker compose support ([d86a1e0](https://github.com/buggregator/trap/commit/d86a1e04d5512f32adfa643d0ac43f3c888aa64a)) +* add initial Makefile ([3d1738f](https://github.com/buggregator/trap/commit/3d1738fff0e0784a67930340bee7d493ffeacba5)) +* add support for pest-php ([340c5eb](https://github.com/buggregator/trap/commit/340c5eb941bc8b805db1cb39cb2bde7259a42911)) +* Makefile now builds trap PHAR locally using `make phar` command ([d86a1e0](https://github.com/buggregator/trap/commit/d86a1e04d5512f32adfa643d0ac43f3c888aa64a)) +* use latest version from auto-incrementing file ([f7b9210](https://github.com/buggregator/trap/commit/f7b9210ad152347963956d3bfcd56e2206a44a67)) + + +### Bug Fixes + +* add cache into the `Info::version()` method; move version.json into `resources` dir ([eb129ba](https://github.com/buggregator/trap/commit/eb129ba460c95755302890ae910f4649fb27d11b)) +* cache version variable ([46b2460](https://github.com/buggregator/trap/commit/46b2460edef7f6239df6d6b2e00b49e82b1d5cdd)) +* return experimental, if version is not found ([a39cdd9](https://github.com/buggregator/trap/commit/a39cdd90f401e1c20b9e831bb01f5721edf4a921)) +* set `console` renderer by default again. ([b6ad654](https://github.com/buggregator/trap/commit/b6ad65463b55afd0670b46b96b95197f2061e573)) +* use .build directory for all development tools ([1f49bb8](https://github.com/buggregator/trap/commit/1f49bb8e0249a01d7080ea6bedeea6b6e6ae80b2)) + + +### Documentation + +* fix link to logo in readme; add `support` shield ([#83](https://github.com/buggregator/trap/issues/83)) ([23ebc91](https://github.com/buggregator/trap/commit/23ebc91337ec5a943e7f2245de3ad944abfe4e67)) +* replace DIV with P around IMG ([4169ae2](https://github.com/buggregator/trap/commit/4169ae28a11a0e5fd38219612bf79cdaa021d44f)) +* replace DIV with P tag to be more readable in packagist page ([9594a1d](https://github.com/buggregator/trap/commit/9594a1dadc6e5d0bdf02ad6f8c5f9ec24be738de)) + + +### Code Refactoring + +* github workflows ([a108476](https://github.com/buggregator/trap/commit/a108476c674fac90f08e0576fb480946cc211293)) diff --git a/LICENSE.md b/LICENSE.md index f3592a62..40070d1f 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -2,18 +2,18 @@ Copyright (c) 2023, Buggregator. All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright +* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Buggregator nor the names of its +* Neither the name of Buggregator nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..618039f7 --- /dev/null +++ b/Makefile @@ -0,0 +1,296 @@ +-include .env + +# BuildKit enables higher performance docker builds and caching possibility +# to decrease build times and increase productivity for free. +# https://docs.docker.com/compose/environment-variables/envvars/ +export DOCKER_BUILDKIT ?= 1 + +# User ID and Group ID to use inside docker containers +HOST_UID ?= $(shell id -u) +HOST_GID ?= $(shell id -g) + +# Docker binary to use, when executing docker tasks +DOCKER ?= docker + +# Binary to use, when executing docker-compose tasks +DOCKER_COMPOSE ?= $(DOCKER) compose + +# Support image with all needed binaries, like envsubst, mkcert, wait4x +SUPPORT_IMAGE ?= wayofdev/build-deps:alpine-latest + +APP_RUNNER ?= $(DOCKER_COMPOSE) run --rm --no-deps app +APP_COMPOSER ?= $(APP_RUNNER) composer + +BUILDER_PARAMS ?= $(DOCKER) run --rm -i \ + --env-file ./.env \ + --env COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \ + --env COMPOSER_AUTH="$(COMPOSER_AUTH)" + +BUILDER ?= $(BUILDER_PARAMS) $(SUPPORT_IMAGE) +BUILDER_WIRED ?= $(BUILDER_PARAMS) --network project.$(COMPOSE_PROJECT_NAME) $(SUPPORT_IMAGE) + +# Shorthand envsubst command, executed through build-deps +ENVSUBST ?= $(BUILDER) envsubst + +# Yamllint docker image +YAML_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \ + -v $(PWD):/data \ + cytopia/yamllint:latest \ + -c ./.github/.yamllint.yaml \ + -f colored . + +ACTION_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \ + -v $(shell pwd):/repo \ + --workdir /repo \ + rhysd/actionlint:latest \ + -color + +MARKDOWN_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \ + -v $(shell pwd):/app \ + --workdir /app \ + davidanson/markdownlint-cli2-rules:latest + +PHIVE_RUNNER ?= $(DOCKER_COMPOSE) run --rm --no-deps app + +EXPORT_VARS = '\ + $${COMPOSE_PROJECT_NAME} \ + $${COMPOSER_AUTH} \ + $${HOST_UID} \ + $${HOST_GID}' + +# +# Self documenting Makefile code +# ------------------------------------------------------------------------------------ +ifneq ($(TERM),) + BLACK := $(shell tput setaf 0) + RED := $(shell tput setaf 1) + GREEN := $(shell tput setaf 2) + YELLOW := $(shell tput setaf 3) + LIGHTPURPLE := $(shell tput setaf 4) + PURPLE := $(shell tput setaf 5) + BLUE := $(shell tput setaf 6) + WHITE := $(shell tput setaf 7) + RST := $(shell tput sgr0) +else + BLACK := "" + RED := "" + GREEN := "" + YELLOW := "" + LIGHTPURPLE := "" + PURPLE := "" + BLUE := "" + WHITE := "" + RST := "" +endif +MAKE_LOGFILE = /tmp/buggregator-trap.log +MAKE_CMD_COLOR := $(BLUE) + +default: all + +help: ## Show this menu + @echo 'Management commands for package:' + @echo 'Usage:' + @echo ' ${MAKE_CMD_COLOR}make${RST} Setups dependencies for fresh-project, like composer install, git hooks and others...' + @grep -E '^[a-zA-Z_0-9%-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf " ${MAKE_CMD_COLOR}make %-21s${RST} %s\n", $$1, $$2}' + @echo + @echo ' ๐Ÿ“‘ Logs are stored in $(MAKE_LOGFILE)' + @echo + @echo ' ๐Ÿ“ฆ Package trap (github.com/buggregator/trap)' + @echo ' ๐Ÿค  Makefile Author Andrij Orlenko (github.com/lotyp)' + @echo ' ๐Ÿข ${YELLOW}Org ๐Ÿž buggregator (github.com/buggregator)${RST}' + @echo +.PHONY: help + +.EXPORT_ALL_VARIABLES: + +# +# Default action +# Defines default command when `make` is executed without additional parameters +# ------------------------------------------------------------------------------------ +all: env prepare install hooks phive up +.PHONY: all + +# +# System Actions +# ------------------------------------------------------------------------------------ +env: ## Generate .env file from example, use `make env force=true`, to force re-create file +ifeq ($(FORCE),true) + @echo "${YELLOW}Force re-creating .env file from example...${RST}" + $(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env +else ifneq ("$(wildcard ./.env)","") + @echo "" + @echo "${YELLOW}The .env file already exists! Use FORCE=true to re-create.${RST}" +else + @echo "Creating .env file from example" + $(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env +endif +.PHONY: env + +prepare: + mkdir -p .build/php-cs-fixer +.PHONY: prepare + +# +# Docker Actions +# ------------------------------------------------------------------------------------ +up: # Creates and starts containers, defined in docker-compose and override file + $(DOCKER_COMPOSE) up --remove-orphans -d +.PHONY: up + +down: # Stops and removes containers of this project + $(DOCKER_COMPOSE) down --remove-orphans --volumes +.PHONY: down + +restart: down up ## Runs down and up commands +.PHONY: restart + +clean: ## Stops containers if required and removes from system + $(DOCKER_COMPOSE) rm --force --stop +.PHONY: clean + +ps: ## List running project containers + $(DOCKER_COMPOSE) ps +.PHONY: ps + +logs: ## Show project docker logs with follow up mode enabled + $(DOCKER_COMPOSE) logs -f +.PHONY: logs + +pull: ## Pull and update docker images in this project + $(DOCKER_COMPOSE) pull +.PHONY: pull + +ssh: ## Login inside running docker container + $(APP_RUNNER) sh +.PHONY: ssh + +# +# Composer +# ------------------------------------------------------------------------------------ +install: ## Installs composer dependencies + $(APP_COMPOSER) install +.PHONY: install + +update: ## Updates composer dependencies by running composer update command + $(APP_COMPOSER) update +.PHONY: update + +phive: ## Installs dependencies with phive + $(APP_RUNNER) /usr/local/bin/phive install --trust-gpg-keys 0xC00543248C87FB13,0x033E5F8D801A2F8D,0x2DF45277AEF09A2F +.PHONY: phive + +phar: + $(APP_RUNNER) sh -c "git config --global --add safe.directory /app \ + && .phive/box validate \ + && .phive/box compile \ + && .phive/box info .build/phar/trap.phar \ + && .build/phar/trap.phar" +.PHONY: phar + +# +# Code Quality, Git, Linting +# ------------------------------------------------------------------------------------ +hooks: ## Install git hooks from pre-commit-config + pre-commit install + pre-commit install --hook-type commit-msg + pre-commit autoupdate +.PHONY: hooks + +lint: lint-yaml lint-actions lint-md lint-php lint-stan lint-composer lint-audit ## Runs all linting commands +.PHONY: lint + +lint-yaml: ## Lints yaml files inside project + @$(YAML_LINT_RUNNER) | tee -a $(MAKE_LOGFILE) +.PHONY: lint-yaml + +lint-actions: ## Lint all github actions + @$(ACTION_LINT_RUNNER) | tee -a $(MAKE_LOGFILE) +.PHONY: lint-actions + +lint-md: ## Lint all markdown files using markdownlint-cli2 + @$(MARKDOWN_LINT_RUNNER) --fix "**/*.md" "!CHANGELOG.md" "!vendor" | tee -a $(MAKE_LOGFILE) +.PHONY: lint-md + +lint-md-dry: ## Lint all markdown files using markdownlint-cli2 in dry-run mode + @$(MARKDOWN_LINT_RUNNER) "**/*.md" "!CHANGELOG.md" "!vendor" | tee -a $(MAKE_LOGFILE) +.PHONY: lint-md-dry + +lint-php: prepare ## Fixes code to follow coding standards using php-cs-fixer + $(APP_COMPOSER) cs:fix +.PHONY: lint-php + +lint-diff: prepare ## Runs php-cs-fixer in dry-run mode and shows diff which will by applied + $(APP_COMPOSER) cs:diff +.PHONY: lint-diff + +lint-stan: ## Runs phpstan โ€“ static analysis tool + $(APP_COMPOSER) stan +.PHONY: lint-stan + +lint-stan-ci: ## Runs phpstan โ€“ static analysis tool with github output (CI mode) + $(APP_COMPOSER) stan:ci +.PHONY: lint-stan-ci + +lint-stan-baseline: ## Runs phpstan to update its baseline + $(APP_COMPOSER) stan:baseline +.PHONY: lint-stan-baseline + +lint-psalm: ## Runs vimeo/psalm โ€“ static analysis tool + $(APP_COMPOSER) psalm +.PHONY: lint-psalm + +lint-psalm-ci: ## Runs vimeo/psalm โ€“ static analysis tool with github output (CI mode) + $(APP_COMPOSER) psalm:ci +.PHONY: lint-psalm-ci + +lint-psalm-baseline: ## Runs vimeo/psalm to update its baseline + $(APP_COMPOSER) psalm:baseline +.PHONY: lint-psalm-baseline + +lint-deps: ## Runs composer-require-checker โ€“ checks for dependencies that are not used + $(APP_RUNNER) .phive/composer-require-checker check \ + --config-file=/app/composer-require-checker.json \ + --verbose +.PHONY: lint-deps + +lint-composer: ## Normalize composer.json and composer.lock files + $(APP_RUNNER) .phive/composer-normalize normalize +.PHONY: lint-composer + +lint-audit: ## Runs security checks for composer dependencies + $(APP_COMPOSER) audit +.PHONY: lint-security + +refactor: ## Runs rector โ€“ code refactoring tool + $(APP_COMPOSER) refactor +.PHONY: refactor + +# +# Testing +# ------------------------------------------------------------------------------------ +infect: ## Runs mutation tests with infection/infection + $(APP_COMPOSER) infect +.PHONY: infect + +infect-ci: ## Runs infection โ€“ mutation testing framework with github output (CI mode) + $(APP_COMPOSER) infect:ci +.PHONY: lint-infect-ci + +test: ## Run project php-unit and pest tests + $(APP_COMPOSER) test +.PHONY: test + +test-cc: ## Run project php-unit and pest tests in coverage mode and build report + $(APP_COMPOSER) test:cc +.PHONY: test-cc + +test-sep: ## Run project php-unit tests that requires @runInSeparateProcess annotation + $(APP_COMPOSER) test:sep +.PHONY: test-sep + +# +# Release +# ------------------------------------------------------------------------------------ +commit: + czg commit --config="./.github/.cz.config.js" +.PHONY: commit diff --git a/README.md b/README.md index 80e5e56e..b04f4254 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,17 @@ -
- logo -
Revolutionize Your Debugging Experience with PHP
-
+

+ logo +

+

Revolutionize Your Debugging Experience with PHP

Buggregator Trap

[![Twitter](https://img.shields.io/badge/-Follow-black?style=flat-square&logo=X)](https://twitter.com/buggregator) [![Discord](https://img.shields.io/discord/1172942458598985738?style=flat-square&logo=discord&color=0000ff)](https://discord.gg/qF3HpXhMEP) +[![Support](https://img.shields.io/static/v1?style=flat-square&label=Support&message=%E2%9D%A4&logo=GitHub&color=%23fe0086)](https://patreon.com/roxblnfk)
@@ -141,15 +145,28 @@ $responder->respond(trap($response)->return()); ### Default port -By default, the Trap server operates on port `9912`. However, if you wish to utilize a different port, you can easily -make this adjustment using the `-p` option. +Trap automatically recognizes the type of traffic. +Therefore, there is no need to open separate ports for different protocols. +By default, it operates on port `9912`. +However, if you wish to utilize a different port, you can easily make this adjustment using the `-p` option: + +```bash +vendor/bin/trap -p8000 +``` -For example, to switch to port 8000, you would use the following command: +Sometimes, it's convenient to run Trap on the same ports that [Buggregator](https://github.com/buggregator/server) +uses by default. Well, that's also possible: ```bash -vendor/bin/trap -p 8000 +vendor/bin/trap -p1025 -p9912 -p9913 -p8000 --ui=8080 ``` +Environment variables can also be used to set endpoints: + +- `TRAP_TCP_PORTS` - for TCP traffic: `9912,9913,1025,8000` +- `TRAP_TCP_HOST` - for the TCP host (default: `127.0.0.1`) +- `TRAP_UI_PORT` - for the web interface: `8080` + ### Choosing Your Senders Buggregator Trap provides a variety of "senders" that dictate where the dumps will be sent. Currently, the available @@ -168,7 +185,6 @@ For instance, to simultaneously use the console, file, and server senders, you w vendor/bin/trap -s console -s file -s server ``` - ## Contributing We believe in the power of community-driven development. Here's how you can contribute: @@ -179,7 +195,7 @@ We believe in the power of community-driven development. Here's how you can cont issues labeled "help wanted" [here](https://github.com/buggregator/trap/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22). - **Documentation:** Help us improve our [guides and tutorials](https://github.com/buggregator/docs/tree/master/docs) for a smoother user experience. - **Community Support:** Join our [Discord](https://discord.gg/qF3HpXhMEP) and help others get the most out of Buggregator. -- **Spread the Word:** Share your experience with Buggregator on social media and encourage others to contribute. +- **Spread the Word:** Share your experience with Buggregator on social media and encourage others to contribute. - **Donate:** Support our work by becoming a patron or making a one-time donation [![roxblnfk](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Droxblnfk%26type%3Dpatrons&label=roxblnfk&style=flat-square)](https://patreon.com/roxblnfk) [![butschster](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dbutschster%26type%3Dpatrons&label=butschster&style=flat-square)](https://patreon.com/butschster) @@ -187,14 +203,10 @@ We believe in the power of community-driven development. Here's how you can cont **Remember, every great developer was once a beginner. Contributing to open source projects is a step in your journey to becoming a better developer. So, don't hesitate to jump in and start contributing!** - ## License Buggregator Trap is open-sourced software licensed under the BSD-3 license. - - -