Repository: salahhusa9/laravel-updater Branch: main Commit: ab7fb4c20bd9 Files: 63 Total size: 82.3 KB Directory structure: gitextract_joqugs2b/ ├── .editorconfig ├── .gitattributes ├── .github/ │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE/ │ │ ├── bug.yml │ │ └── config.yml │ ├── dependabot.yml │ └── workflows/ │ ├── dependabot-auto-merge.yml │ ├── deploy-docs.yml │ ├── fix-php-code-style-issues.yml │ ├── run-tests.yml │ └── update-changelog.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── config/ │ └── updater.php ├── database/ │ └── factories/ │ └── ModelFactory.php ├── phpunit.xml.dist ├── renovate.json ├── resources/ │ └── views/ │ └── .gitkeep ├── src/ │ ├── Commands/ │ │ ├── CheckCommand.php │ │ └── UpdaterCommand.php │ ├── Contracts/ │ │ ├── Pipeline.php │ │ └── Repository.php │ ├── Events/ │ │ ├── NewVersionAvailable.php │ │ ├── UpdateFailed.php │ │ └── UpdatedSuccessfully.php │ ├── Exceptions/ │ │ ├── GitFailedException.php │ │ └── GithubConfigException.php │ ├── Facades/ │ │ └── Updater.php │ ├── Helpers/ │ │ ├── Git.php │ │ └── Helper.php │ ├── Pipelines/ │ │ ├── ArtisanCallCacheClearPipe.php │ │ ├── ArtisanCallConfigClearPipe.php │ │ ├── ArtisanCallMigratePipe.php │ │ ├── ArtisanCallOptimizePipe.php │ │ ├── ArtisanCallRouteClearPipe.php │ │ ├── ArtisanCallViewClearPipe.php │ │ ├── GitPipe.php │ │ └── SeedersPipe.php │ ├── RepositorySource/ │ │ └── GithubRepository.php │ ├── Updater.php │ └── UpdaterServiceProvider.php ├── tests/ │ ├── ArchTest.php │ ├── Commands/ │ │ ├── CheckCommandTest.php │ │ └── UpdaterCommandTest.php │ ├── ExampleTest.php │ ├── GitTest.php │ ├── HelperTest.php │ ├── Pest.php │ ├── Pipelines/ │ │ ├── ArtisanCallCacheClearPipeTest.php │ │ ├── ArtisanCallConfigClearPipeTest.php │ │ ├── ArtisanCallMigratePipeTest.php │ │ ├── ArtisanCallOptimizePipeTest.php │ │ ├── ArtisanCallRouteClearPipeTest.php │ │ ├── ArtisanCallViewClearPipeTest.php │ │ ├── GitPipeTest.php │ │ └── SeedersPipeTest.php │ ├── RepositorySource/ │ │ └── GithubRepositoryTest.php │ ├── TestCase.php │ └── UpdaterTest.php └── workbench/ └── app/ └── Providers/ └── WorkbenchServiceProvider.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ root = true [*] charset = utf-8 end_of_line = lf indent_size = 4 indent_style = space insert_final_newline = true trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false [*.{yml,yaml}] indent_size = 2 ================================================ FILE: .gitattributes ================================================ # Path-based git attributes # https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html # Ignore all test and documentation with "export-ignore". /.github export-ignore /.gitattributes export-ignore /.gitignore export-ignore /phpunit.xml.dist export-ignore /art export-ignore /docs export-ignore /tests export-ignore /workbench export-ignore /.editorconfig export-ignore /.php_cs.dist.php export-ignore /psalm.xml export-ignore /psalm.xml.dist export-ignore /testbench.yaml export-ignore /UPGRADING.md export-ignore /phpstan.neon.dist export-ignore /phpstan-baseline.neon export-ignore ================================================ FILE: .github/FUNDING.yml ================================================ # These are supported funding model platforms github: [salahhusa9] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] ================================================ FILE: .github/ISSUE_TEMPLATE/bug.yml ================================================ name: Bug Report description: Report an Issue or Bug with the Package title: "[Bug]: " labels: ["bug"] body: - type: markdown attributes: value: | We're sorry to hear you have a problem. Can you help us solve it by providing the following details. - type: textarea id: what-happened attributes: label: What happened? description: What did you expect to happen? placeholder: I cannot currently do X thing because when I do, it breaks X thing. validations: required: true - type: textarea id: how-to-reproduce attributes: label: How to reproduce the bug description: How did this occur, please add any config values used and provide a set of reliable steps if possible. placeholder: When I do X I see Y. validations: required: true - type: input id: package-version attributes: label: Package Version description: What version of our Package are you running? Please be as specific as possible placeholder: 2.0.0 validations: required: true - type: input id: php-version attributes: label: PHP Version description: What version of PHP are you running? Please be as specific as possible placeholder: 8.2.0 validations: required: true - type: input id: laravel-version attributes: label: Laravel Version description: What version of Laravel are you running? Please be as specific as possible placeholder: 9.0.0 validations: required: true - type: dropdown id: operating-systems attributes: label: Which operating systems does with happen with? description: You may select more than one. multiple: true options: - macOS - Windows - Linux - type: textarea id: notes attributes: label: Notes description: Use this field to provide any other notes that you feel might be relevant to the issue. validations: required: false ================================================ FILE: .github/ISSUE_TEMPLATE/config.yml ================================================ blank_issues_enabled: false contact_links: - name: Ask a question url: https://github.com/salahhusa9/laravel-updater/discussions/new?category=q-a about: Ask the community for help - name: Request a feature url: https://github.com/salahhusa9/laravel-updater/discussions/new?category=ideas about: Share ideas for new features - name: Report a security issue url: https://github.com/salahhusa9/laravel-updater/security/policy about: Learn how to notify us for sensitive bugs ================================================ FILE: .github/dependabot.yml ================================================ # Please see the documentation for all configuration options: # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates version: 2 updates: - package-ecosystem: "github-actions" directory: "/" schedule: interval: "weekly" labels: - "dependencies" ================================================ FILE: .github/workflows/dependabot-auto-merge.yml ================================================ name: dependabot-auto-merge on: pull_request_target permissions: pull-requests: write contents: write jobs: dependabot: runs-on: ubuntu-latest if: ${{ github.actor == 'dependabot[bot]' }} steps: - name: Dependabot metadata id: metadata uses: dependabot/fetch-metadata@v2.5.0 with: github-token: "${{ secrets.GITHUB_TOKEN }}" - name: Auto-merge Dependabot PRs for semver-minor updates if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}} run: gh pr merge --auto --merge "$PR_URL" env: PR_URL: ${{github.event.pull_request.html_url}} GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - name: Auto-merge Dependabot PRs for semver-patch updates if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} run: gh pr merge --auto --merge "$PR_URL" env: PR_URL: ${{github.event.pull_request.html_url}} GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} ================================================ FILE: .github/workflows/deploy-docs.yml ================================================ # Sample workflow for building and deploying a Next.js site to GitHub Pages # # To get started with Next.js see: https://nextjs.org/docs/getting-started # name: Deploy Docs site to Pages on: # Runs on pushes targeting the default branch push: branches: ["docs"] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: contents: read pages: write id-token: write # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: group: "pages" cancel-in-progress: false jobs: # Build job build: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Detect package manager id: detect-package-manager run: | if [ -f "${{ github.workspace }}/yarn.lock" ]; then echo "manager=yarn" >> $GITHUB_OUTPUT echo "command=install" >> $GITHUB_OUTPUT echo "runner=yarn" >> $GITHUB_OUTPUT exit 0 elif [ -f "${{ github.workspace }}/package.json" ]; then echo "manager=npm" >> $GITHUB_OUTPUT echo "command=ci" >> $GITHUB_OUTPUT echo "runner=npx --no-install" >> $GITHUB_OUTPUT exit 0 else echo "Unable to determine package manager" exit 1 fi - name: Setup Node uses: actions/setup-node@v6 with: node-version: "22" cache: ${{ steps.detect-package-manager.outputs.manager }} # - name: Setup Pages # uses: actions/configure-pages@v3 # with: # # Automatically inject basePath in your Next.js configuration file and disable # # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized). # # # # You may remove this line if you want to manage the configuration yourself. # static_site_generator: next - name: Restore cache uses: actions/cache@v4 with: path: | .next/cache # Generate a new cache whenever packages or source files change. key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} # If source files changed but packages didn't, rebuild from a prior cache. restore-keys: | ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}- - name: Install dependencies run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} - name: Build with Next.js run: ${{ steps.detect-package-manager.outputs.runner }} next build - name: Static HTML export with Next.js run: ${{ steps.detect-package-manager.outputs.runner }} next export - name: Upload artifact uses: actions/upload-pages-artifact@v4 with: path: ./out # Deployment job deploy: environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest needs: build steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 ================================================ FILE: .github/workflows/fix-php-code-style-issues.yml ================================================ name: Fix PHP code style issues on: push: paths: - '**.php' permissions: contents: write jobs: php-code-styling: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} - name: Fix PHP code style issues uses: aglipanci/laravel-pint-action@2.6 - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v7 with: commit_message: Fix styling ================================================ FILE: .github/workflows/run-tests.yml ================================================ name: run-tests on: push: branches: [main] pull_request: branches: [main] jobs: test: runs-on: ${{ matrix.os }} strategy: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] # php: [8.1, 8.2] laravel: [10.*, 11.*, 12.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* testbench: 8.* php: 8.1 - laravel: 11.* testbench: 9.* php: 8.2 - laravel: 12.* testbench: 10.* php: 8.3 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo coverage: none - name: Setup problem matchers run: | echo "::add-matcher::${{ runner.tool_cache }}/php.json" echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Install dependencies run: | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: List Installed Dependencies run: composer show -D - name: Execute tests run: vendor/bin/pest --ci ================================================ FILE: .github/workflows/update-changelog.yml ================================================ name: "Update Changelog" on: release: types: [released] permissions: contents: write jobs: update: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: ref: main - name: Update Changelog uses: stefanzweifel/changelog-updater-action@v1 with: latest-version: ${{ github.event.release.name }} release-notes: ${{ github.event.release.body }} - name: Commit updated CHANGELOG uses: stefanzweifel/git-auto-commit-action@v7 with: branch: main commit_message: Update CHANGELOG file_pattern: CHANGELOG.md ================================================ FILE: .gitignore ================================================ .idea .phpunit.cache build composer.lock coverage docs phpunit.xml phpstan.neon testbench.yaml vendor node_modules .next ================================================ FILE: CHANGELOG.md ================================================ # Changelog All notable changes to `laravel-updater` will be documented in this file. ## v1.3.0 - 2025-04-01 ### What's Changed * Bump aglipanci/laravel-pint-action from 2.4 to 2.5 by @dependabot in https://github.com/salahhusa9/laravel-updater/pull/62 * Update dependency illuminate/contracts to **v12** by @renovate in https://github.com/salahhusa9/laravel-updater/pull/63 * Update dependency node to v22 by @renovate in https://github.com/salahhusa9/laravel-updater/pull/65 * chore(deps): update dependency orchestra/testbench to v10 by @renovate in https://github.com/salahhusa9/laravel-updater/pull/64 > Thank you for using this package! ❤️ Consider supporting my work: https://github.com/sponsors/salahhusa9 **Full Changelog**: https://github.com/salahhusa9/laravel-updater/compare/v1.2.4...v1.3.0 ## v1.2.4 - 2025-01-27 ### What's Changed * Update dependabot/fetch-metadata action to v2.3.0 by @renovate in https://github.com/salahhusa9/laravel-updater/pull/58 * Update Updater.php to merge before and after update pipelines with existing pipelines by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/60 Thank you for using this package! ❤️ Consider supporting my work: https://github.com/sponsors/salahhusa9 **Full Changelog**: https://github.com/salahhusa9/laravel-updater/compare/v1.2.3...v1.2.4 ## v1.2.3 - 2024-07-17 ### What's Changed * Update dependabot/fetch-metadata action to v2.2.0 by @renovate in https://github.com/salahhusa9/laravel-updater/pull/52 * [Add sponsor message and link in Update Command](https://github.com/sponsors/salahhusa9) > Thank you for using this package! ❤️ Consider supporting my work: https://github.com/sponsors/salahhusa9 **Full Changelog**: https://github.com/salahhusa9/laravel-updater/compare/v1.2.2...v1.2.3 ## v1.2.2 - 2024-06-25 **Full Changelog**: https://github.com/salahhusa9/laravel-updater/compare/v1.2.1...v1.2.2 ## v1.2.1 - 2024-06-08 ### What's Changed * Update laravel in github action by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/44 * Bump aglipanci/laravel-pint-action from 2.3.1 to 2.4 by @dependabot in https://github.com/salahhusa9/laravel-updater/pull/45 * Update dependabot/fetch-metadata action to v2.1.0 by @renovate in https://github.com/salahhusa9/laravel-updater/pull/46 * Remove symfony component process executable finder by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/50 **Full Changelog**: https://github.com/salahhusa9/laravel-updater/compare/v1.2.0...v1.2.1 ## v1.2.0 - 2024-04-01 ### What's Changed * Git checkout throw away local modifications by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/43 * Update dependency orchestra/testbench to v9 by @renovate in https://github.com/salahhusa9/laravel-updater/pull/39 * Update dependabot/fetch-metadata action to v1.7.0 by @renovate in https://github.com/salahhusa9/laravel-updater/pull/40 * Update dependabot/fetch-metadata action to v2 by @renovate in https://github.com/salahhusa9/laravel-updater/pull/41 **Full Changelog**: https://github.com/salahhusa9/laravel-updater/compare/v1.1.0...v1.2.0 ## v1.1.0 - 2024-03-12 ### What's Changed * Add support of Laravel 11 by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/38 **Full Changelog**: https://github.com/salahhusa9/laravel-updater/compare/v1.0.2...v1.1.0 ## v1.0.2 - 2024-02-10 ### What's Changed * new ui output by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/37 **Full Changelog**: https://github.com/salahhusa9/laravel-updater/compare/v1.0.1...v1.0.2 ## v1.0.1 - 2024-02-03 ### What's Changed * Update actions/upload-pages-artifact action to v3 by @renovate in https://github.com/salahhusa9/laravel-updater/pull/28 * Update actions/deploy-pages action to v4 by @renovate in https://github.com/salahhusa9/laravel-updater/pull/27 * Bump aglipanci/laravel-pint-action from 2.3.0 to 2.3.1 by @dependabot in https://github.com/salahhusa9/laravel-updater/pull/30 * remove migration file and in configure Package by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/36 * Bump actions/cache from 3 to 4 by @dependabot in https://github.com/salahhusa9/laravel-updater/pull/32 * [Update exception classes to use RuntimeException instead of Exception](https://github.com/salahhusa9/laravel-updater/commit/705485c97efaa161da81b3cc825e2b20c1f43d6f) **Full Changelog**: https://github.com/salahhusa9/laravel-updater/compare/v1.0.0...v1.0.1 ## Laravel Updater v1 - 2023-11-21 ### What's Changed - Update actions/setup-node action to v4 by @renovate in https://github.com/salahhusa9/laravel-updater/pull/14 - Git failed exception by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/17 - Tests pipelines by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/18 - Tests Repository Source by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/19 - Command test by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/20 - updater facade tests by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/21 - Remove Git Pull in update by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/22 **Full Changelog**: https://github.com/salahhusa9/laravel-updater/compare/v0.0.1...v1.0.0 ## Laravel Updater Beta - 2023-10-31 ### What's Changed - Bump aglipanci/laravel-pint-action from 2.2.0 to 2.3.0 by @dependabot in https://github.com/salahhusa9/laravel-updater/pull/1 - Patch 1 by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/5 - Pipelines by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/6 - Configure Renovate by @renovate in https://github.com/salahhusa9/laravel-updater/pull/4 - Bump stefanzweifel/git-auto-commit-action from 4 to 5 by @dependabot in https://github.com/salahhusa9/laravel-updater/pull/2 - Bump actions/checkout from 3 to 4 by @dependabot in https://github.com/salahhusa9/laravel-updater/pull/3 - Interface pipeline by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/10 - Fun docs by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/11 - Test by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/12 - Output in run by @salahhusa9 in https://github.com/salahhusa9/laravel-updater/pull/13 ### New Contributors - @dependabot made their first contribution in https://github.com/salahhusa9/laravel-updater/pull/1 - @salahhusa9 made their first contribution in https://github.com/salahhusa9/laravel-updater/pull/5 - @renovate made their first contribution in https://github.com/salahhusa9/laravel-updater/pull/4 **Full Changelog**: https://github.com/salahhusa9/laravel-updater/commits/v0.0.1 ================================================ FILE: LICENSE.md ================================================ The MIT License (MIT) Copyright (c) salahhusa9 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Laravel Updater [![Latest Version on Packagist](https://img.shields.io/packagist/v/salahhusa9/laravel-updater.svg?style=flat-square)](https://packagist.org/packages/salahhusa9/laravel-updater) ![laravel](https://img.shields.io/badge/Laravel-10%7C11%7C12-red) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/salahhusa9/laravel-updater/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/salahhusa9/laravel-updater/actions?query=workflow%3Arun-tests+branch%3Amain) [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/salahhusa9/laravel-updater/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/salahhusa9/laravel-updater/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/salahhusa9/laravel-updater.svg?style=flat-square)](https://packagist.org/packages/salahhusa9/laravel-updater) This is a useful package for update your laravel project with one command/click. ## Support us You can support us by [buying me a coffee](https://github.com/sponsors/salahhusa9) ☕️ . ## Docs You find the **docs** in [salahhusa9.com/laravel-updater](https://salahhusa9.com/laravel-updater) ## Testing ```bash composer test ``` ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. ## Contributing Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## Security Vulnerabilities Please review [our security policy](../../security/policy) on how to report security vulnerabilities. ## Credits - [salahhusa9](https://github.com/salahhusa9) - [All Contributors](../../contributors) ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information. ================================================ FILE: composer.json ================================================ { "name": "salahhusa9/laravel-updater", "description": "Laravel Updater is a simple yet powerful package for updater your Laravel applications. It makes it easy to upgrade your application to the latest version with just one command.", "keywords": [ "salahhusa9", "laravel", "laravel-updater", "laravel package", "laravel self updater", "laravel package self updater", "laravel package updater", "laravel package update", "laravel package update itself" ], "homepage": "https://github.com/salahhusa9/laravel-updater", "license": "MIT", "authors": [ { "name": "salahhusa9", "email": "salahhusa9@gmail.com", "role": "Developer" } ], "require": { "php": "^8.1|^8.2", "guzzlehttp/guzzle": "^7.8", "illuminate/contracts": "^10.0|^11.0|^12.0", "spatie/laravel-package-tools": "^1.0", "symfony/process": "^6.3|^7.0" }, "require-dev": { "laravel/pint": "^1.0", "nunomaduro/collision": "^7.8|^8.0", "orchestra/testbench": "10.1.0", "pestphp/pest": "^2.20|^3.0", "pestphp/pest-plugin-arch": "^2.0|^3.0", "pestphp/pest-plugin-laravel": "^2.0|^3.0" }, "autoload": { "psr-4": { "Salahhusa9\\Updater\\": "src/", "Salahhusa9\\Updater\\Database\\Factories\\": "database/factories/" } }, "autoload-dev": { "psr-4": { "Salahhusa9\\Updater\\Tests\\": "tests/", "Workbench\\App\\": "workbench/app/" } }, "scripts": { "post-autoload-dump": "@composer run prepare", "clear": "@php vendor/bin/testbench package:purge-laravel-updater --ansi", "prepare": "@php vendor/bin/testbench package:discover --ansi", "build": [ "@composer run prepare", "@php vendor/bin/testbench workbench:build --ansi" ], "start": [ "Composer\\Config::disableProcessTimeout", "@composer run build", "@php vendor/bin/testbench serve" ], "test": "vendor/bin/pest", "test-coverage": "vendor/bin/pest --coverage", "format": "vendor/bin/pint" }, "config": { "sort-packages": true, "allow-plugins": { "pestphp/pest-plugin": true } }, "extra": { "laravel": { "providers": [ "Salahhusa9\\Updater\\UpdaterServiceProvider" ], "aliases": { "Updater": "Salahhusa9\\Updater\\Facades\\Updater" } } }, "minimum-stability": "dev", "prefer-stable": true } ================================================ FILE: config/updater.php ================================================ 'git', 'repository_source' => \Salahhusa9\Updater\RepositorySource\GithubRepository::class, 'github_token' => env('GITHUB_TOKEN'), 'github_username' => env('GITHUB_USERNAME'), 'github_repository' => env('GITHUB_REPOSITORY'), 'github_timeout' => 100, 'maintenance_mode' => true, 'maintenance_mode_secret' => env('MAINTENANCE_MODE_SECRET', false), 'before_update_pipelines' => [ // you can add your own pipelines here ], // run php artisan migrate after update? 'migrate' => false, // run seeders after update? 'seeders' => [ // '\Database\Seeders\DatabaseSeeder::class', ], // run php artisan cache:clear after update? 'cache:clear' => false, // run php artisan view:clear after update? 'view:clear' => false, // run php artisan config:clear after update? 'config:clear' => false, // run php artisan route:clear after update? 'route:clear' => false, // run php artisan optimize after update? 'optimize' => false, 'after_update_pipelines' => [ // you can add your own pipelines here ], ]; ================================================ FILE: database/factories/ModelFactory.php ================================================ tests ./src ================================================ FILE: renovate.json ================================================ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:base" ] } ================================================ FILE: resources/views/.gitkeep ================================================ ================================================ FILE: src/Commands/CheckCommand.php ================================================ components->info('No new version available'); return self::SUCCESS; } $this->components->info('New version available: '.$newVersionAvailable['latest_version']); event(new NewVersionAvailable($newVersionAvailable['current_version'], $newVersionAvailable['latest_version'])); return self::SUCCESS; } } ================================================ FILE: src/Commands/UpdaterCommand.php ================================================ components->error('No new version available'); return self::FAILURE; } $this->components->info('Updating to version '.$newVersionAvailable['latest_version']); Updater::update(output: function ($message) { $this->components->task($message); }); $this->components->twoColumnDetail('Application updated', Updater::getCurrentVersion()); $this->components->info(' Thank you for using this package! ❤️ Consider supporting my work: https://github.com/sponsors/salahhusa9 '); return self::SUCCESS; } } ================================================ FILE: src/Contracts/Pipeline.php ================================================ currentVersion = $currentVersion; $this->newVersion = $newVersion; } } ================================================ FILE: src/Events/UpdateFailed.php ================================================ pastVersion = $pastVersion; $this->newVersion = $newVersion; $this->exception = $exception; } } ================================================ FILE: src/Events/UpdatedSuccessfully.php ================================================ pastVersion = $pastVersion; $this->newVersion = $newVersion; } } ================================================ FILE: src/Exceptions/GitFailedException.php ================================================ failed()) { throw new GitFailedException('this command failed: '.$process->command().' with message: '.$process->errorOutput()); } return trim($process->output()); } /** * getCurrentBranch * * @return string * * @throws GitFailedException */ public static function getCurrentBranch() { $process = Process::run(self::gitPath().' rev-parse --abbrev-ref HEAD'); if ($process->failed()) { throw new GitFailedException('this command failed: '.$process->command().' with message: '.$process->errorOutput()); } return trim($process->output()); } /** * getCurrentTag * * @return string * * @throws GitFailedException */ public static function getCurrentTag() { $process = Process::run(self::gitPath().' describe --tags --abbrev=0'); if ($process->failed()) { throw new GitFailedException('this command failed: '.$process->command().' with message: '.$process->errorOutput()); } return trim($process->output()); } /** * auth * * @return string * * @throws GitFailedException */ public static function auth() { $process = Process::run(self::gitPath().' remote set-url origin https://'.config('updater.github_username').':'.config('updater.github_token').'@github.com/'.config('updater.github_username').'/'.config('updater.github_repository').'.git'); if ($process->failed()) { throw new GitFailedException('this command failed: '.$process->command().' with message: '.$process->errorOutput()); } return trim($process->output()); } /** * pull * * @return string * * @throws GitFailedException */ public static function pull() { $process = Process::run(self::gitPath().' pull'); if ($process->failed()) { throw new GitFailedException('this command failed: '.$process->command().' with message: '.$process->errorOutput()); } return trim($process->output()); } /** * checkout * * @param mixed $branch * @return string * * @throws GitFailedException */ public static function checkout($branch) { $process = Process::run(self::gitPath().' checkout '.$branch.' -f'); if ($process->failed()) { throw new GitFailedException('this command failed: '.$process->command().' with message: '.$process->errorOutput()); } return trim($process->output()); } /** * fetch * * @return string * * @throws GitFailedException */ public static function fetch() { $process = Process::run(self::gitPath().' fetch'); if ($process->failed()) { throw new GitFailedException('this command failed: '.$process->command().' with message: '.$process->errorOutput()); } return trim($process->output()); } /** * gitPath * * @return string */ public static function gitPath() { $gitPath = config('updater.git_path', 'git'); return $gitPath; } } ================================================ FILE: src/Helpers/Helper.php ================================================ true, ]); if (is_callable($content['output'])) { call_user_func($content['output'], 'Migrated!'); } return $next($content); } } ================================================ FILE: src/Pipelines/ArtisanCallOptimizePipe.php ================================================ $class, '--force' => true, ]); } if (is_callable($content['output'])) { call_user_func($content['output'], 'Seeded!'); } return $next($content); } } ================================================ FILE: src/RepositorySource/GithubRepository.php ================================================ checkConfig(); return isset($this->getLatestVersionData()['message']) ? throw new \Exception($this->getLatestVersionData()['message']) : $this->getLatestVersionData()['tag_name']; } /** * getLatestVersionData * * @return Illuminate\Support\Collection */ public function getLatestVersionData(): \Illuminate\Support\Collection { $this->checkConfig(); $response = Http::withHeaders([ 'Accept' => 'application/vnd.github.v3+json', 'Authorization' => 'Bearer '.config('updater.github_token'), 'X-GitHub-Api-Version' => '2022-11-28', ]) ->timeout(config('updater.github_timeout', 100)) ->get('https://api.github.com/repos/'.config('updater.github_username').'/'.config('updater.github_repository').'/releases/latest'); return $response->collect(); } /** * getVersions */ public function getVersions(): array { $this->checkConfig(); $versionsData = $this->getVersionsData(); if (isset($versionsData['message'])) { throw new \Exception($versionsData['message']); } return $versionsData->map(function ($version) { return $version['tag_name']; })->toArray(); } /** * getVersionsData * * @return Illuminate\Support\Collection */ public function getVersionsData(): \Illuminate\Support\Collection { $this->checkConfig(); $response = Http::withHeaders([ 'Accept' => 'application/vnd.github.v3+json', 'Authorization' => 'Bearer '.config('updater.github_token'), 'X-GitHub-Api-Version' => '2022-11-28', ]) ->timeout(config('updater.github_timeout', 100)) ->get('https://api.github.com/repos/'.config('updater.github_username').'/'.config('updater.github_repository').'/releases'); return $response->collect(); } /** * checkConfig * * @return void */ public function checkConfig() { if (config('updater.github_token') == null) { throw new GithubConfigException('Please set GITHUB_TOKEN in .env file'); } if (config('updater.github_username') == null) { throw new GithubConfigException('Please set GITHUB_USERNAME in .env file'); } if (config('updater.github_repository') == null) { throw new GithubConfigException('Please set GITHUB_REPOSITORY in .env file'); } return true; } } ================================================ FILE: src/Updater.php ================================================ output = $output; if (is_array($this->newVersionAvailable())) { return $this->updateTo($this->getLatestVersion()); } else { return 'No new version available'; } } /** * updateTo * * @param mixed $version */ private function updateTo($version): string { if (is_array($this->newVersionAvailable()) && $this->newVersionAvailable()['current_version'] != $version) { $current_version_in_past = $this->newVersionAvailable()['current_version']; try { if (config('updater.maintenance_mode', false)) { $this->output('Maintenance mode is on, turning it on'); Artisan::call( 'down', config('updater.maintenance_mode_secret', false) ? [ '--secret' => config('updater.maintenance_mode_secret', false), ] : [] ); } $pipelines = [ Pipelines\GitPipe::class, ]; if (config('updater.before_update_pipelines', false) && is_array(config('updater.before_update_pipelines')) && count(config('updater.before_update_pipelines')) > 0) { $pipelines = array_merge($pipelines, config('updater.before_update_pipelines')); } if (config('updater.migrate', false)) { $pipelines[] = Pipelines\ArtisanCallMigratePipe::class; } if (config('updater.seeders', false) && is_array(config('updater.seeders')) && count(config('updater.seeders')) > 0) { $pipelines[] = Pipelines\SeedersPipe::class; } if (config('updater.cache:clear', false)) { $pipelines[] = Pipelines\ArtisanCallCacheClearPipe::class; } if (config('updater.view:clear', false)) { $pipelines[] = Pipelines\ArtisanCallViewClearPipe::class; } if (config('updater.config:clear', false)) { $pipelines[] = Pipelines\ArtisanCallConfigClearPipe::class; } if (config('updater.route:clear', false)) { $pipelines[] = Pipelines\ArtisanCallRouteClearPipe::class; } if (config('updater.optimize', false)) { $pipelines[] = Pipelines\ArtisanCallOptimizePipe::class; } if (config('updater.after_update_pipelines', false) && is_array(config('updater.after_update_pipelines')) && count(config('updater.after_update_pipelines')) > 0) { $pipelines = array_merge($pipelines, config('updater.after_update_pipelines')); } // check if pipelines is array and not empty and items is implemented Pipeline contract if (is_array($pipelines) && count($pipelines) > 0) { foreach ($pipelines as $pipeline) { if (! is_subclass_of($pipeline, \Salahhusa9\Updater\Contracts\Pipeline::class)) { throw new \RuntimeException('Pipeline '.$pipeline.' is not implemented Pipeline contract:'.\Salahhusa9\Updater\Contracts\Pipeline::class); } } } else { throw new \RuntimeException('Pipelines is not array or empty'); } $this->output('Start Updating to version '.$version); Pipeline::send([ 'current_version' => $this->getCurrentVersion(), 'new_version' => $version, 'output' => $this->output, ]) ->through($pipelines) ->then( function ($content) { return $content; } ); if (config('updater.maintenance_mode', false)) { $this->output('Maintenance mode is on, turning it off'); Artisan::call('up'); } event(new Events\UpdatedSuccessfully($current_version_in_past, $version)); return 'Updated to version '.$version; } catch (\Throwable $th) { if (config('updater.maintenance_mode', false)) { $this->output('Maintenance mode is on, turning it off'); Artisan::call('up'); } event(new Events\UpdateFailed($current_version_in_past, $version, $th->getMessage())); throw $th; } } else { $this->output('No new version available'); return 'No new version available'; } } /** * output * * @param mixed $message */ public function output($message): void { if (is_callable($this->output)) { call_user_func($this->output, $message); } } /** * newVersionAvailable * * @return bool */ public function newVersionAvailable(): bool|array { $currentVersion = $this->getCurrentVersion(); $latestVersion = $this->getLatestVersion(); if ($currentVersion != $latestVersion) { return [ 'current_version' => $currentVersion, 'latest_version' => $latestVersion, ]; } return false; } /** * getCurrentVersion */ public function getCurrentVersion(): string { $branch = Git::getCurrentBranch(); $tag = Git::getCurrentTag(); $head = $branch != 'HEAD' ? $branch : $tag; return $head; } /** * getLatestVersion */ public function getLatestVersion(): string { return Cache::remember('latest_version', 5, function () { return app(Repository::class)->getLatestVersion(); }); } /** * getLatestVersionData */ public function getLatestVersionData(): array { return Cache::remember('latest_version_data', 5, function () { return app(Repository::class)->getLatestVersionData()->toArray(); }); } /** * versions */ public function versions(): array { return Cache::remember('versions', 5, function () { return app(Repository::class)->getVersions(); }); } } ================================================ FILE: src/UpdaterServiceProvider.php ================================================ name('laravel-updater') ->hasConfigFile() ->hasViews() ->hasCommands(UpdaterCommand::class, CheckCommand::class); $this->app->singleton(Repository::class, function () { return new (config('updater.repository_source', GithubRepository::class))(); }); } } ================================================ FILE: tests/ArchTest.php ================================================ expect(['dd', 'dump', 'ray']) ->each->not->toBeUsed(); ================================================ FILE: tests/Commands/CheckCommandTest.php ================================================ once()->andReturn(false); $this->artisan('updater:check') ->expectsOutputToContain('No new version available') ->assertExitCode(CheckCommand::SUCCESS); } /** @test */ public function it_shows_a_message_if_a_new_version_is_available() { Updater::shouldReceive('newVersionAvailable')->once()->andReturn([ 'current_version' => '1.0.0', 'latest_version' => '1.1.0', ]); $this->artisan('updater:check') ->expectsOutputToContain('New version available: 1.1.0') ->assertExitCode(CheckCommand::SUCCESS); } /** @test */ public function it_fires_a_new_version_available_event_if_a_new_version_is_available() { Event::fake(); Updater::shouldReceive('newVersionAvailable')->once()->andReturn([ 'current_version' => '1.0.0', 'latest_version' => '1.1.0', ]); $this->artisan('updater:check') ->expectsOutputToContain('New version available: 1.1.0'); Event::assertDispatched(NewVersionAvailable::class, function ($event) { return $event->currentVersion === '1.0.0' && $event->newVersion === '1.1.0'; }); } } ================================================ FILE: tests/Commands/UpdaterCommandTest.php ================================================ once() ->andReturn([ 'current_version' => 'v1.0.0', 'latest_version' => 'v1.0.1', ]); Http::fake([ 'https://api.github.com/repos/salahhusa9/laravel-updater/releases/latest' => Http::response([ 'tag_name' => 'v1.0.1', ], 200), ]); // Mock the Updater facade to return the update command Updater::shouldReceive('getCurrentVersion') ->once() ->andReturn('v1.0.0'); // Mock the Updater facade to return the update command Updater::shouldReceive('update') ->once() ->andReturn('Updated to version v1.0.1'); // Call the UpdaterCommand $this->artisan('updater:update') ->expectsOutputToContain('Updating to version v1.0.1') ->expectsOutputToContain('Application updated') // in real life this should be v1.0.1 but we mock it to v1.0.0 // ->expectsOutputToContain('v1.0.0') // in real life this should be v1.0.1 but we mock it to v1.0.0 // ->expectsOutputToContain('You are now on version') // in real life this should be v1.0.1 but we mock it to v1.0.0 ->assertExitCode(0); } /** @test */ public function it_does_not_update_when_no_new_version_available() { // Mock the Updater facade to return no new version Updater::shouldReceive('newVersionAvailable') ->once() ->andReturn(false); // Call the UpdaterCommand $this->artisan('updater:update') ->expectsOutputToContain('No new version available') ->assertExitCode(1); } } ================================================ FILE: tests/ExampleTest.php ================================================ toBeTrue(); }); ================================================ FILE: tests/GitTest.php ================================================ Process::result('commit-hash'), ]); // change config git_path to git, because git path changed between windows and linux config()->set('updater.git_path', 'git'); $this->assertEquals('commit-hash', Salahhusa9\Updater\Helpers\Git::getCurrentCommit()); } public function test_get_current_commit_failed(): void { $this->expectException(Salahhusa9\Updater\Exceptions\GitFailedException::class); $this->expectExceptionMessage('Test error output'); Process::fake([ 'git log --pretty="%h" -n1 HEAD' => Process::result( output: 'Test output', errorOutput: 'Test error output', exitCode: 1, ), ]); // change config git_path to git, because git path changed between windows and linux config()->set('updater.git_path', 'git'); Salahhusa9\Updater\Helpers\Git::getCurrentCommit(); } public function test_get_current_branch(): void { Process::fake([ 'git rev-parse --abbrev-ref HEAD' => Process::result('branch-name'), ]); // change config git_path to git, because git path changed between windows and linux config()->set('updater.git_path', 'git'); $this->assertEquals('branch-name', Salahhusa9\Updater\Helpers\Git::getCurrentBranch()); } public function test_get_current_branch_failed(): void { $this->expectException(Salahhusa9\Updater\Exceptions\GitFailedException::class); $this->expectExceptionMessage('Test error output'); Process::fake([ 'git rev-parse --abbrev-ref HEAD' => Process::result( output: 'Test output', errorOutput: 'Test error output', exitCode: 1, ), ]); // change config git_path to git, because git path changed between windows and linux config()->set('updater.git_path', 'git'); Salahhusa9\Updater\Helpers\Git::getCurrentBranch(); } public function test_get_current_tag(): void { Process::fake([ 'git describe --tags --abbrev=0' => Process::result('tag-name'), ]); // change config git_path to git, because git path changed between windows and linux config()->set('updater.git_path', 'git'); $this->assertEquals('tag-name', Salahhusa9\Updater\Helpers\Git::getCurrentTag()); } public function test_get_current_tag_failed(): void { $this->expectException(Salahhusa9\Updater\Exceptions\GitFailedException::class); $this->expectExceptionMessage('Test error output'); Process::fake([ 'git describe --tags --abbrev=0' => Process::result( output: 'Test output', errorOutput: 'Test error output', exitCode: 1, ), ]); // change config git_path to git, because git path changed between windows and linux config()->set('updater.git_path', 'git'); Salahhusa9\Updater\Helpers\Git::getCurrentTag(); } public function test_get_git_path(): void { config()->set('updater.git_path', 'git'); $this->assertEquals('git', Salahhusa9\Updater\Helpers\Git::gitPath()); } public function test_git_auth(): void { config()->set('updater.github_token', 'token'); config()->set('updater.github_username', 'username'); config()->set('updater.github_repository', 'repository'); Process::fake([ 'git remote set-url origin https://'.config('updater.github_username').':'.config('updater.github_token').'@github.com/'.config('updater.github_username').'/'.config('updater.github_repository').'.git' => Process::result(''), ]); config()->set('updater.git_path', 'git'); $this->assertEquals('', Salahhusa9\Updater\Helpers\Git::auth()); } public function test_git_auth_failed(): void { $this->expectException(Salahhusa9\Updater\Exceptions\GitFailedException::class); $this->expectExceptionMessage('Test error output'); Process::fake([ 'git remote set-url origin https://'.config('updater.github_username').':'.config('updater.github_token').'@github.com/'.config('updater.github_username').'/'.config('updater.github_repository').'.git' => Process::result( output: 'Test output', errorOutput: 'Test error output', exitCode: 1, ), ]); config()->set('updater.git_path', 'git'); Salahhusa9\Updater\Helpers\Git::auth(); } public function test_git_pull(): void { Process::fake([ 'git pull' => Process::result(''), ]); config()->set('updater.git_path', 'git'); $this->assertEquals('', Salahhusa9\Updater\Helpers\Git::pull()); } public function test_git_pull_failed(): void { $this->expectException(Salahhusa9\Updater\Exceptions\GitFailedException::class); $this->expectExceptionMessage('Test error output'); Process::fake([ 'git pull' => Process::result( output: 'Test output', errorOutput: 'Test error output', exitCode: 1, ), ]); config()->set('updater.git_path', 'git'); Salahhusa9\Updater\Helpers\Git::pull(); } public function test_git_checkout(): void { Process::fake([ 'git checkout branch-name -f' => Process::result(''), ]); config()->set('updater.git_path', 'git'); $this->assertEquals('', Salahhusa9\Updater\Helpers\Git::checkout('branch-name')); } public function test_git_checkout_failed(): void { $this->expectException(Salahhusa9\Updater\Exceptions\GitFailedException::class); $this->expectExceptionMessage('Test error output'); Process::fake([ 'git checkout branch-name -f' => Process::result( output: 'Test output', errorOutput: 'Test error output', exitCode: 1, ), ]); config()->set('updater.git_path', 'git'); Salahhusa9\Updater\Helpers\Git::checkout('branch-name'); } public function test_git_fetch(): void { Process::fake([ 'git fetch' => Process::result(''), ]); config()->set('updater.git_path', 'git'); $this->assertEquals('', Salahhusa9\Updater\Helpers\Git::fetch()); } public function test_git_fetch_failed(): void { $this->expectException(Salahhusa9\Updater\Exceptions\GitFailedException::class); $this->expectExceptionMessage('Test error output'); Process::fake([ 'git fetch' => Process::result( output: 'Test output', errorOutput: 'Test error output', exitCode: 1, ), ]); config()->set('updater.git_path', 'git'); Salahhusa9\Updater\Helpers\Git::fetch(); } } ================================================ FILE: tests/HelperTest.php ================================================ assertEquals($helper->isVersion('v1.2.3'), 1); } public function test_is_version_returns_false_for_invalid_version() { $helper = new Helper; $this->assertEqualsCanonicalizing($helper->isVersion('invalid-version'), 0); } } ================================================ FILE: tests/Pest.php ================================================ in(__DIR__); ================================================ FILE: tests/Pipelines/ArtisanCallCacheClearPipeTest.php ================================================ Process::result('cache:clear'), ]); $messages = [ 'Start clearing cache', 'Cache cleared!', ]; $content = [ 'output' => function ($message) use ($messages) { $this->assertTrue(in_array($message, $messages)); }, ]; $next = function ($result) use ($content) { $this->assertEquals($result, $content); }; app()->make(ArtisanCallCacheClearPipe::class)->handle($content, $next); } } ================================================ FILE: tests/Pipelines/ArtisanCallConfigClearPipeTest.php ================================================ Process::result('config:clear'), ]); $messages = [ 'Start clearing config cache', 'Config cache cleared!', ]; $content = [ 'output' => function ($message) use ($messages) { $this->assertTrue(in_array($message, $messages)); }, ]; $next = function ($result) use ($content) { $this->assertEquals($result, $content); }; app()->make(ArtisanCallConfigClearPipe::class)->handle($content, $next); } } ================================================ FILE: tests/Pipelines/ArtisanCallMigratePipeTest.php ================================================ Process::result('migrate'), ]); $messages = [ 'Start migrating', 'Migrated!', ]; $content = [ 'output' => function ($message) use ($messages) { $this->assertTrue(in_array($message, $messages)); }, ]; $next = function ($result) use ($content) { $this->assertEquals($result, $content); }; app()->make(ArtisanCallMigratePipe::class)->handle($content, $next); } } ================================================ FILE: tests/Pipelines/ArtisanCallOptimizePipeTest.php ================================================ Process::result('optimize'), ]); $messages = [ 'Start optimizing', 'Optimized!', ]; $content = [ 'output' => function ($message) use ($messages) { $this->assertTrue(in_array($message, $messages)); }, ]; $next = function ($result) use ($content) { $this->assertEquals($result, $content); }; app()->make(ArtisanCallOptimizePipe::class)->handle($content, $next); } } ================================================ FILE: tests/Pipelines/ArtisanCallRouteClearPipeTest.php ================================================ Process::result('route:clear'), ]); $messages = [ 'Start clearing route cache', 'Route cache cleared!', ]; $content = [ 'output' => function ($message) use ($messages) { $this->assertTrue(in_array($message, $messages)); }, ]; $next = function ($result) use ($content) { $this->assertEquals($result, $content); }; app()->make(ArtisanCallRouteClearPipe::class)->handle($content, $next); } } ================================================ FILE: tests/Pipelines/ArtisanCallViewClearPipeTest.php ================================================ Process::result('view:clear'), ]); $messages = [ 'Start clearing view cache', 'View cache cleared!', ]; $content = [ 'output' => function ($message) use ($messages) { $this->assertTrue(in_array($message, $messages)); }, ]; $next = function ($result) use ($content) { $this->assertEquals($result, $content); }; app()->make(ArtisanCallViewClearPipe::class)->handle($content, $next); } } ================================================ FILE: tests/Pipelines/GitPipeTest.php ================================================ Process::result('1.0.0'), // this for return $version in getCurrentVersion() ]); $messages = [ 'Start downloading version 1.0.0', 'Checkout success', ]; $content = [ 'output' => function ($message) use ($messages) { $this->assertTrue(in_array($message, $messages)); }, 'new_version' => '1.0.0', ]; $next = function ($result) use ($content) { $this->assertEquals($result, $content); }; app()->make(GitPipe::class)->handle($content, $next); } public function test_run_handle_with_error() { $this->expectException(\Exception::class); Process::fake([ '*' => Process::result('error'), // this for throw new \Exception('git checkout failed: '.$checkout); becouse $checkout = Git::checkout($version); return error ]); $messages = [ 'Start downloading version 1.0.0', 'git checkout failed: error', ]; $content = [ 'output' => function ($message) use ($messages) { $this->assertTrue(in_array($message, $messages)); }, 'new_version' => '1.0.0', ]; $next = function ($result) use ($content) { $this->assertEquals($result, $content); }; app()->make(GitPipe::class)->handle($content, $next); } } ================================================ FILE: tests/Pipelines/SeedersPipeTest.php ================================================ function ($message) use ($messages) { $this->assertTrue(in_array($message, $messages)); }, ]; $next = function ($result) use ($content) { $this->assertEquals($result, $content); }; config()->set('updater.seeders', [ ]); app()->make(SeedersPipe::class)->handle($content, $next); } } ================================================ FILE: tests/RepositorySource/GithubRepositoryTest.php ================================================ set('updater.github_token', 'salahhusa9'); config()->set('updater.github_username', 'salahhusa9'); config()->set('updater.github_repository', 'laravel-updater'); $githubRepository = new GithubRepository; $this->assertTrue($githubRepository->checkConfig()); } /** @test */ public function config_check_exception() { $this->expectException(GithubConfigException::class); $githubRepository = new GithubRepository; $this->assertTrue($githubRepository->checkConfig()); } /** @test */ public function it_can_get_latest_version() { // set env config()->set('updater.github_token', 'salahhusa9'); config()->set('updater.github_username', 'salahhusa9'); config()->set('updater.github_repository', 'laravel-updater'); Http::fake([ 'https://api.github.com/repos/salahhusa9/laravel-updater/releases/latest' => Http::response([ 'tag_name' => 'v1.0.0', ], 200), ]); $githubRepository = new GithubRepository; $this->assertEquals('v1.0.0', $githubRepository->getLatestVersion()); } /** @test */ public function it_can_get_latest_version_data() { // set env config()->set('updater.github_token', 'salahhusa9'); config()->set('updater.github_username', 'salahhusa9'); config()->set('updater.github_repository', 'laravel-updater'); Http::fake([ 'https://api.github.com/repos/salahhusa9/laravel-updater/releases/latest' => Http::response([ 'tag_name' => 'v1.0.0', ], 200), ]); $githubRepository = new GithubRepository; $this->assertIsArray($githubRepository->getLatestVersionData()->toArray()); } /** @test */ public function it_can_get_versions() { // set env config()->set('updater.github_token', 'salahhusa9'); config()->set('updater.github_username', 'salahhusa9'); config()->set('updater.github_repository', 'laravel-updater'); Http::fake([ 'https://api.github.com/repos/salahhusa9/laravel-updater/releases' => Http::response([ [ 'tag_name' => 'v1.0.0', ], [ 'tag_name' => 'v1.0.1', ], ], 200), ]); $githubRepository = new GithubRepository; $this->assertIsArray($githubRepository->getVersions()); } /** @test */ public function it_can_get_versions_data() { // set env config()->set('updater.github_token', 'salahhusa9'); config()->set('updater.github_username', 'salahhusa9'); config()->set('updater.github_repository', 'laravel-updater'); Http::fake([ 'https://api.github.com/repos/salahhusa9/laravel-updater/releases' => Http::response([ [ 'tag_name' => 'v1.0.0', ], [ 'tag_name' => 'v1.0.1', ], ], 200), ]); $githubRepository = new GithubRepository; $this->assertIsArray($githubRepository->getVersionsData()->toArray()); } } ================================================ FILE: tests/TestCase.php ================================================ 'Salahhusa9\\Updater\\Database\\Factories\\'.class_basename($modelName).'Factory' ); } protected function getPackageProviders($app) { return [ UpdaterServiceProvider::class, ]; } public function getEnvironmentSetUp($app) { config()->set('database.default', 'testing'); /* $migration = include __DIR__.'/../database/migrations/create_laravel-updater_table.php.stub'; $migration->up(); */ } } ================================================ FILE: tests/UpdaterTest.php ================================================ set('updater.git_path', 'git'); Process::fake([ 'git rev-parse --abbrev-ref HEAD' => 'HEAD', 'git describe --tags --abbrev=0' => '1.0.0', ]); $this->assertEquals('1.0.0', Updater::getCurrentVersion()); } public function test_get_latest_version() { Http::fake([ 'https://api.github.com/repos/salahhusa9/laravel-test/releases/latest' => Http::response([ 'tag_name' => '1.0.1', ], 200), ]); config()->set('updater.git_path', 'git'); config()->set('updater.github_token', 'salahhusa9'); config()->set('updater.github_username', 'salahhusa9'); config()->set('updater.github_repository', 'laravel-test'); Process::fake([ 'git rev-parse --abbrev-ref HEAD' => 'HEAD', 'git describe --tags --abbrev=0' => '1.0.0', 'git pull' => '', 'git checkout 1.0.1' => 'TEST', 'git remote set-url origin https://salahhusa9:salahhusa9@github.com/salahhusa9/laravel-test.git' => '', 'git fetch' => '', ]); $this->assertEquals('1.0.1', Updater::getLatestVersion()); } public function test_get_latest_version_data() { Http::fake([ 'https://api.github.com/repos/salahhusa9/laravel-test/releases/latest' => Http::response([ 'tag_name' => '1.0.1', ], 200), ]); config()->set('updater.git_path', 'git'); config()->set('updater.github_token', 'salahhusa9'); config()->set('updater.github_username', 'salahhusa9'); config()->set('updater.github_repository', 'laravel-test'); Process::fake([ 'git rev-parse --abbrev-ref HEAD' => 'HEAD', 'git describe --tags --abbrev=0' => '1.0.0', 'git pull' => '', 'git checkout 1.0.1' => 'TEST', 'git remote set-url origin https://salahhusa9:salahhusa9@github.com/salahhusa9/laravel-test.git' => '', 'git fetch' => '', ]); $this->assertEquals(['tag_name' => '1.0.1'], Updater::getLatestVersionData()); } public function test_versions() { Http::fake([ 'https://api.github.com/repos/salahhusa9/laravel-test/releases' => Http::response([ [ 'tag_name' => '1.0.0', ], [ 'tag_name' => '1.1.0', ], [ 'tag_name' => '2.0.0', ], ], 200), ]); config()->set('updater.git_path', 'git'); config()->set('updater.github_token', 'salahhusa9'); config()->set('updater.github_username', 'salahhusa9'); config()->set('updater.github_repository', 'laravel-test'); Process::fake([ 'git rev-parse --abbrev-ref HEAD' => 'HEAD', 'git describe --tags --abbrev=0' => '1.0.0', 'git pull' => '', 'git checkout 1.0.1' => 'TEST', 'git remote set-url origin https://salahhusa9:salahhusa9@github.com/salahhusa9/laravel-test.git' => '', 'git fetch' => '', ]); $this->assertEquals(['1.0.0', '1.1.0', '2.0.0'], Updater::versions()); } public function test_new_version_available() { Http::fake([ 'https://api.github.com/repos/salahhusa9/laravel-test/releases/latest' => Http::response([ 'tag_name' => '1.0.1', ], 200), ]); config()->set('updater.git_path', 'git'); config()->set('updater.github_token', 'salahhusa9'); config()->set('updater.github_username', 'salahhusa9'); config()->set('updater.github_repository', 'laravel-test'); Process::fake([ 'git rev-parse --abbrev-ref HEAD' => 'HEAD', 'git describe --tags --abbrev=0' => '1.0.0', 'git pull' => '', 'git checkout 1.0.1' => 'TEST', 'git remote set-url origin https://salahhusa9:salahhusa9@github.com/salahhusa9/laravel-test.git' => '', 'git fetch' => '', ]); $this->assertEquals(['current_version' => '1.0.0', 'latest_version' => '1.0.1'], Updater::newVersionAvailable()); } public function test_update() { Event::fake(); // Artisan::fake(); Http::fake([ 'https://api.github.com/repos/salahhusa9/laravel-test/releases/latest' => Http::response([ 'tag_name' => '1.0.1', ], 200), ]); config()->set('updater.git_path', 'git'); config()->set('updater.github_token', 'salahhusa9'); config()->set('updater.github_username', 'salahhusa9'); config()->set('updater.github_repository', 'laravel-test'); Process::fake([ 'git rev-parse --abbrev-ref HEAD' => 'HEAD', 'git describe --tags --abbrev=0' => '1.0.0', 'git pull' => '', 'git checkout 1.0.1 -f' => 'TEST', 'git remote set-url origin https://salahhusa9:salahhusa9@github.com/salahhusa9/laravel-test.git' => '', 'git fetch' => '', ]); // Artisan::shouldReceive('call')->once()->with('up'); $this->assertEquals('Updated to version 1.0.1', Updater::update()); // Test update failure Process::fake([ 'git rev-parse --abbrev-ref HEAD' => 'HEAD', 'git describe --tags --abbrev=0' => '1.0.0', 'git pull origin HEAD' => '', 'git checkout 1.0.1 -f' => '...', 'git remote set-url origin https://salahhusa9:salahhusa9@github.com/salahhusa9/laravel-test.git' => '', 'git fetch' => '', ]); $this->expectException(Exception::class); $this->expectExceptionMessage('git checkout failed: ...'); Updater::update(); } } ================================================ FILE: workbench/app/Providers/WorkbenchServiceProvider.php ================================================