Skip to content

Conversation

@mshafer-NI
Copy link
Collaborator

Publishing is currently broken due to using an old PAT.

As part of switching to OIDC based publishing, we should bring in the update ni/python-actions templates

@github-actions
Copy link
Contributor

Thank you for contributing! 👋

@mshafer-NI
Copy link
Collaborator Author

@bkeryan, does this look right? (also, not sure how to test before merging...)

@bkeryan
Copy link
Contributor

bkeryan commented Jun 20, 2025

@bkeryan, does this look right? (also, not sure how to test before merging...)

After merging, it will show up in the UI, but, to test before merging:

  • temporarily add on: pull_request: to get GitHub to recognize the workflow
  • use gh workflow run --ref dev/update_release_process to run it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- name: Upload Python package
if: ${{ github.event.release.target_commitish == 'main' || startsWith(github.event.release.target_commitish, 'releases/')}}
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trusted publishing will not work without specifying the "pypi" environment and "id-token: write" permissions. See https://github.com/ni/nitypes-python/blob/main/.github/workflows/publish.yml#L66

Also, it is not secure to run poetry install, pytest, etc. in the "pypi" environment. You should split the workflow into multiple jobs:

  • build/test, upload artifact (default permissions)
  • download artifact, upload to pypi ("pypi" environment, "id-token: write" permissions)
  • update project version (default permissions)

@bkeryan
Copy link
Contributor

bkeryan commented Jun 20, 2025

@bkeryan, does this look right? (also, not sure how to test before merging...)

Also, you can test the publish workflow with TestPyPI by creating an account on test.pypi.org, editing the workflow to use testpypi by default, and publishing a release in your personal fork of the repo.

on:
release:
types: [released]
types: [published]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, published is equivalent to [released, prereleased], so it allows you to publish prereleases. However, this repo's versioning strategy does not currently support this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I was reading, they're also different in that

"released" is triggered when a release (non-draft) is made
"published" is truggered when a non-draft release is or a draft release is marked as non-draft.

(unless I read that wrong...)

If that is the case, this is a favorable change despite the version limitations

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The note on https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release makes it sound like "released" will work with "Save draft" + "Publish release" but "prereleased" will not work with "[x] Set as a pre-release" + "Save draft" + "Publish release". I think we may have run into this when we started publishing measurement-plugin-python pre-releases.

Comment on lines +48 to +50
# If the version is 0.1.0-alpha.0, this will set the version to 0.1.0
- name: Promote package version to release
run: poetry version patch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, we are not doing this in other Python projects:

  • Modifying the project version before publishing causes the tagged commit and the release .zip file to have the wrong version. This has been an annoyance for the measurement-plugin-python project.
  • Converting alpha/beta/dev versions to release before publishing means you can't publish alpha/beta/dev versions to PyPI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On point b, we (PWG) decided to do this so that "alpha" always means "from source", not saying that was a good decision, just what this was setup with.

@irwand irwand merged commit da696d8 into ni:main Jul 10, 2025
19 checks passed
@mshafer-NI mshafer-NI deleted the dev/update_release_process_to_ni_python_actions branch July 10, 2025 13:35
mshafer-NI added a commit that referenced this pull request Jul 10, 2025
* update publishing flow to use ni/python-actions

* github: Split Publish-Package.yml jobs according to security best practices

* github: Restore versioning policy

* github: Fix next version update

---------

Co-authored-by: Brad Keryan <brad.keryan@ni.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants