Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid-publisher error when using reusable workflow #166

Open
janosh opened this issue Jul 7, 2023 · 29 comments
Open

invalid-publisher error when using reusable workflow #166

janosh opened this issue Jul 7, 2023 · 29 comments
Labels
question Further information is requested

Comments

@janosh
Copy link

janosh commented Jul 7, 2023

My publish step sits in a resuable workflow .github/workflows/pytest-release.yml.

When setting up trusted publishing, should the workflow name be the file in the actual repo (test.yml in my case) or the reusable workflow file being exectued (pytest-release.yml)? The docs sound like the former which throws

Error: Trusted publishing exchange failure:
Token request failed: the server refused the request for the following reasons:

  • invalid-publisher: valid token, but no corresponding publisher
@webknjaz
Copy link
Member

webknjaz commented Jul 9, 2023

Hello, reusable workflows aren't fully supported on the PyPI side at the moment. The only known case when this might work is when the reusable workflows are in the same repository.
This is tracked @ pypi/warehouse#11096 (comment).

@webknjaz
Copy link
Member

webknjaz commented Jul 9, 2023

@woodruffw should we improve the hint that PyPI returns to also suggest checking whether the workflow is reusable?

@webknjaz webknjaz added the question Further information is requested label Jul 9, 2023
@woodruffw
Copy link
Member

@woodruffw should we improve the hint that PyPI returns to also suggest checking whether the workflow is reusable?

IMO this would be a (small) mismatch: reusable workflows are a GitHub concept not an OIDC one, while these error messages are mostly limited generic to OIDC configuration problems or errors (and not specific publishers).

We could do it, but I think my preference would be for linking the troubleshooting page everywhere instead and having users diagnose from there -- that way we don't introduce individual trusted publisher implementation details and don't give them a potential red herring 🙂

@janosh
Copy link
Author

janosh commented Jul 9, 2023

The error message could state that the workflow was not found in the publishing repo itself which currently is a must. Seems generic enough. Other git hosters may have the same concept of reusable workflows.

Does it make sense to wait for reusable workflow support btw? Would be a shame to have to revert legacy publishing everywhere.

@woodruffw
Copy link
Member

Other git hosters may have the same concept of reusable workflows.

