如何确保某些内容位于 Github Actions 的路径中?

问题描述 投票:0回答:1

我在使用 GitHub Action 在 Windows 上测试 Python 模块时遇到问题。为了测试该模块,我需要安装 ffmpeg 并确保它位于 Path 上,但无论我在工作流程文件或安装 ffmpeg 的 Python 脚本中做什么,我似乎都无法让它出现在 Path 上。

我通过这个脚本安装ffmpeg,它使用这种方法将其添加到路径:

def add_path_to_environment(path):
    '''Adds a filepath to the users PATH variable after asking the user's consent'''
    os_path = os.environ['path']
    if not os_path.endswith(';'):
        os_path += ';'
    command = f'[Environment]::SetEnvironmentVariable("Path","{os_path}{path}","User")'
    print('\n\n')
    print(command)
    print()

    try:
        subprocess.check_output(['powershell', command])
    except subprocess.CalledProcessError as e:
        print(e.stdout.decode())

我在工作流程中的最新尝试是使用这个:

[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\FFMPEG\bin", [System.EnvironmentVariableTarget]::User)
echo $env:Path
ffmpeg -version

我在here找到了它,但我也尝试过只使用

$env:Path += ";C:\FFMPEG\bin"

有人对我如何在 Path 上获取 ffmpeg 有任何建议吗?

python-3.x windows powershell ffmpeg github-actions
1个回答
0
投票

如果你还没有尝试过。我在 GitHub Action 脚本中使用 FedericoCarboni 的 setup-ffmpeg@v3,它在测试我的 Python 项目时运行良好。此操作将 FFmpeg 路径放入系统路径,因此您应该能够从 PowerShell 调用

ffmpeg
ffprobe

我的

action.yml
文件中有以下条目:

      - name: Set up FFmpeg
        uses: FedericoCarboni/setup-ffmpeg@v3
        with:
          architecture: x64
          github-token: ${{ secrets.GITHUB_TOKEN }}
© www.soinside.com 2019 - 2024. All rights reserved.