在 Real Python 的幫助下,我通過 CircleCI 了解了持續集成。我config.yml根據 RP 教程編寫了這個文件:version: 2jobs: build: docker: - image: circleci/python:3.8 working_directory: ~/repo steps: # Step 1: obtain repo from GitHub - checkout # Step 2: create virtual env and install dependencies - run: name: install dependencies command: | python3 -m venv venv . venv/bin/activate pip install -r requirements.txt # Step 3: run linter and tests - run: name: run tests command: | . venv/bin/activate pytest -v --cov接下來,在我當前的項目中實施上述內容并確保其正常工作后,我繼續閱讀文檔并找到了一些其他編寫配置文件的方法。也就是說,我喜歡順序工作流格式,因為它將構建和測試分開為兩個不同的工作。我試圖重組上述配置以遵循此準則:# Python CircleCI 2.0 configuration fileversion: 2jobs: build: docker: - image: circleci/python:3.8 working_directory: ~/repo steps: # Step 1: obtain repo from GitHub - checkout # Step 2: create virtual env and install dependencies - run: name: install dependencies command: | python3 -m venv venv . venv/bin/activate pip install -r requirements.txt unittest: docker: - image: circleci/python:3.8 # Step 3: run linter and tests steps : - checkout - run: name: run tests command: | . venv/bin/activate pytest -v --covworkflows: build_and_test: jobs: - build - unittest: requires: -build但是,這會在構建 0.3 秒后失敗并出現錯誤:#!/bin/sh -eo pipefail# Unsupported or missing workflows config version# # -------# Warning: This configuration was auto-generated to show you the message above.# Don't rerun this job. Rerunning will have no effect.falseExited with code exit status 1我想知道我搞砸了什么。謝謝。
3 回答

HUX布斯
TA貢獻1876條經驗 獲得超6個贊
好吧,我想通了這個問題:
在 Real Python 教程中,構建和測試都是在單個作業中完成的,該作業在單個 docker 容器內運行。
我沒有意識到的是,每個工作都需要一個碼頭工人,而這些工作不共享碼頭工人。
這意味著為了將我的工作build
和我的工作分開test
,我必須:
重建虛擬環境
重新激活它
重新安裝安裝依賴項。
對于這兩個工作。只有這樣我才能運行 pytest。
這看起來效率很低,但現在可以了!

隔江千里
TA貢獻1906條經驗 獲得超10個贊
我得到了相同的結果,并將添加的版本修復到工作流選項卡。像那樣:
workflows: version: 2 build_and_test: jobs: ...
但要小心空格或制表符。
添加回答
舉報
0/150
提交
取消