1# 2# GitHub actions for building the distribution and wheels of the sgp4 package 3# linting and testing the source. 4# 5# Contributed by @mworion 6# 7# Strategy: 8# The action is called with each commit, pull request master (and) release 9# branch. If commit is to release branch, the PyPI upload will follow 10# successful tests automatically. 11# 12# Run lint on python source, build step by step the python distro and 13# run all package tests for all OS and python versions 14# 15# If this job succeeds, build step by step all wheels for all OS and python 16# versions and run the tests in accelerated mode. 17# 18# If the first two jobs succeed, upload the distro and wheels to PyPI 19# 20 21name: test_package 22 23on: 24 # the trigger event for running the action is either a push on master or 25 # release branch 26 27 push: 28 branches: 29 - master 30 - release 31 32 # or a pull request to master branch 33 pull_request: 34 branches: 35 - master 36 37jobs: 38 # This action is split into three jobs: 39 # - Building the distribution linting and testing without acceleration 40 # - Building the wheels for the distribution and testing with acceleration 41 # - Uploading the artifacts to PyPI package if branch is release 42 # The uploading job needs all tests to be finished without error. 43 44 build_test_dist: 45 # Build the distribution in a matrix. Jobs are done in parallel. 46 # The formal distro which is uploaded to PyPI will be build on 47 # ubuntu-latest for python 3.9, which is the recent one. 48 # As in dist build no compilation takes place, we run all tests 49 # in not accelerated mode. 50 51 runs-on: ${{ matrix.os }} 52 strategy: 53 max-parallel: 18 54 matrix: 55 python-version: [2.7, 3.6, 3.7, 3.8, 3.9] 56 os: [ubuntu-latest, windows-latest, macos-latest] 57 58 steps: 59 - name: checkout 60 uses: actions/checkout@v2 61 62 - name: Setup_Python_${{ matrix.python-version }} 63 uses: actions/setup-python@v2 64 with: 65 python-version: ${{ matrix.python-version }} 66 67 # The build test needs numpy and pyflakes. Adding twine enables for 68 # testing and checking the metadata. Adding wheels for package 69 # installation before running the tests 70 71 - name: install_deps 72 run: pip install numpy pyflakes 73 74 - name: build_sdist 75 run: python setup.py sdist 76 77 - name: check_metadata 78 if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' 79 run: | 80 pip install twine 81 twine check dist/* 82 83 - name: upload_sdist 84 if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' 85 uses: actions/upload-artifact@v2 86 with: 87 name: dist 88 path: dist/*.tar.gz 89 90 - name: copy_file 91 run: mv dist/sgp4*.* dist/sgp4.tar.gz 92 93 - name: install_dist 94 run: | 95 pip install dist/sgp4.tar.gz 96 python -c "from sgp4.api import accelerated; print(accelerated)" 97 98 - name: run_tests 99 run: python -m sgp4.tests 100 101 build_test_wheels: 102 # Building wheels for different OS and python versions. This is done with 103 # the help of 'cibuildwheel' package. It will run on the three different 104 # supported OS each running cibuildwheel on newest python supported as 105 # default on github. 106 # Reference: https://cibuildwheel.readthedocs.io/en/stable/ 107 # OS: Windows, Linux and macOS 108 # Python: versions 3.5 - 3.9 (limited by capabilities cibuildwheel) 109 # As all build wheels are installed after build, the tests run in 110 # accelerated mode only. 111 # 112 # Actually need to address cp39 in CIBW_BUILD explicit, otherwise 113 # only cp36 - cp38 are build. No earlier versions, fits exactly 114 # to actual travis (except aarch64, which is not supported on github) 115 116 runs-on: ${{ matrix.os }} 117 needs: [build_test_dist] 118 119 strategy: 120 max-parallel: 3 121 matrix: 122 os: [windows-latest, ubuntu-latest, macos-latest] 123 python-version: [3.7] 124 125 steps: 126 - name: checkout 127 uses: actions/checkout@v2 128 129 - name: Setup_Python_${{ matrix.python-version }} 130 uses: actions/setup-python@v2 131 with: 132 python-version: ${{ matrix.python-version }} 133 134 - name: install_deps 135 run: python -m pip install cibuildwheel 136 137 - name: build_test 138 run: python -m cibuildwheel --output-dir wheelhouse 139 env: 140 CIBW_BUILD: "cp36-* cp37-* cp38-* cp39-*" 141 CIBW_BUILD_VERBOSITY: 0 142 CIBW_TEST_REQUIRES: numpy 143 CIBW_TEST_COMMAND: python -m sgp4.tests 144 145 - name: upload_wheels 146 uses: actions/upload-artifact@v2 147 with: 148 name: wheelhouse 149 path: wheelhouse 150 151 upload_to_pypi: 152 # Finally, we collect all out data from the artifacts and put them back to 153 # dist directory for an upload. The final step waits for the other jobs to 154 # be finished and starts only if the trigger event of the action was a push 155 # on release branch 156 157 runs-on: [ubuntu-latest] 158 needs: [build_test_dist, build_test_wheels] 159 160 if: | 161 github.event_name == 'push' && 162 github.ref == 'refs/heads/release' 163 164 steps: 165 - uses: actions/setup-python@v2 166 167 # download dist files 168 - uses: actions/download-artifact@v2 169 with: 170 name: dist 171 path: dist 172 173 # download wheels 174 - uses: actions/download-artifact@v2 175 with: 176 name: wheelhouse 177 path: dist 178 179 # For the activation of the PyPI index, please add a secret token from 180 # PyPI to the GitHub repo, give it a name and replace in the password 181 # reference the <pypi_password> with the name of the secret's name you have 182 # chosen for the PyPI token. 183 184 - name: upload_to_pypi 185 uses: pypa/gh-action-pypi-publish@v1.4.1 186 with: 187 user: __token__ 188 password: ${{ secrets.pypi_password }} 189 skip_existing: true 190