kcl-lang.io/kpm@v0.8.7-0.20240520061008-9fc4c5efc8c7/docs/publish_pkg_to_ah-zh.md (about)

     1  # 发布 KCL 包
     2  
     3  接下来,我们将以一个 helloworld 的例子,展示如何快速发布您的包到 kcl-lang 官方的 Registry 中,已经发布的包您可以在 AH (artifacthub.io) 中找到他们。
     4  
     5  ## 准备工作
     6  
     7  - 安装 [kpm](https://kcl-lang.io/zh-CN/docs/user_docs/guides/package-management/installation/)
     8  - 安装 [git](https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-Git)
     9  - [注册一个 Github 账户(可选,您需要有一个github的账户)](https://docs.github.com/zh/get-started/signing-up-for-github/signing-up-for-a-new-github-account)
    10  
    11  ## 代码仓库
    12  
    13  注意:如果您希望将您的 KCL 包发布到 kcl-lang 官方的 Registry 中,那么您的 KCL 包的源代码将以开源的形式保存在 [Github 仓库: https://github.com/kcl-lang/artifacthub)](https://github.com/kcl-lang/artifacthub) 中,您需要将您的包的源代码通过 PR 提交到这个仓库中。
    14  
    15  ## 快速开始
    16  接下来,我们以 KCL 包 `helloworld` 为例,展示一下包的发布过程。
    17  
    18  ### 1. 下载代码仓库
    19  
    20  首先,您需要使用 git 将仓库 https://github.com/kcl-lang/artifacthub下载到您的本地 
    21  
    22  ```
    23  git clone https://github.com/kcl-lang/artifacthub --depth=1
    24  ```
    25  
    26  ### 2. 为您的包创建一个分支
    27  
    28  我们推荐您的分支名为:publish-pkg-<pkg_name>, <pkg_name> 为您包的名称。
    29  
    30  以包 helloworld 为例
    31  
    32  进入您下载的artifacthub目录中
    33  ```
    34  cd artifacthub
    35  ```
    36  为包 helloworld 创建一个分支 `publish-pkg-helloworld`
    37  ```
    38  git checkout -b publish-pkg-helloworld
    39  ```
    40  
    41  ### 3. 添加您的包
    42  
    43  您需要将您的包移动到当前目录下,在我们的例子中,我们使用 kpm init 命令创建包 helloworld
    44  
    45  ```
    46  kpm init helloworld
    47  ```
    48  
    49  您可以为 helloworld 包增加一个 README.md 文件保存在包的根目录下,用来展示在 AH 的首页中。
    50  ```
    51  echo "## Introduction" >> helloworld/README.md
    52  echo "This is a kcl package named helloworld." >> helloworld/README.md
    53  ```
    54  
    55  ### 4. 提交您的包
    56  
    57  您可以使用如下命令提交您的包
    58  
    59  使用 `git add .` 命令将您的包添加到 git 的暂存区中
    60  
    61  ```
    62  git add .
    63  ```
    64  
    65  使用 `git commit -s` 命令提交您的包, 我们推荐您的 commit message 遵循  “publish package <pkg_name>” 的格式。
    66  ```
    67  git commit -m"publish package helloworld" -s
    68  ```
    69  
    70  使用 `git push` 命令将您的包提交到您的分支 publish-pkg-<pkg_name> 中
    71  ```
    72  git push
    73  ```
    74  
    75  ### 5. 提交 PR
    76  
    77  将您的分支 publish-pkg-<pkg_name> 向仓库的 main 分支提交 PR。
    78  
    79  - [如何创建 PR](https://docs.github.com/zh/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
    80  
    81  
    82  
    83