使用 conda-smithy 管理您的 CI
conda-forge,尤其是 conda-smithy
,包含許多工具,可用於在各種不同的平台和架構上建置和部署持續整合 (CI) 基礎架構。如果您可以重複使用所有這些辛勤工作,而無需編寫或管理自己的 CI 配置,那不是很好嗎?
透過在您的儲存庫中新增 recipe/
目錄,conda-smithy 命令 ci-skeleton
可讓您連結到經過良好測試且穩健的 CI 基礎架構。使用 conda-smithy rerender
命令,您可以讓您的儲存庫與任何需要的變更保持最新。
開始使用
ci-skeleton
命令透過準備儲存庫以具有正確的結構來協助您入門,以便 rerender
命令能正確地新增 CI 配置。讓我們來看一個範例!
假設您有一個名為 myproj
的專案儲存庫。在儲存庫的根目錄層級,您可以執行以下命令
~/repo $ conda smithy ci-skeleton myproj
這將產生如下所示的輸出
Generating ~/repo/conda-forge.yml
Generating ~/repo/recipe/meta.yaml
Updating ~/repo/.gitignore
A CI skeleton has been generated! Please use the following steps
to complete the CI setup process:
1. Fill out recipe/meta.yaml with your install and test code
2. Commit all changes to the repo.
$ git add . && git commit -m "ran conda smithy skeleton"
3. Remember to register your repo with the CI providers.
4. Rerender this repo to generate the CI configurations files.
This can be done with:
$ conda smithy rerender -c auto
At any time in the future, you will be able to automatically update your
CI configuration by re-running the rerender command above. Happy testing!
如您所見,這會產生和更新一些重要的檔案。它建立的第一個檔案是 conda-forge.yml
檔案。這是專門設計來告訴 conda smithy rerender
我們沒有將 myproj
CI 作為常規 feedstock 執行。修改 .gitignore
是為了避免意外地將不需要的 conda-smithy 暫存檔新增到您的儲存庫。
此外,ci-skeleton
輸出的步驟對於正確地連接所有內容非常重要。幸運的是,它們很容易執行!讓我們逐一瀏覽它們!
1. 填寫 recipe/meta.yaml
ci-skeleton
命令會發出一個範例 meta.yaml
檔案,用於建置 myproj
,因此名稱中包含 "skeleton"(骨架)部分。如果您不希望在 recipe/
目錄中產生骨架,您可以使用 -r
選項來提供替代方案。
meta.yaml 看起來像
{% set name = "myproj" %}
{% set version = environ.get('GIT_DESCRIBE_TAG', 'untagged')|string|replace('-','_') %}
package:
name: {{ name|lower }}
version: {{ version }}
source:
git_url: {{ environ.get('FEEDSTOCK_ROOT', '..') }}
build:
# Uncomment the following line if the package is pure Python and the recipe
# is exactly the same for all platforms. It is okay if the dependencies are
# not built for all platforms/versions, although selectors are still not allowed.
# See https://conda-forge.dev.org.tw/docs/maintainer/knowledge_base.html#noarch-python
# for more details.
# noarch: python
number: {{ environ.get('GIT_DESCRIBE_NUMBER', '0') }}
string: {{ [build_number, ('h' + PKG_HASH), environ.get('GIT_DESCRIBE_HASH', '')]|join('_') }}
# If the installation is complex, or different between Unix and Windows,
# use separate bld.bat and build.sh files instead of this key. By default,
# the package will be built for the Python versions supported by conda-forge
# and for all major OSs. Add the line "skip: True # [py<35]" (for example)
# to limit to Python 3.5 and newer, or "skip: True # [not win]" to limit
# to Windows.
script: "{{ PYTHON }} -m pip install . -vv"
requirements:
build:
# If your project compiles code (such as a C extension) then add the required
# compilers as separate entries here. Compilers are named 'c', 'cxx' and 'fortran'.
- {{ compiler('c') }}
host:
- python
- pip
run:
- python
test:
# Some packages might need a `test/commands` key to check CLI.
# List all the packages/modules that `run_test.py` imports.
imports:
- myproj
# Run your test commands here
commands:
- myproj --help
- pytest
# declare any test-only requirements here
requires:
- pytest
# copy over any needed test files here
source_files:
- tests/
# Uncomment and fill in myproj metadata
#about:
# home: https://github.com/conda-forge/conda-smithy
# license: BSD-3-Clause
# license_family: BSD
# license_file: LICENSE
# Uncomment the following if this will be on a forge
# Remove these lines if this is only be used for CI
#extra:
# recipe-maintainers:
# - BobaFett
# - LisaSimpson
此 recipe 配置為正確地從 git 抓取原始碼和版本資訊。它也列出了您可能想要讓 conda-build
在執行測試套件時使用的任何測試檔案。
由於您使用 conda-forge、conda-build 等作為您的 CI,因此在此處執行完整的測試套件非常重要。
諸如許可證和維護者之類的元數據可能不太重要,因為在預設情況下,此處建立的套件永遠不會上傳到頻道。您可以隨意刪除或忽略這些欄位。
2. 提交變更
一旦您編寫了您的 recipe,儲存修改就很重要!只需執行以下命令
~/repo $ git add . && git commit -m "ran conda smithy skeleton"
3. 向 CI 提供者註冊
這很重要!如果您尚未執行此操作,您需要前往 CI 提供者(Travis、Circle、Azure 等)並為您的儲存庫啟用 CI。您使用的每個 CI 提供者都會有關於如何設定它們的文件。
4. 重新渲染
最後,但同樣重要的是,我們需要產生 CI 配置腳本!這是基於 recipe 的內容以及在 conda-forge.yml
檔案中進行的提供者選擇。(請參閱這些文件以取得 CI 提供者的完整列表。)
為了產生 CI 配置檔案,請執行
~/repo $ conda smithy rerender -c auto
將這些變更推送至儲存庫現在應該會在 CI 上建置和測試您的套件!
保持最新
使用 ci-skeleton
的主要優點是,一旦設定完成,就很容易讓您的 CI 系統保持最新。如果您修改您的 recipe 以啟用新的架構,您想要在不同的提供者上執行,或者即使 CI 系統在您不知情的情況下變更,恢復運作就像重新渲染一樣容易。您只需要重複上面的步驟 4
~/repo $ conda smithy rerender -c auto
這將為當前時間和 recipe 狀態產生和取代 CI 配置檔案。就這麼簡單!