【问题标题】:how to set up github actions for dart and python如何为 dart 和 python 设置 github 操作
【发布时间】:2021-02-16 14:13:08
【问题描述】:

我想用 dart 和 python 设置一个 github 操作容器。我使用了 dart 动作模板并安装了 python。但是,我一直收到错误提示

WARNING: The directory '/github/home/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: pip in /__t/Python/3.8.7/x64/lib/python3.8/site-packages (21.0.1)
/__w/_temp/95e6ebc6-5365-42a8-8197-9f5d14c042d3.sh: 2: /__w/_temp/95e6ebc6-5365-42a8-8197-9f5d14c042d3.sh: pip: not found

这是我的yaml 文件:

name: Dart

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest

    # Note that this workflow uses the latest stable version of the Dart SDK.
    # Docker images for other release channels - like dev and beta - are also
    # available. See https://hub.docker.com/r/google/dart/ for the available
    # images.
    container:
      image:  google/dart:latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up Python 3.8
        uses: actions/setup-python@v2
        with:
          python-version: 3.8
          
      - name: Print Dart SDK version
        run: dart --version

      - name: Install dependencies
        run: | 
          python -m pip install --upgrade pip
          pip install flake8 pytest
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
          cd integ_tests
          dart pub get

      # Run uvicorn
      - name: Run uvicorn
        run: |
          cd fastapi/
          uvicorn app.main:app --reload --port 8000
          
      # run my test
      - name: Run dart test
        run: |
          cd integ_tests
          dart lib/main.dart --dry true

此外,我担心在容器内运行uvicorn 会使容器挂起(因为它永远不会退出)。如果是这种情况,如何在不让容器永远运行的情况下使用 uvicorn 启动 localhost?

编辑:完整日志

如果我使用 sudo 运行它,我会收到一条错误提示

/__w/_temp/2ffb7222-f1dd-4273-870c-c85ac57b9da3.sh: 1: /__w/_temp/2ffb7222-f1dd-4273-870c-c85ac57b9da3.sh: sudo: not found

【问题讨论】:

  • 查看完整日志会很有帮助。您能否提供带有失败的特定 GitHub 操作的 repo 的 URL?
  • @MoneyBall,您在依赖项安装步骤的第一步升级 pip 是否有特殊原因?
  • @astrochun 这实际上是我自己的仓库,目前是私有的。
  • @jidicula 很多时候不是 pip 没有升级到最新版本。此外,这是 Github 操作提供的模板。
  • 我认为问题源于没有在 docker 容器中安装 pip。我有一个类似的问题,即使跑步者安装了git,我也没有找到git。这就是为什么我要求提供完整的日志以查看失败的步骤。

标签: github-actions fastapi uvicorn


【解决方案1】:

我怀疑这里的问题仍然是您试图在容器内运行pip。这就是为什么。 dart 版本在setup-python 安装之后但在pip 安装之前提供。我会更改顺序以确保dart --version 步骤在“运行飞镖测试”步骤之前。这将确保所有 python 构建和配置都在 setup-python 之后完成。

我查看了我的 Python 版本,在升级 pip 的步骤中,我明白了:

> Run python -m pip install --upgrade pip
Requirement already satisfied: pip in /opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages (21.0.1)
Collecting pytest

我相信这将使uvicorn 在容器外部(即在运行器 VM 中)运行。

【讨论】:

  • 您是否尝试过使用dart 映像在本地构建它?这可能有助于根除问题。
猜你喜欢
  • 1970-01-01
  • 2020-09-19
  • 2020-09-27
  • 1970-01-01
  • 2020-09-01
  • 2022-12-20
  • 2022-01-04
  • 2019-12-27
  • 2020-12-08
相关资源
最近更新 更多