gh-action-pypi-publish: Producing attestations fails when attempting publishing from unsupported reusable workflows (when enabled)

Howdy! We just had to turn off release attestations to get our releases running in langchain-ai/langchain. Haven’t had a chance to dig deeper into attestation configuration in order to see what we need to fix, and thought I’d file an issue in case others run into the same thing!

https://github.com/langchain-ai/langchain/pull/27765

Release Workflow

We run releases from the two workflow files edited in ^ that PR

  • _release.yml, which calls _test_release.yml, and then publishes to pypi
  • _test_release.yml for publishing to test.pypi

Error

We were seeing errors in your releases, e.g. in this workflow run: https://github.com/langchain-ai/langchain/actions/runs/11602468120/job/32307568692

Configuration of test release - 2 main things that look weird are /legacy/ and repository_url (we configure repository-url per docs)

Run pypa/gh-action-pypi-publish@release/v1
  with:
    packages-dir: libs/core/dist/
    verbose: true
    print-hash: true
    repository-url: https://test.pypi.org/legacy/
    skip-existing: true
    user: __token__
    repository_url: https://upload.pypi.org/legacy/
    packages_dir: dist
    verify_metadata: true
    skip_existing: false
    print_hash: false
    attestations: true
  env:
    POETRY_VERSION: 1.7.1
    PYTHON_VERSION: [3](https://github.com/langchain-ai/langchain/actions/runs/11602468120/job/32307568692#step:5:3).10

Logs - partially redacted

Checking libs/core/dist/langchain_core-0.3.14-py3-none-any.whl: PASSED
Checking libs/core/dist/langchain_core-0.3.14.tar.gz: PASSED
Notice: Generating and uploading digital attestations
Fulcio client using URL: https://fulcio.sigstore.dev
TUF metadata: /root/.local/share/sigstore-python/tuf/https%3A%2F%2Ftuf-repo-cdn.sigstore.dev
TUF targets cache: /root/.cache/sigstore-python/tuf/https%3A%2F%2Ftuf-repo-cdn.sigstore.dev
Found and verified trusted root
Generating ephemeral keys...
Requesting ephemeral certificate...
Retrieving signed certificate...
Found <Name(O=sigstore.dev,CN=sigstore-intermediate)> as issuer, verifying if it is a ca
attempting to verify SCT with key ID xxx
Successfully verified SCT...
DSSE PAE: xxx
proposed: xxx
integrated: xxx
Transparency log entry created with index: 145293525
DSSE PAE: xxx
proposed: xxx
integrated: xxx
Transparency log entry created with index: 145293526
Showing hash values of files to be uploaded:
/github/workspace/libs/core/dist/langchain_core-0.3.14-py3-none-any.whl

SHA256: xxx
MD5: xxx
BLAKE2-256: xxx

/github/workspace/libs/core/dist/langchain_core-0.3.14.tar.gz

SHA256: xxx 
MD5: xxx
BLAKE2-256: xxx

/github/workspace/libs/core/dist/langchain_core-0.3.14-py3-none-any.whl.publish.attestation

SHA256: xxx
MD5: xxx
BLAKE2-256: xxx

/github/workspace/libs/core/dist/langchain_core-0.3.14.tar.gz.publish.attestation

SHA256: xxx
MD5: xxx
BLAKE2-256: xxx

Uploading distributions to https://test.pypi.org/legacy/
INFO     libs/core/dist/langchain_core-0.3.14-py3-none-any.whl (399.1 KB)       
INFO     libs/core/dist/langchain_core-0.3.14.tar.gz (320.2 KB)                 
INFO     password set by command options                                        
INFO     username: __token__                                                    
INFO     password: <hidden>                                                     
Uploading langchain_core-0.3.14-py3-none-any.whl
INFO     Response from https://test.pypi.org/legacy/:                           
         400 Bad Request                                                        
INFO     <html>                                                                 
          <head>                                                                
           <title>400 Could not verify the uploaded artifact using the included 
         attestation: Verification failed: 0 of 2 policies succeeded</title>    
          </head>                                                               
          <body>                                                                
           <h1>400 Could not verify the uploaded artifact using the included    
         attestation: Verification failed: 0 of 2 policies succeeded</h1>       
           The server could not comply with the request since it is either      
         malformed or otherwise incorrect.<br/><br/>                            
         Could not verify the uploaded artifact using the included attestation: 
         Verification failed: 0 of 2 policies succeeded                         
                                                                                
                                                                                
          </body>                                                               
         </html>                                                                
ERROR    HTTPError: 400 Bad Request from https://test.pypi.org/legacy/

Temporary Fix

https://github.com/langchain-ai/langchain/pull/27765

We turned off attestations with attestations: false

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 58 (30 by maintainers)

Commits related to this issue

Most upvoted comments

There’s a pretty big disparity between how most users think of TestPyPI and how the packaging maintainers think of it (this is not the first instance I’ve noticed of this).

Most users think of it as a way to test the full release process in a sandbox before doing the final release. If this isn’t what it is, you should really consider making it into that, because that’s what’s useful to people. The principle issue is that pushing to PyPI is a destructive process, since releases cannot be deleted once they are pushed, so it’s useful to have something to run a “test deployment” on (I admit the current TestPyPI doesn’t actually completely work for this because releases cannot be deleted from it either, but it’s better than nothing).

According to the previous comment yes because there’s also a check in this workflow itself.

It would be great if you could fix the workflow so that this just works here, even if it isn’t recommended. I have a lot of release workflows that upload to testpypi then upload to real pypi that used to work just fine and it would be nice if they could continue to work.

I’m a little reluctant to go around trying to refactor my publishing GitHub Actions file. What I have works (or at least used to). I’m not an expert on GitHub Actions (someone else wrote this file initially), and this one in particular is annoying to modify because you can’t really test that it works without doing a release, which itself is tough because PyPI doesn’t let you undo a release. Plus so many steps have to be done manually by typing stuff into a form on pypi.org or clicking around in the GitHub settings. If you want to make a PR to my project doing whatever fix you are suggesting, go for it.

Otherwise, I’m most likely going to just permanently disable either TestPyPI uploading or attestations in the job, since those seem to be the cause of the issue and that should fix the issue going forward, as I understand it.

This worked for me when pubslishing for test PyPI, but I got the same error when the GHA tries to publish to real PyPI.

Test PyPI:

Checking dist/svgcheck-0.9.0.tar.gz: PASSED
Notice: Generating and uploading digital attestations
Fulcio client using URL: https://fulcio.sigstore.dev/
TUF metadata: /root/.local/share/sigstore-python/tuf/https%3A%2F%2Ftuf-repo-cdn.sigstore.dev
TUF targets cache: /root/.cache/sigstore-python/tuf/https%3A%2F%2Ftuf-repo-cdn.sigstore.dev
Found and verified trusted root
Generating ephemeral keys...
Requesting ephemeral certificate...
Retrieving signed certificate...
Found <Name(O=sigstore.dev,CN=sigstore-intermediate)> as issuer, verifying if it is a ca
attempting to verify SCT with key ID dd3d306ac6c7113263191e1c99673702a24a5eb8de3cadff878a72802f29ee8e
Successfully verified SCT...

PyPI:

Checking dist/svgcheck-0.9.0.tar.gz: PASSED
Checking dist/svgcheck-0.9.0.tar.gz.publish.attestation: ERROR    InvalidDistribution: Unknown distribution format:                      
         'svgcheck-0.9.0.tar.gz.publish.attestation'

. It would be really confusing and insecure to allow re-uploading deleted releases on PyPI. A good testing ground is the better solution IMHO

Yes, this is essentially the rationale: immutable files are an important security invariant on the index itself. I agree that the community would benefit from a better automatable testing ground, which TestPyPI itself can probably never be. I don’t have super strong opinions on what that should be, other than that twine check is a great pre-existing UX that should probably provide stronger guarantees.

Random idea: Why not have atomic publishing? That way either the whole release fails or succeeds, but you’d never end up with something partially published where just some files are missing.

We’re currently working on that, stay tuned 🙂

Random idea: Why not have atomic publishing? That way either the whole release fails or succeeds, but you’d never end up with something partially published where just some files are missing.

This would also help with cases where a release runs into quota limits (which happened e.g. for an uv release a few months ago, where they had to yank the whole release while waiting for a quota increase…).

(And in case, it wasn’t clear, if PyPI actually let you delete and redo broken releases, this wouldn’t be nearly so big of an issue. I’ve never understood why there has always been such a strong pushback against allowing that)

Right, but it would also fail uploading to PyPI, so there’s no reason to see if it fails on test pypi first. There’s also no guarantee that test pypi has the same version deployed as pypi, so it may not even fail in the same way. Test PyPI also doesn’t have the same uptime/performance specs as PyPI, so it can fail even if the actual release would succeed.

This is not true. I’ve had testpypi fail because of a broken build, which saved me because it never got to the real upload phase. The issue (IIRC) was that one release file that was uploaded was fine, and “created” the release, but a subsequent file had some issue.

Of course, as noted, there’s no way to delete releases from testpypi, so after doing this I had to temporarily disable the testpypi to make the actual release work, so it’s still not actually ideal for this particular use-case.

This project doesn’t control twine’s release schedule.

TL;DR: Attestations are probably a useful feature, but bugs like this just make things annoying for everyone.

I understand your frustration, and I’m sorry that this bug bit you. At the same time, I don’t think it’s true that this makes things “annoying for everything”: public upload statistics indicate that >99% of workflows were upgraded seamlessly.

Of the workflows that are experiencing problems, the majority are of a shape that was already known to be problematic (reusable workflows), and a minority are of a new shape (stacking publish steps on top of each other). It’s worth noting that the top-level issue here is for the majority case, not the case you’re experiencing.

We’re going to improve the failure mode here as well (I’m going to be working on it in the coming days), but I don’t think there’s much value in overstating the case.

I freely admit I don’t understand how attestations work, and your description doesn’t even make sense to me (how does something get “left on disk” in a GitHub action?

FWIW, this is because the steps within a single job on GitHub actions all share the same filesystem (and all other machine state). The filesystem only disappears in between jobs, because each job gets scheduled on its own VM.

I think @webknjaz has a fair point about public API surface here (and I’ll note that the change here isn’t intrinsically related to attestations; it’s just the first feature to surface it). At the same time, I think it’s unfortunate that we caused any degree of public workflow breakage here.

In the short term, you can work around this by setting attestations: false on the TestPyPI step – attestations don’t really matter for TestPyPI anyways, and that’ll prevent the file conflict. I’ll think some more about a longer-term solution tonight (I have ideas around enforcing domain separation between PyPI and TestPyPI artifacts that would potentially allow us to handle these kinds of cases).

Maybe if we’d known before. But that ship has sailed. This wasn’t a public API change, so SemVer expectations don’t apply. You can clean the artifacts between the runs if you want, but that’s the extent of it. The validation exists to catch a security condition of accidentally leaving incorrect artifacts on disk produced by something outside the action invocation. And it did its job — it found misconfiguration. So it works as one would expect. The only action item I see is documenting this, as it’s probably not very obvious.

Just had this fail in Blinker (and if I had upgraded a bit sooner, it would have failed in Werkzeug and Flask too). It’s not directly related to the title of this issue, but further down it was indicated that uploading to test then pypi in the same workflow results in the error as well. Here’s the workflow run: https://github.com/pallets-eco/blinker/actions/runs/11746299115/job/32725793081?pr=176 It looks like it’s been fixed in twine and we’re just waiting for a release, and I’m going to try removing the test upload and re-running in the mean time. Nothing urgent, just wanted to add some extra data.

Is this something that can be fixed upstream in this action? I’m not really changing the default way this action works, just uploading to TestPyPI first, which I imagine should be a rather common thing to do.

it’s useful to have something to run a “test deployment” on

If you have “upload to test pypi” then “upload to pypi” as sequential steps in a single job, as long as uploading to test pypi passes you won’t have time to verify it, it will move on to uploading to pypi. If uploading to test pypi fails, it would also fail on pypi, so you’re not gaining anything from the check.

If you want to use it as a true “upload to test, then check things before uploading to pypi”, then you would use two separate jobs, each with their own approval environment, which is exactly what the solution to this problem is too.

Most users think of it as a way to test the full release process in a sandbox

I was also in this camp (and may have unintentionally advocated it by using the pattern in Flask), but even before this issue I was starting to realize that it’s not actually helping the way I thought it was.

What’s wrong with chaining TestPyPI/PyPI uploads? Isn’t that how TestPyPI is meant to be used?

TestPyPI isn’t intended to be used in serial with PyPI – it’s an ephemeral index that you can use to test your workflows.

One common pattern I’ve seen with TestPyPI is to publish to it on push: main and similar events. But it’s generally not a good idea (IMO) to publish to it during normal release flows, since it’s not guaranteed to preserve account or package states (much less have any degree of uptime).

In terms of resources:

@woodruffw do we want to keep producing the artifacts as outputs in the dist directory, provided we don’t currently set any outputs? If not, we could even go as far as writing them into a temporary directory instead of the workdir and then passing that to twine upload so they wouldn’t leak into the host filesystem. That’s what I mentioned to @facutuesca like 15 minutes ago on IRC… I just didn’t remember if we discussed files being “promised outputs” explicitly.

I think we should make said warning very verbose and outline very specific steps to take to “migrate”. This would tie nicely with https://github.com/pypa/gh-action-pypi-publish/pull/305#issuecomment-2499315017, I imagine.

I’m not following how the ship has sailed, especially if it’s not a public API change.

I will say that if your goal here is to push attestations as a “good thing” for the ecosystem, then this problem goes against that goal, because from a high level, the appearance here is that things worked before attestations and they broke after attestations. It’s not a great feeling or a great look. Telling people that they now need to rewrite their complex workflows that used to work “just because” isn’t exactly meeting people where they are.

I freely admit I don’t understand how attestations work, and your description doesn’t even make sense to me (how does something get “left on disk” in a GitHub action? Aren’t github actions runs self contained?). But that’s the point. I’m sure most people are like me in that their eyes glaze over when faced with technical descriptions of why their GitHub Actions started breaking for no reason. It just feels like things used to work and now they don’t, and it’s clearly because of a change made in this repo, because they stopped working when dependabot updated this action.

I’m also getting the same InvalidDistribution: Unknown distribution format trying to upload the attestation to PyPI (but no such error to TestPyPI). https://github.com/data-apis/array-api-strict/actions/runs/11713859145/job/32627476623

I don’t think I’m using a reusable workflow (that means it has on: workflow_call in it, right?). https://github.com/data-apis/array-api-strict/blob/main/.github/workflows/publish-package.yml

Not really — there’s a long backlog and everybody wants to be escalated. It may take a long time to get your request reviewed. In general, we’re trying to emphasize that the PSF / PyPA needs funding to hire more people to go through that queue. I think one position has been funded for a year and that person is speeding up the process, but that’s probably not enough really. Ask your employer to fund another PyPI support person 😃

@webknjaz Thanks. I’ll review publishing workflow.

appreciate the quick look @woodruffw !

Thanks for the report. It would be useful to have a link to the log. And I even more useful if the job is restarted in debug mode. Meanwhile, we’ll have to wait for @woodruffw to see this and take a look from his side.