-
Notifications
You must be signed in to change notification settings - Fork 6
[CI] build'n'publish with steroids #64
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
Merged
AdamRJensen
merged 15 commits into
pvlib:main
from
echedey-ls:ci-build-n-publish-improvements
Mar 21, 2025
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f580e09
Update .gitignore (not venv in it, what crime was that 👀 )
echedey-ls b6d3fdd
Update publish CI
echedey-ls 998ba58
refine instructions
echedey-ls 7181ecc
Update publish.yml
echedey-ls 8c710fc
Merge branch 'main' into pr/64
AdamRJensen eda66f2
retrigger RTD by removing an optional instruction
echedey-ls f5962d1
Merge branch 'main' into pr/64
AdamRJensen 1c53d9d
Merge branch 'ci-build-n-publish-improvements' of https://github.com/…
AdamRJensen 7448482
Change CI name
echedey-ls b32c5e9
Fix using env in if statements
echedey-ls 465b605
Hard-coding it cause GH did not thought about constants
echedey-ls 3729c5c
setuptools-scm did not work with a shallow copy
echedey-ls dd6fa23
fix installation size listing
echedey-ls 7f109d4
Switch to SPDX license format
AdamRJensen 0fb3d48
Add license-file field to pyproject.toml
AdamRJensen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,102 @@ | ||
| name: Publish distributions to PyPI | ||
|
|
||
| # if this workflow is modified to be a generic CI workflow then | ||
| # add an if statement to the publish step so it only runs on tags. | ||
| # CI setup instructions: | ||
| # 1. Create a new environment for additional protection and security in the GitHub UI: | ||
| # Settings > Environments | ||
| # Name: release | ||
| # 2. Setup trusted publishing for the release environment: | ||
| # https://docs.pypi.org/trusted-publishers/ | ||
| # 3. Ensure your main development branch is named 'main'; if not, update the workflow or rename the branch | ||
|
|
||
| # This workflow is triggered on pull requests that target the main branch | ||
| # on pushes to the main branch new tags that start with 'v' (for example, 'v1.0.0'). | ||
| # Only the main branch is used for publishing to PyPI, in the second job. | ||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| push: | ||
| branches: | ||
| - main | ||
| tags: | ||
| - "v*" | ||
|
|
||
| env: | ||
| python-version: "3.12" | ||
| base-repo: "pvlib/twoaxistracking" | ||
|
|
||
| jobs: | ||
| build-n-publish: | ||
| name: Build and publish distributions to PyPI | ||
| if: github.repository == 'pvlib/twoaxistracking' | ||
| build-distribution: | ||
| name: Build distribution | ||
| if: github.repository == env.base-repo | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| id-token: write # This is required for requesting the JWT | ||
| contents: read # This is required for actions/checkout | ||
| steps: | ||
| # fetch all commits and tags so versioneer works | ||
| - uses: actions/checkout@v4 | ||
| # Shallow clone to fetch only the latest commit, which is faster | ||
| with: | ||
| fetch-depth: 0 | ||
| fetch-depth: 1 | ||
|
|
||
| - name: Fetch latest tag | ||
| # Fetch the latest tag explicitly, so setuptools-scm can use it for the version | ||
| run: | | ||
| git fetch --tags | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
| python-version: ${{ env.python-version }} | ||
|
|
||
| - name: Install build tools | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| python -m pip install --upgrade setuptools wheel build | ||
| python -m pip install --upgrade setuptools wheel build twine | ||
| - name: Build packages | ||
| run: python -m build --sdist --wheel | ||
| # creates the necessary distribution files to /dist | ||
| run: python -m build | ||
|
|
||
| - name: Check metadata verification | ||
| # this step ensures the metadata is correct and complete | ||
| # it is a good practice to run this before publishing to PyPI | ||
| run: python -m twine check --strict dist/* | ||
|
|
||
| - name: Distribution files & installation sizes | ||
| # this step is useful to get some useful metrics and ensure changes do not break the size of the distribution | ||
| run: | | ||
| echo "Distribution files sizes" | ||
| du -sh dist/* | ||
| python -m pip install dist/*.whl --target /tmp/${{ env.base-repo }} --quiet --quiet | ||
| echo "Installation size of wheel" | ||
| du -sh /tmp/${{ env.base-repo }} | ||
| - name: Upload artifact with distribution files | ||
| # this step uploads the distribution files to the GitHub artifact store if they are needed later to publish to PyPI | ||
| if: github.repository == env.base-repo && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: distro-files | ||
| path: dist/ | ||
| if-no-files-found: error # files are required in the next job | ||
| retention-days: 1 # delete the artifact after 1 day, no need to keep it for too long | ||
| compression-level: 0 # no need to compress the files | ||
|
|
||
| publish-distribution: | ||
| name: Upload distribution to PyPI | ||
| runs-on: ubuntu-latest | ||
| needs: build-distribution # first build, then publish | ||
| # only publish distribution to PyPI in tagged commits | ||
| if: github.repository == env.base-repo && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | ||
| environment: release | ||
| permissions: | ||
| id-token: write # this permission mandatory for trusted publishing | ||
| steps: | ||
| - name: Download artifact with distribution files | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: distro-files | ||
| path: dist/ | ||
|
|
||
| - name: Publish distribution to PyPI | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
| - name: Publish distribution to PyPI | ||
| # this step publishes the distribution files to PyPI by using PyPI trusted publishers | ||
| # https://docs.pypi.org/trusted-publishers/ | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the benefit of using a GHA environment here? We won't be using any of the features (or will we?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know.

There's a claim in the setup instructions from PyPI that recommends it. I think they've clarified a bit why, I don't remember seeing it when I set it up.
In https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/
Second image, the first one on setting up GHA:
And the note below it:
@AdamRJensen I won't be able to test this locally with act until weekend/next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@echedey-ls let me know if I should do something, e.g., merge this PR and make a pre-release.