-
Notifications
You must be signed in to change notification settings - Fork 371
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
BLD: Wheels! #2197
Merged
Merged
BLD: Wheels! #2197
Changes from all commits
Commits
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 was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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,63 +1,126 @@ | ||
name: Build and upload to PyPI | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }} | ||
cancel-in-progress: true | ||
|
||
# Only build on published releases | ||
on: | ||
release: | ||
types: | ||
- published | ||
|
||
jobs: | ||
build: | ||
name: Build sdist | ||
runs-on: ubuntu-18.04 | ||
defaults: | ||
run: | ||
shell: bash -l {0} | ||
build_sdist: | ||
name: Build source distribution | ||
runs-on: ubuntu-latest | ||
outputs: | ||
SDIST_NAME: ${{ steps.sdist.outputs.SDIST_NAME }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: conda-incubator/setup-miniconda@v2 | ||
with: | ||
activate-environment: test-environment | ||
python-version: ${{ matrix.python-version }} | ||
channels: conda-forge/label/testing,conda-forge | ||
# We need the full history to generate the proper version number | ||
fetch-depth: 0 | ||
|
||
- uses: actions/setup-python@v4 | ||
name: Install Python | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install dependencies | ||
run: python -m pip install build twine | ||
|
||
- name: Build sdist | ||
id: sdist | ||
run: | | ||
PACKAGES="cython fiona matplotlib-base numpy pyproj pykdtree scipy" | ||
PACKAGES="$PACKAGES owslib pep8 pillow pyshp pytest" | ||
PACKAGES="$PACKAGES pytest-xdist setuptools_scm shapely" | ||
conda install $PACKAGES | ||
python -m build --sdist | ||
# Get the name of the build sdist file for later use | ||
echo "SDIST_NAME=$(ls -1 dist)" >> $GITHUB_OUTPUT | ||
|
||
- name: Create sdist | ||
run: python setup.py build_ext sdist | ||
- name: Check README rendering for PyPI | ||
run: twine check dist/* | ||
|
||
- name: Save built packages as artifact | ||
- name: Upload sdist result | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: packages-${{ runner.os }}-${{ matrix.python-version }} | ||
path: dist/ | ||
name: sdist | ||
path: dist/*.tar.gz | ||
if-no-files-found: error | ||
retention-days: 5 | ||
|
||
generate-wheels-matrix: | ||
name: Generate wheels matrix | ||
runs-on: ubuntu-latest | ||
outputs: | ||
include: ${{ steps.set-matrix.outputs.include }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install cibuildwheel | ||
run: pipx install cibuildwheel==f21bb8376a051ffb6cb5604b28ccaef7b90e8ab7 # v2.14.1 | ||
- id: set-matrix | ||
run: | | ||
MATRIX=$( | ||
{ | ||
cibuildwheel --print-build-identifiers --platform linux \ | ||
| jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \ | ||
&& cibuildwheel --print-build-identifiers --platform macos \ | ||
| jq -nRc '{"only": inputs, "os": "macos-latest"}' \ | ||
&& cibuildwheel --print-build-identifiers --platform windows \ | ||
| jq -nRc '{"only": inputs, "os": "windows-2019"}' | ||
} | jq -sc | ||
) | ||
echo "include=$MATRIX" >> $GITHUB_OUTPUT | ||
env: | ||
CIBW_BUILD: "cp39-* cp310-* cp311-*" | ||
# Skip 32 bit windows builds and musllinux due to lack of numpy wheels | ||
CIBW_SKIP: "*-win32 *-musllinux*" | ||
CIBW_ARCHS_MACOS: x86_64 arm64 | ||
|
||
build_wheels: | ||
name: Build ${{ matrix.os }} ${{ matrix.only }} | ||
needs: [generate-wheels-matrix, build_sdist] | ||
strategy: | ||
matrix: | ||
include: ${{ fromJson(needs.generate-wheels-matrix.outputs.include) }} | ||
runs-on: ${{ matrix.os }} | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
|
||
- name: Download sdist | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: sdist | ||
path: dist/ | ||
|
||
- uses: pypa/cibuildwheel@f21bb8376a051ffb6cb5604b28ccaef7b90e8ab7 # v2.14.1 | ||
with: | ||
only: ${{ matrix.only }} | ||
package-dir: dist/${{ needs.build_sdist.outputs.SDIST_NAME }} | ||
|
||
- uses: actions/upload-artifact@v3 | ||
with: | ||
path: ./wheelhouse/*.whl | ||
|
||
publish: | ||
name: Publish to PyPI | ||
needs: build | ||
# Only publish on releases | ||
if: github.event_name == 'release' | ||
needs: [build_wheels, build_sdist] | ||
environment: | ||
name: PyPI | ||
url: https://pypi.org/project/cartopy | ||
permissions: | ||
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing | ||
runs-on: ubuntu-18.04 | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Download packages | ||
uses: actions/download-artifact@v3 | ||
|
||
- name: Consolidate packages for upload | ||
run: | | ||
mkdir dist | ||
cp packages-*/* dist/ | ||
dopplershift marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with: | ||
name: artifact | ||
path: dist | ||
|
||
- name: Publish Package | ||
uses: pypa/gh-action-pypi-publish@v1.8.8 |
Oops, something went wrong.
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.
Isn't this redundant with the entire workflow's
on
trigger? Should that be removed?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.
You beat me to this :) I was just going to add a comment here indicating I added this. I agree it is the same as the trigger, but this is an extra safeguard that I think is worth it in this case. For example, when I was testing building wheels on my fork, I removed the "on: release", but this would fail because I don't have credentials. However, then I force-pushed to this branch, and all of a sudden triggered this workflow on the PR. I'm not entirely clear it would have gone through the action but it seems prudent to keep to me just to make sure I don't fat finger something again on accident. In the future, we may want to change the trigger to let us trigger it automatically on certain pushes or on request.
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.
PRs shouldn't have any of the credentials/write permissions necessary.
Also, there's no way this workflow as written should be able to trigger on a PR.
That said, there's no harm in being careful.