在 Real Python 的幫助下,我通過 CircleCI 了解了持續(xù)集成。我config.yml根據(jù) RP 教程編寫了這個(gè)文件: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接下來,在我當(dāng)前的項(xiàng)目中實(shí)施上述內(nèi)容并確保其正常工作后,我繼續(xù)閱讀文檔并找到了一些其他編寫配置文件的方法。也就是說,我喜歡順序工作流格式,因?yàn)樗鼘?gòu)建和測(cè)試分開為兩個(gè)不同的工作。我試圖重組上述配置以遵循此準(zhǔn)則:# 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但是,這會(huì)在構(gòu)建 0.3 秒后失敗并出現(xiàn)錯(cuò)誤:#!/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貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個(gè)贊
好吧,我想通了這個(gè)問題:
在 Real Python 教程中,構(gòu)建和測(cè)試都是在單個(gè)作業(yè)中完成的,該作業(yè)在單個(gè) docker 容器內(nèi)運(yùn)行。
我沒有意識(shí)到的是,每個(gè)工作都需要一個(gè)碼頭工人,而這些工作不共享碼頭工人。
這意味著為了將我的工作build
和我的工作分開test
,我必須:
重建虛擬環(huán)境
重新激活它
重新安裝安裝依賴項(xiàng)。
對(duì)于這兩個(gè)工作。只有這樣我才能運(yùn)行 pytest。
這看起來效率很低,但現(xiàn)在可以了!

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