如何在GitHub Actions测试矩阵中添加Python不稳定版本
解决GitHub Actions中Python 3.11 beta版本适配问题
你想要更新GitHub Actions工作流以适配Python 3.11的可用版本,已知当前可用的Python 3.11版本为3.11.0-beta.3和3.11.0-beta.2。你的当前测试矩阵配置如下:
name: Python package on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build: runs-on: ubuntu-latest strategy: fail-fast: false matrix: python-version: ["3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install flake8 pytest pip install -r requirements.txt - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | python -m pytest tests --timesensitive
当你尝试在矩阵中添加"3.11"时,配置无法生效,报错信息如下:
Run actions/setup-python@v2 with: python-version: 3.11 token: *** Version 3.11 was not found in the local cache Error: Version 3.11 with arch x64 not found The list of all available versions can be found here: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json
解决方法
1. 指定具体的beta版本号
actions/setup-python@v2版本无法通过简写的3.11匹配到beta版本,必须明确指定完整的beta版本号。修改测试矩阵配置如下:
strategy: fail-fast: false matrix: python-version: ["3.8", "3.9", "3.10", "3.11.0-beta.3"]
如果需要同时测试多个beta版本,可全部加入矩阵:
matrix: python-version: ["3.8", "3.9", "3.10", "3.11.0-beta.3", "3.11.0-beta.2"]
2. 升级actions/setup-python到最新版本(推荐)
actions/setup-python@v4及以上版本支持更灵活的版本匹配规则,你可以直接用3.11-beta自动匹配最新的Python 3.11 beta版本,无需手动指定具体的beta编号。
修改后的工作流示例(同时升级actions/checkout到对应新版本):
name: Python package on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build: runs-on: ubuntu-latest strategy: fail-fast: false matrix: python-version: ["3.8", "3.9", "3.10", "3.11-beta"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install flake8 pytest pip install -r requirements.txt - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | python -m pytest tests --timesensitive
内容的提问来源于stack exchange,提问作者root-11
相关产品推荐
相关产品推荐

