使用私有 GitLab 发布 Composer package

创建 package

  • cd foobar/

  • composer init

# This command will guide you through creating your composer.json config.
# 
# Package name (<vendor>/<name>) [vendor/foobar]:
# Description []:
# Author [nfangxu <nfangxu@gmail.com>, n to skip]:
# Minimum Stability []:
# Package Type (e.g. library, project, metapackage, composer-plugin) []:
# License []:
# 
# Define your dependencies.
# 
# Would you like to define your dependencies (require) interactively [yes]?
# Search for a package:
# Would you like to define your dev dependencies (require-dev) interactively [yes]?
# Search for a package:
# 
# 这个时候会在此处显示你上面所配置的内容, 即: composer.json 文件的预览
# 
# Do you confirm generation [yes]?

# 根据自己的需要配置 composer.json 
  • 上传到 gitlab

使用 package

  • 参考 官方文档

  • 在项目的 composer.json 文件中, 添加以下配置:

{
    .
    .
    .
    "repositories": [
        {
            "type": "vcs", # gitlab 时的固定值
            "url":  "git@glab.nfangxu.com:nfangxu/package.git" # 项目的 git 地址
        }
    ],
    .
    .
    .
    "require": {
        .
        .
        .
        "nfangxu/package" : "dev-master" # 如果使用分支, 需要在分支名前面添加 dev- , 使用 tag 则直接写 tag 名称即可
    },
    .
    .
    .

执行 composer update

这种操作是不推荐的

package 更新 (2018/11/21 更新)

对于发布到 packagist.org 的扩展包是有版本显示的, 私有的扩展包同样可以实现类似的功能
gitlab 并没有提供直接的 release 功能, 需要通过 tag 来实现

添加 tag

  • 打开项目目录 > repository > 标签 > New Tag

    • tag name : v1.0 # 作为你的版本标识
    • Create from : master # 从哪里创建, 选择 master 分支, 或你的任意分支
    • Message # 不填也可以
    • Release notes # 不填也可以
  • 点击 create tag

使用版本

  • 打开你项目中的 composer.json 文件, 修改内容为
.
.
.
"nfangxu/package" : "v1.0"
.
.
.
  • 执行 composer update nfangxu/package 即可更新到指定版本(tag)

注意

如果更新版本, 也需要先更改 composer.json 再执行 composer update nfangxu/package 命令,
如果直接执行 composer update nfangxu/package:v1.1 命令, 会提示 Package "nfangxu/package:v1.1" listed for update is not installed. Ignoring.

网站原文

本作品采用《CC 协议》,转载必须注明作者和本文链接
nfangxu
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 2

这种方式如果发布的版本过多,或者分支过多,将会导致 composer 内存爆了,最好是开启 Gitlab 的 Package Registry

3年前 评论

您问您的是私有仓库吗? 还是公有的?

3年前 评论
nfangxu (楼主) 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!