2

我很难将包发布到 AWS CodeArtifact。问题是身份验证。

首先,我尝试通过 aws cli 执行登录,但由于缺少包含无法解决的存储库设置的 .pypirc 文件。现在我尝试存储令牌并将其提供给 --repository-url 但在这两种情况下,我最终都认为该进程需要一个用户名。

堆栈跟踪:

File "/opt/hostedtoolcache/Python/3.9.1/x64/bin/twine", line 8, in <module>
    sys.exit(main())
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/site-packages/twine/__main__.py", line 28, in main
    result = cli.dispatch(sys.argv[1:])
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/site-packages/twine/cli.py", line 82, in dispatch
    return main(args.args)
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/site-packages/twine/commands/upload.py", line 154, in main
    return upload(upload_settings, parsed_args.dists)
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/site-packages/twine/commands/upload.py", line 91, in upload
    repository = upload_settings.create_repository()
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/site-packages/twine/settings.py", line 345, in create_repository
    self.username,
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/site-packages/twine/settings.py", line 146, in username
    return cast(Optional[str], self.auth.username)
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/site-packages/twine/auth.py", line 35, in username
    return utils.get_userpass_value(
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/site-packages/twine/utils.py", line 241, in get_userpass_value
    return prompt_strategy()
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/site-packages/twine/auth.py", line 81, in username_from_keyring_or_prompt
    return self.prompt("username", input)
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/site-packages/twine/auth.py", line 92, in prompt
    return how(f"Enter your {what}: ")
EOFError: EOF when reading a line
Enter your username: 
Error: Process completed with exit code 1.

部分 github-action.yml:

steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine
        
    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_CA_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_CA_SECRET_ACCESS_KEY }}
        aws-region: eu-central-1
       
    - name: Build and publish   
      run: |
        token=$(aws codeartifact get-authorization-token --domain foobar --domain-owner 123456678901 --query authorizationToken --output text)
        python setup.py sdist bdist_wheel
        twine upload --repository-url https://aws:$token@foobar-123456678901.d.codeartifact.eu-central-1.amazonaws.com/pypi/my-repo/simple dist/*
4

2 回答 2

0

您需要传递以缠绕正确的身份验证值,请尝试以下操作:

twine upload --repository-url https://foobar-123456678901.d.codeartifact.eu-central-1.amazonaws.com/pypi/my-repo/simple --username aws --password $token dist/*

见:https ://tine.readthedocs.io/en/latest/#commands

于 2021-01-08T22:18:00.653 回答
0

AWS CLI 允许您配置凭证,twine因此您不必显式传递它们。

    - name: Build and publish
      run: |
        aws codeartifact login --tool twine --domain foobar --repository my-repo
        python setup.py sdist bdist_wheel
        twine upload --repository codeartifact dist/*

链接:

https://docs.aws.amazon.com/codeartifact/latest/ug/python-configure.html

https://docs.aws.amazon.com/codeartifact/latest/ug/python-run-twine.html

于 2022-02-08T13:34:17.580 回答