1. <tfoot id='mUzri'></tfoot>
    2. <small id='mUzri'></small><noframes id='mUzri'>

        <bdo id='mUzri'></bdo><ul id='mUzri'></ul>

      <i id='mUzri'><tr id='mUzri'><dt id='mUzri'><q id='mUzri'><span id='mUzri'><b id='mUzri'><form id='mUzri'><ins id='mUzri'></ins><ul id='mUzri'></ul><sub id='mUzri'></sub></form><legend id='mUzri'></legend><bdo id='mUzri'><pre id='mUzri'><center id='mUzri'></center></pre></bdo></b><th id='mUzri'></th></span></q></dt></tr></i><div id='mUzri'><tfoot id='mUzri'></tfoot><dl id='mUzri'><fieldset id='mUzri'></fieldset></dl></div>

      <legend id='mUzri'><style id='mUzri'><dir id='mUzri'><q id='mUzri'></q></dir></style></legend>

        如何从 Github 工作流访问环境机密?

        时间:2023-07-04
      1. <legend id='Kme6E'><style id='Kme6E'><dir id='Kme6E'><q id='Kme6E'></q></dir></style></legend>

          1. <small id='Kme6E'></small><noframes id='Kme6E'>

            <i id='Kme6E'><tr id='Kme6E'><dt id='Kme6E'><q id='Kme6E'><span id='Kme6E'><b id='Kme6E'><form id='Kme6E'><ins id='Kme6E'></ins><ul id='Kme6E'></ul><sub id='Kme6E'></sub></form><legend id='Kme6E'></legend><bdo id='Kme6E'><pre id='Kme6E'><center id='Kme6E'></center></pre></bdo></b><th id='Kme6E'></th></span></q></dt></tr></i><div id='Kme6E'><tfoot id='Kme6E'></tfoot><dl id='Kme6E'><fieldset id='Kme6E'></fieldset></dl></div>
          2. <tfoot id='Kme6E'></tfoot>

                <bdo id='Kme6E'></bdo><ul id='Kme6E'></ul>
                  <tbody id='Kme6E'></tbody>
                • 本文介绍了如何从 Github 工作流访问环境机密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试从 Github 工作流程向 PyPI 发布 Python 包,但身份验证失败用于测试 PyPI".我从命令行成功发布到 Test PyPI,所以我的 API 令牌必须是正确的.我还检查了秘密值中的前导和尾随空格(即在 GitHub 上).

                  正如上次提交所显示的,我尝试了一些事情但没有成功.

                  我首先尝试将简单的 bash 命令内联到工作流中,如下所示,但我无法将我的秘密放入环境变量中.当我打印这些变量时,日志中没有任何显示.

                  - 名称:在测试 PyPI 上发布环境:TWINE_USERNAME:__token__TWINE_PASSWORD:${{ 秘密.PYPI_TEST_TOKEN }}TWINE_REPOSITORY_URL:https://test.pypi.org/legacy/"运行:|回声$TWINE_PASSWORD"点安装麻线麻线检查距离/*twine 上传 dist/*

                  我也尝试使用如下专用的 GitHub Action,但它也不起作用.我想问题出在我的工作流程中不可用的秘密.让我感到困惑的是,我的工作流程使用另一个令牌/秘密就好了!但是,如果我将它放在环境变量中,则不会打印任何内容.我还以不同的名称(PYPI_TEST_TOKEN 和 TEST_PYPI_API_TOKEN)重新创建了我的秘密,但无济于事.

                  - name: Publish to Test PyPI用途:pypa/gh-action-pypi-publish@release/v1和:用户:__token__密码:${{ secrets.TEST_PYPI_API_TOKEN }}存储库网址:https://test.pypi.org/legacy/

                  我想我错过了一些明显的东西(像往常一样).非常感谢任何帮助.

                  解决方案

                  我终于想通了.我的错误是我在一个环境中定义了我的秘密,并且默认情况下,工作流不在任何特定环境中运行.为此,我必须在职位描述中明确命名环境,如下所示:

                  工作:发布:environment: CI # <---/! 这里是环境的链接需求:构建运行:ubuntu-latest如果:startsWith(github.ref, 'refs/tags/v')脚步:- 使用:actions/checkout@v2# 这里还有一些步骤...- 名称:发布到测试 PyPI环境:TWINE_USERNAME:__token__"TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}TWINE_REPOSITORY_URL:https://test.pypi.org/legacy/"运行:|回显键:'${TWINE_PASSWORD}'麻线检查距离/*twine 上传 --verbose --skip-existing dist/*

                  文档实际上提到了它.p>

                  感谢那些给我指出正确方向的评论.

                  I am trying to publish a Python package to PyPI, from a Github workflow, but the authentication fails for "Test PyPI". I successfully published to Test PyPI from the command line, so my API token must be correct. I also checked for leading and trailing spaces in the secret value (i.e., on GitHub).

                  As the last commits show, I tried a few things without success.

                  I first tried to inline simple bash commands into the workflow as follows, but I have not been able to get my secrets into environment variables. Nothing showed up in the logs when I printed these variables.

                  - name: Publish on Test PyPI 
                    env:
                       TWINE_USERNAME: __token__
                       TWINE_PASSWORD: ${{ secrets.PYPI_TEST_TOKEN }}
                       TWINE_REPOSITORY_URL: "https://test.pypi.org/legacy/"
                    run: |
                       echo "$TWINE_PASSWORD"
                       pip install twine
                       twine check dist/*
                       twine upload dist/*
                  

                  I also tried to use a dedicated GitHub Action as follows, but it does not work either. I guess the problem comes from the secrets not being available in my workflow. What puzzled me is that my workflow uses another token/secret just fine! Though, if I put it in an environment variable, nothing is printed out. I also recreated my secrets under different names (PYPI_TEST_TOKEN and TEST_PYPI_API_TOKEN) but to no avail.

                  - name: Publish to Test PyPI
                    uses: pypa/gh-action-pypi-publish@release/v1
                    with:
                      user: __token__
                      password: ${{ secrets.TEST_PYPI_API_TOKEN }}
                      repository_url: https://test.pypi.org/legacy/
                  

                  I guess I miss something obvious (as usual). Any help is highly appreciated.

                  解决方案

                  I eventually figured it out. My mistake was that I defined my secrets within an environment and, by default, workflows do not run in any specific environment. For this to happen, I have to explicitly name the environment in the job description as follows:

                  jobs:
                    publish:
                      environment: CI    # <--- /! Here is the link to the environment
                      needs: build
                      runs-on: ubuntu-latest
                      if: startsWith(github.ref, 'refs/tags/v')
                      steps:
                      - uses: actions/checkout@v2
                      # Some more steps here ...
                      - name: Publish to Test PyPI
                        env:
                          TWINE_USERNAME: "__token__"
                          TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
                          TWINE_REPOSITORY_URL: "https://test.pypi.org/legacy/"
                        run: |
                          echo KEY: '${TWINE_PASSWORD}'
                          twine check dist/*
                          twine upload --verbose --skip-existing dist/*
                  

                  The documentation mentions it actually.

                  Thanks to those who commented for pointing me in the right direction.

                  这篇关于如何从 Github 工作流访问环境机密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 python 脚本中修改系统路径变量? 下一篇:python-dotenv有什么用?

                  相关文章

                • <i id='vpear'><tr id='vpear'><dt id='vpear'><q id='vpear'><span id='vpear'><b id='vpear'><form id='vpear'><ins id='vpear'></ins><ul id='vpear'></ul><sub id='vpear'></sub></form><legend id='vpear'></legend><bdo id='vpear'><pre id='vpear'><center id='vpear'></center></pre></bdo></b><th id='vpear'></th></span></q></dt></tr></i><div id='vpear'><tfoot id='vpear'></tfoot><dl id='vpear'><fieldset id='vpear'></fieldset></dl></div>

                    <small id='vpear'></small><noframes id='vpear'>

                      <tfoot id='vpear'></tfoot>
                      • <bdo id='vpear'></bdo><ul id='vpear'></ul>

                    1. <legend id='vpear'><style id='vpear'><dir id='vpear'><q id='vpear'></q></dir></style></legend>