Sorry, this is a source of confusion: trusted publishers are not necessarily git-based, or even source repositories at all: they might be arbitrary CI or cloud platforms (such as Google Cloud, which we're currently working on supporting).

In general, IMO PyPI should avoid responding with recommendations that it isn't confident in (e.g. the error might be because of a reusable workflow, or it might be something completely different). This unfortunately inconveniences some users, but keeps us from throwing red herrings at others.

@janosh
Copy link
Author

janosh commented Jul 9, 2023

Oh, thanks for clearing that up.

Another thing I was uncertain about: Is the need for the workflow file to be in the same repo a security measure?

@woodruffw
Copy link
Member

Another thing I was uncertain about: Is the need for the workflow file to be in the same repo a security measure?

Nope! That's purely a technical limitation of the current approach. It's tracked as an item to fix as part of the issue linked above.

@mikegerber
Copy link

I stumbled upon this, and having the reusable workflow in the same repo also causes this error, it seems.

@woodruffw
Copy link
Member

I stumbled upon this, and having the reusable workflow in the same repo also causes this error, it seems.

Can you share your trusted publisher configuration and the repository + workflow you're attempting to use it with?

@mikegerber
Copy link

I stumbled upon this, and having the reusable workflow in the same repo also causes this error, it seems.

Can you share your trusted publisher configuration and the repository + workflow you're attempting to use it with?

I've since somewhat reverted it, but I think this was it:

Trusted publisher configuration (not sure if the second one is necessary):
grafik

This was my attempt:
https://github.com/qurator-spk/setuptools_ocrd/tree/5415329d46c78981190b37389b89ab46b97a53c2/.github/workflows

release.yml should use release-github+pypi.yml. I put secrets: inherit into release.yml, should that also go into the (supposedly) reusable workflow release-github+pypi.yml?

It works beautifully non-reusable, see current master branch if necessary. Ideally I'd like to use the workflow in a few more projects where I want to publish to GitHub + PyPI.

@mikegerber
Copy link

Could gh-action-pypi-publish give more debugging info - if possible? Eg. the values of Publisher - Repository - Workflow - Environment name that should be used in the Trusted publisher configuration?

@webknjaz
Copy link
Member

@mikegerber v1.8.9 has more debug info

@webknjaz
Copy link
Member

release.yml should use release-github+pypi.yml. I put secrets: inherit into release.yml, should that also go into the (supposedly) reusable workflow release-github+pypi.yml?

@mikegerber
You don't use a relative in-repo path + you reuse the workflow from whatever master points to, which will not be the same commit most of the time. Maybe that's what prevents it from working.
Try uses: ./.github/workflows/release-github+pypi.yml — this makes sure that both workflows come from the same commit.

@virtuald
Copy link
Contributor

PR #186 adds a warning to tell users that reusable workflows don't work.

... why don't they work? Is there a manual workaround using "The Manual Way" referenced at https://docs.pypi.org/trusted-publishers/using-a-publisher/ ?

@webknjaz
Copy link
Member

There's no workaround. It has to be implemented in Warehouse.

@woodruffw
Copy link
Member

To add to what @webknjaz said: the limitations with reusable workflows are currently documented here: https://docs.pypi.org/trusted-publishers/troubleshooting/#reusable-workflows-on-github

Adding support for reusable workflows is on my list of things to do, but there's no current timeline for it.

@woodruffw
Copy link
Member

This keeps snaring people despite documentation, unfortunately, so maybe it's time to add a check to the action for it 😅

@webknjaz How would you feel about a check similar to the current third-party PR one? In effect, "fail if the underlying action event is workflow_call."

@webknjaz
Copy link
Member

@woodruffw maybe not fail hard but show a big explainer for this specific case? I don't remember if workflow_call is exposed as an event. I think it's the event of the calling workflow that is visible to us. Also, some people managed to get it to work when the reusable workflow is within the same repo and all the secrets are inherited, it seems. I don't want to break them. But if the upload fails, showing something that is impossible to miss would be a good idea. For some reason I thought we already had that warning in the error messages calling out the reusable workflows special case explicitly but it seems like it's not there.

@woodruffw
Copy link
Member

Makes sense! I'll try and set aside some time to add that warning.

puckdoug added a commit to puckdoug/zpdatafetch that referenced this issue May 11, 2024
@janosh
Copy link
Author

janosh commented May 11, 2024

Adding support for reusable workflows is on my list of things to do, but there's no current timeline for it.

would you accept a bounty for this feature? happy to use GH Sponsors

@woodruffw
Copy link
Member

would you accept a bounty for this feature? happy to use GH Sponsors

This is a very thoughtful offer, thank you! Unfortunately, I can't really personally take bounties for this kind of work -- OSS engineering is my full time job, and I get paid a salary for it. I might do this eventually as a side project, but to do it professionally I'll need one of my clients (or a new client) to fund it.

(I am happy to discuss that further if you'd like, but I also completely understand if that kind of funding isn't what you're interested in.)

janosh added a commit to janosh/pymatviz that referenced this issue Oct 7, 2024
…and pypi publish workflows

latter no longer being a reusable workflow so should now work with PyPI trusted publishing (see pypa/gh-action-pypi-publish/issues/166)
janosh added a commit to janosh/pymatviz that referenced this issue Oct 7, 2024
* use pytest-split in GitHub Action

* fix test_set_template breaking test_get_plotly_font_color_default by modifying global plotly template

* migrate from pytest-release.yml reusable workflow to separate pytest and pypi publish workflows

latter no longer being a reusable workflow so should now work with PyPI trusted publishing (see pypa/gh-action-pypi-publish/issues/166)
@webknjaz webknjaz pinned this issue Nov 5, 2024
MarkoSagadin added a commit to IRNAS/irnas-east-software that referenced this issue Nov 7, 2024
This seems to be needed to make sure that trusted publishing (see below
link) works properly, since the readme says that it can't work from an
reusable workflow.

I ran into this issue when trying to build the release, the
publish-release workflow was failing with a big amount of text:
https://github.com/IRNAS/irnas-east-software/actions/runs/11718734433/job/32640627624

Relevant issues that helped to get a sense of what is happening:
https://github.com/pypa/gh-action-pypi-publish?tab=readme-ov-file#trusted-publishing
pypi/warehouse#11096
pypa/gh-action-pypi-publish#166
MarkoSagadin added a commit to IRNAS/irnas-east-software that referenced this issue Nov 7, 2024
This seems to be needed to make sure that trusted publishing (see below
link) works properly, since the readme says that it can't work from an
reusable workflow.

I ran into this issue when trying to build the release, the
publish-release workflow was failing with a big amount of text:
https://github.com/IRNAS/irnas-east-software/actions/runs/11718734433/job/32640627624

Relevant issues that helped to get a sense of what is happening:
https://github.com/pypa/gh-action-pypi-publish?tab=readme-ov-file#trusted-publishing
pypi/warehouse#11096
pypa/gh-action-pypi-publish#166
MarkoSagadin added a commit to IRNAS/irnas-east-software that referenced this issue Nov 7, 2024
This seems to be needed to make sure that trusted publishing (see below
link) works properly, since the readme says that it can't work from an
reusable workflow.

I ran into this issue when trying to build the release, the
publish-release workflow was failing with a big amount of text:
https://github.com/IRNAS/irnas-east-software/actions/runs/11718734433/job/32640627624

Relevant issues that helped to get a sense of what is happening:
https://github.com/pypa/gh-action-pypi-publish?tab=readme-ov-file#trusted-publishing
pypi/warehouse#11096
pypa/gh-action-pypi-publish#166
dkropachev added a commit to dkropachev/python-driver that referenced this issue Mar 1, 2025
There is bug pypa/gh-action-pypi-publish#166
that does not allow to publish from reusable workflows, this is
workaround for it.
dkropachev added a commit to scylladb/python-driver that referenced this issue Mar 1, 2025
There is bug pypa/gh-action-pypi-publish#166
that does not allow to publish from reusable workflows, this is
workaround for it.
dkropachev added a commit to scylladb/python-driver that referenced this issue Mar 5, 2025
There is bug in publishing github action: pypa/gh-action-pypi-publish#166
that does not allow to publish from reusable workflows.
So we have to move it out.
dkropachev added a commit to scylladb/python-driver that referenced this issue Mar 5, 2025
There is bug in publishing github action: pypa/gh-action-pypi-publish#166
that does not allow to publish from reusable workflows.
So we have to move it out.
dkropachev added a commit to scylladb/python-driver that referenced this issue Mar 5, 2025
* cicd: introduce build-test.yml

Mantaining file for building and publishing and building for testing is
complicated.
Let's split them.

* cicd: move out publishing stage from reusable workflow

There is bug in publishing github action: pypa/gh-action-pypi-publish#166
that does not allow to publish from reusable workflows.
So we have to move it out.
janosh added a commit to janosh/pymatviz that referenced this issue Mar 28, 2025
* use pytest-split in GitHub Action

* fix test_set_template breaking test_get_plotly_font_color_default by modifying global plotly template

* migrate from pytest-release.yml reusable workflow to separate pytest and pypi publish workflows

latter no longer being a reusable workflow so should now work with PyPI trusted publishing (see pypa/gh-action-pypi-publish/issues/166)
@alecbcs
Copy link

alecbcs commented Apr 3, 2025

Also, some people managed to get it to work when the reusable workflow is within the same repo and all the secrets are inherited, it seems. I don't want to break them.

@webknjaz you mentioned some folks were able to successfully setup trusted publishers when using reusable workflows from the same repository. I'm trying to do the same, but running into errors even when inheriting secrets. Do you have any examples of a successful configuration here?

For reference my top level workflow is,
https://github.com/LLNL/repligit/blob/main/.github/workflows/ci.yml

Which is calling this reusable workflow after unit-tests have all passed,
https://github.com/LLNL/repligit/blob/main/.github/workflows/publish.yml

And I've set both as trusted publishers on PyPI for the project.

@webknjaz
Copy link
Member

webknjaz commented Apr 3, 2025

No, I don't. Until PyPI implements support, there's no point in wasting time on hacks. Plus, they'll likely break. For now, it's strictly discouraged. I think some people had it working before attestations were a thing. But if you want to disable useful features, you might as well go back to API tokens, while on it 🤷‍♂️

@alecbcs
Copy link

alecbcs commented Apr 3, 2025

Thank you for the quick response. It's a bit disappointing that simply trying to order unit tests before a publish step forces you back to an API token, but it makes sense that we're better off waiting for official support from PyPI.

@webknjaz
Copy link
Member

webknjaz commented Apr 3, 2025

@alecbcs you can still have tests and the rest/most of the jobs in reusable workflows. Check out sphinx-contrib/sphinxcontrib-towncrier for how I do this.

@webknjaz
Copy link
Member

webknjaz commented Apr 3, 2025

P.S. Once PyPI supports this, I was thinking of providing a reusable workflow similar to this action so that people don't have to have diverging copies of basically the same thing all over GitHub...
P.P.S. Looking at your workflow, I think you may also be interested in my other creation for your last job: https://github.com/marketplace/actions/alls-green#why.

@webknjaz
Copy link
Member

webknjaz commented Apr 3, 2025

As for the publish workflow you have — I think that when you bundle it with testing, the job order should be different. You can build the dists first and then test those dists (currently, you build possibly diverging dists in your test jobs additionally), and only then, you could publish what you tested, not untested dists.
I also have another helper action for testing from sdist instead of a Git checkout that facilitates such a CI/CD structure and more: https://github.com/marketplace/actions/checkout-python-sdist.

@FelixS90
Copy link

Also, some people managed to get it to work when the reusable workflow is within the same repo and all the secrets are inherited, it seems. I don't want to break them.

@webknjaz you mentioned some folks were able to successfully setup trusted publishers when using reusable workflows from the same repository. I'm trying to do the same, but running into errors even when inheriting secrets. Do you have any examples of a successful configuration here?

For reference my top level workflow is, https://github.com/LLNL/repligit/blob/main/.github/workflows/ci.yml

Which is calling this reusable workflow after unit-tests have all passed, https://github.com/LLNL/repligit/blob/main/.github/workflows/publish.yml

And I've set both as trusted publishers on PyPI for the project.

I observed the same with https://github.com/ZEISS/pylibczirw. Publishing from a reusable workflow in the same repo without inheriting secrets used to work last year whereas with a recent try yesterday turned out to not work anymore ... It is a bit annoying not to know what caused this to change ...

@webknjaz
Copy link
Member

not to know what caused this to change ...

Attestations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants