elendev/composer-push

为 composer 提供一个 Push 命令,用于向仓库推送

安装数: 103,843

依赖者: 6

建议者: 2

安全性: 0

星星: 49

关注者: 7

分支: 29

开放问题: 14

类型:composer-plugin

1.0.5 2024-08-15 16:11 UTC

README

此 composer 插件提供了一个 composer push 命令,允许将当前包推送到远程 composer 仓库。

目前支持的仓库有

安装

 $ composer require elendev/composer-push

重要说明

此插件是 elendev/nexus-composer-push 的延续,如果您还没有迁移,请迁移到这个版本。

使用方法

许多选项都是可选的,因为它们可以直接添加到 composer.json 文件中。

 # At the root of your directory
 $ composer push [--name=<package name>] \
   [--url=<URL to the composer repository>] \
   [--type=<Type of repository, nexus by default, artifactory available too>]
   [--repository=<the repository you want to save, use this parameter if you want to control which repository to upload to by command-line parameter>] \
   [--username=USERNAME] \
   [--password=PASSWORD] \
   [--ignore=test.php]\
   [--ignore=foo/]\
   [--ignore-by-git-attributes]\
   [--src-type=<The type of repository used for source code: git, svn, ... which will be added to source tag of composer package>]\
   [--src-url=<URL of the source code repository which will be added to source tag of composer package>]\
   [--src-ref=<The reference to the current code version for this package which will be added to source tag of composer package>]\
   [--keep-vendor, Keep vendor directory when creating zip]\
   [--ssl-verify=true/]\
   [--access-token=<ACCESS_TOKEN added in Bearer>]
   <version>

If <version> is not set, `composer.json` version will be used.
   
 # Example 
 $ composer push --username=admin --password=admin123 --url=https://:8081/repository/composer --ignore=test.php --ignore=foo/ --src-type=git --src-url="$(git remote get-url origin)" --src-ref="$(git rev-parse HEAD)" 0.0.1
 
 # Example of use --repository
 # you need firstly configure multi repositories in composer.json of the project.
 # Please refer to Configuration below (multi repository configuration format) for configuration method
 # The component will be uploaded to the first repository whose's name value matching -- repository value
 # If there is no matching between the value of repository name and the value of -- repository, the upload will fail with a prompt
 $ composer push --username=admin --password=admin123 --repository=prod --ignore=test.php --ignore=foo/ 0.0.1

配置

可以在 composer.json 文件中添加一些配置

{
    "extra": {
        "push": {
            "url": "https://:8081/repository/composer",
            "type": "nexus",
            "ssl-verify": true,
            "username": "admin",
            "password": "admin123",
            "ignore-by-git-attributes": true,
            "ignore": [
                "test.php",
                "foo/"
            ]
        }
    }
}

上述配置可能被称为唯一仓库配置格式,因为在 composer.json 中只能配置一个仓库。

实际上,出于安全原因,不同版本的组件代码,如生产版本和开发版本,通常应用不同的部署策略,例如禁用生产版本的重新部署,允许开发版本的重新部署,因此它们需要存储在不同的仓库中。对于 0.1.5 版本以后的版本,命令行参数 -- repository 被引入以满足这一需求。要启用 -- repository 参数,composer.json 文件需要以下格式

{
    "extra": {
        "push": [{
            "name": "prod",
            "type": "artifactory",
            "url": "https://jfrog-art.com/artifactory/composer-local/",
            "username": "admin",
            "password": "admin123",
            "ignore-by-git-attributes": true,
            "ignore": [
                "test.php",
                "foo/"
            ]
        }, {
            "name": "dev",
            "url": "https://:8081/repository/composer-devs",
            "username": "admin",
            "password": "admin123",
            "ignore-by-git-attributes": true,
            "ignore": [
                "test.php",
                "foo/"
            ]
        }]
    }
}

上述配置可能被称为多仓库配置格式。

新版本继续支持解析唯一仓库配置格式,但请记住,在这种情况下不能使用 -- repository 命令行参数。

usernamepassword 可以使用 Composer 提供的 认证机制auth.json 文件中按用户指定。

提供商

一些提供商的特定性。

Nexus

源类型,URL,引用

这是可以为包含此版本源引用的包添加到 composer.json 文件中的可选部分。此选项在您有源管理器并希望直接链接到特定版本的源时很有用。上面给出的示例将读取 git 的最后一个提交 ID 和远程地址,这很简单且很有用。

Artifactory

令牌

令牌目前作为密码使用时受支持。仍需要用户名才能使其工作。

目前不支持独立令牌。

令牌使用示例

{
    "extra": {
        "push": {
            "url": "https://jfrog-art.com/artifactory/composer-local",
            "type": "artifactory",
            "username": "<username>",
            "password": "<Authentication token for the user username>"
        }
    }
}