anisaronno/laravel-auto-updater

Laravel 自动更新器是一个帮助您自动更新 Laravel 应用的包。

1.0.1 2024-09-30 09:50 UTC

This package is auto-updated.

Last update: 2024-09-30 10:57:47 UTC


README

一个强大的 Laravel 包,便于从 GitHub、GitLab、Bitbucket 或自定义仓库自动更新您的 Laravel 应用。 支持 Laravel 8 及以上版本。

目录

特性

  • 多源支持:从 GitHub、GitLab、Bitbucket 或自定义仓库更新
  • 通过环境变量和配置文件进行简单配置
  • 内置更新检查和启动命令
  • 排除更新敏感文件/文件夹
  • 全面错误处理和日志记录
  • 通过 composer.json 跟踪版本
  • 全局 Blade 组件,便于集成
  • 用于程序化更新管理的 API 端点
  • 可配置中间件以提高 API 安全性

安装

通过 Composer 安装包

composer require anisaronno/laravel-auto-updater

发布配置文件

php artisan vendor:publish --tag=auto-updater-config

这将在您的 config 目录中创建 auto-updater.php

可选,发布资源和视图

php artisan vendor:publish --tag=auto-updater-assets
php artisan vendor:publish --tag=auto-updater-views

配置

环境变量

将这些添加到您的 .env 文件中

RELEASE_URL=https://github.com/anisAronno/laravel-starter
PURCHASE_KEY=your_optional_purchase_key
  • RELEASE_URL:您的仓库发布 URL
  • PURCHASE_KEY:(可选) 用于认证 API 或私有仓库

配置文件

config/auto-updater.php 文件包含重要设置

  • 仓库配置:该文件使用 VersionSourceFactory 根据您的 RELEASE_URL 创建适当的适配器。
  • 排除项:定义要排除的更新文件和文件夹。
  • 中间件:指定应用于自动更新器 API 端点的中间件。

排除更新项

编辑 config/auto-updater.php 中的 exclude_items 数组

"exclude_items" => [
    '.env',
    '.git',
    'storage',
    'node_modules',
    'vendor',
    // Add custom exclusions here
],

在配置文件中设置中间件

要配置中间件,编辑 config/auto-updater.php 文件中的 middleware 数组

"middleware" => ['web'],

默认情况下,中间件设置为 web

应用版本

composer.json 中指定您的应用版本

{
  "version": "1.0.0"
}

在更改配置后,刷新配置缓存

php artisan config:cache

用法

更新检查命令

检查可用更新

php artisan update:check

启动更新命令

启动更新过程

php artisan update:initiate

计划更新

添加到 app/Console/Kernel.php(Laravel 10 及以下)

protected function schedule(Schedule $schedule)
{
    $schedule->command('update:initiate')->daily();
}

对于 Laravel 11 及以上,添加到 routes/console.php

use Illuminate\Support\Facades\Schedule;

Schedule::command('update:initiate')->daily();

修改文件警告

更新器会警告修改了项目文件,排除 .envstorage/

自定义更新 URL

对于自定义更新源,请确保您的 API 返回

{
  "version": "1.0.0",
  "download_url": "https://example.com/api/v1/release",
  "changelog": "Your changelog text"
}

API 端点

用于程序化更新的这些端点

  • 检查更新: GET /api/auto-updater/check
  • 启动更新: POST /api/auto-updater/update

这些端点由配置文件中指定的中间件保护。

Blade 组件

在任何视图中使用全局组件

<x-auto-updater />

贡献指南

我们欢迎贡献!请参阅我们的贡献指南以获取详细信息。

许可

此包是开源软件,根据MIT 许可证授权。