|
| 1 | +name: Python Linting, Test and Upload |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + # JOB |
| 10 | + # This job runs unit tests, linting and format checks |
| 11 | + tests: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + strategy: |
| 15 | + # If either the tests for 3.8 or 3.10 fail all workflows |
| 16 | + # are terminated to safe computing resources. |
| 17 | + fail-fast: true |
| 18 | + # To safe runtime least and latest version supported are |
| 19 | + # chosen. We go for 3.8 due to some dependencies. For more |
| 20 | + # info see the pyproject.toml |
| 21 | + matrix: |
| 22 | + python-version: ["3.8", "3.10"] |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v3 |
| 26 | + |
| 27 | + - name: Set up Python ${{ matrix.python-version }} |
| 28 | + uses: actions/setup-python@v4 |
| 29 | + with: |
| 30 | + python-version: ${{ matrix.python-version }} |
| 31 | + |
| 32 | + - name: Install Task |
| 33 | + run: | |
| 34 | + sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d |
| 35 | +
|
| 36 | + # Cache dependencies from poetry to speed things up |
| 37 | + - name: Load cached venv |
| 38 | + id: cached-poetry-dependencies |
| 39 | + uses: actions/cache@v3 |
| 40 | + with: |
| 41 | + path: .venv |
| 42 | + key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} |
| 43 | + |
| 44 | + - name: Install and upgrade pip and poetry |
| 45 | + run: python -m pip install --upgrade pip poetry |
| 46 | + |
| 47 | + - name: Install Dependencies |
| 48 | + run: ./bin/task setup |
| 49 | + |
| 50 | + - name: Lint code |
| 51 | + run: ./bin/task lint |
| 52 | + |
| 53 | + - name: Test code |
| 54 | + run: ./bin/task test |
| 55 | + |
| 56 | + # JOB |
| 57 | + # This job publishes the package to test-pipy. |
| 58 | + test-publish: |
| 59 | + # Will run after the job 'tests' |
| 60 | + needs: [tests] |
| 61 | + |
| 62 | + if: > |
| 63 | + startsWith(github.ref, 'refs/tags/') || |
| 64 | + startsWith(github.ref, 'refs/heads/release/') |
| 65 | + runs-on: ubuntu-latest |
| 66 | + # Required for installation of the test package in the |
| 67 | + # next job. |
| 68 | + outputs: |
| 69 | + version: ${{ steps.extract_version.outputs.version }} |
| 70 | + |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v3 |
| 73 | + |
| 74 | + - name: Remember version |
| 75 | + id: extract_version |
| 76 | + run: | |
| 77 | + VERSION=$(cat pyproject.toml | grep -oE -m 1 "version = \"(.*)\"" | cut -f2 -d '"') |
| 78 | + echo "Version: ${VERSION}" |
| 79 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 80 | +
|
| 81 | + # For publishing any version will do |
| 82 | + - name: Set up Python 3.10 |
| 83 | + uses: actions/setup-python@v4 |
| 84 | + with: |
| 85 | + python-version: "3.10" |
| 86 | + |
| 87 | + - name: Install Task |
| 88 | + run: | |
| 89 | + sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d |
| 90 | +
|
| 91 | + - name: Load cached venv |
| 92 | + id: cached-poetry-dependencies |
| 93 | + uses: actions/cache@v3 |
| 94 | + with: |
| 95 | + path: .venv |
| 96 | + key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} |
| 97 | + |
| 98 | + - name: Install Dependencies |
| 99 | + run: | |
| 100 | + python -m pip install --upgrade pip poetry |
| 101 | + ./bin/task setup |
| 102 | +
|
| 103 | + - name: Build packages for release |
| 104 | + run: ./bin/task build |
| 105 | + |
| 106 | + - name: Publish distribution to Test PyPI |
| 107 | + env: |
| 108 | + TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/ |
| 109 | + TWINE_USERNAME: __token__ |
| 110 | + TWINE_NON_INTERACTIVE: 1 |
| 111 | + TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 112 | + run: poetry run twine upload --skip-existing --verbose 'dist/*' |
| 113 | + |
| 114 | + # JOB |
| 115 | + # Test install from pypi to see if we have any installation bugs. |
| 116 | + test-install: |
| 117 | + needs: [test-publish] |
| 118 | + if: > |
| 119 | + startsWith(github.ref, 'refs/tags/') || |
| 120 | + startsWith(github.ref, 'refs/heads/release/') |
| 121 | +
|
| 122 | + runs-on: ubuntu-latest |
| 123 | + |
| 124 | + # Use the version from the previous job |
| 125 | + env: |
| 126 | + VERSION: ${{ needs.test-publish.outputs.version }} |
| 127 | + |
| 128 | + steps: |
| 129 | + # Install python (be aware NO checkout action) |
| 130 | + - name: Set up Python 3.10 |
| 131 | + uses: actions/setup-python@v4 |
| 132 | + with: |
| 133 | + python-version: "3.10" |
| 134 | + |
| 135 | + # Check if it installs without errors |
| 136 | + - name: Install package |
| 137 | + run: | |
| 138 | + python -m pip install \ |
| 139 | + --index-url https://test.pypi.org/simple/ \ |
| 140 | + --extra-index-url https://pypi.org/simple \ |
| 141 | + lasso-python=="${VERSION}" |
| 142 | +
|
| 143 | + # We run the D3plot import here as it is the most delicate piece of the |
| 144 | + # package for importing C-libraries. |
| 145 | + - name: Test if the installed package works |
| 146 | + run: python -c 'from lasso.dyna import D3plot' |
| 147 | + |
| 148 | + # JOB |
| 149 | + # Finally publish the code to pypi |
| 150 | + publish: |
| 151 | + needs: [test-install] |
| 152 | + if: startsWith(github.ref, 'refs/tags/') |
| 153 | + runs-on: ubuntu-latest |
| 154 | + |
| 155 | + steps: |
| 156 | + - uses: actions/checkout@v3 |
| 157 | + |
| 158 | + - name: Set up Python 3.10 |
| 159 | + uses: actions/setup-python@v4 |
| 160 | + with: |
| 161 | + python-version: "3.10" |
| 162 | + |
| 163 | + - name: Install Task |
| 164 | + run: | |
| 165 | + sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d |
| 166 | +
|
| 167 | + - name: Load cached venv |
| 168 | + id: cached-poetry-dependencies |
| 169 | + uses: actions/cache@v3 |
| 170 | + with: |
| 171 | + path: .venv |
| 172 | + key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} |
| 173 | + |
| 174 | + - name: Install Dependencies |
| 175 | + run: | |
| 176 | + python -m pip install --upgrade poetry pip |
| 177 | + ./bin/task setup |
| 178 | +
|
| 179 | + - name: Build packages for release |
| 180 | + run: ./bin/task build |
| 181 | + |
| 182 | + # Not required but this saves the distribution files |
| 183 | + # with the package upload for debugging purposes. |
| 184 | + - name: Save packages as artifacts |
| 185 | + uses: actions/upload-artifact@v2 |
| 186 | + with: |
| 187 | + name: dist |
| 188 | + path: dist |
| 189 | + if-no-files-found: error |
| 190 | + |
| 191 | + - name: Publish distribution to PyPI |
| 192 | + env: |
| 193 | + TWINE_USERNAME: __token__ |
| 194 | + TWINE_NON_INTERACTIVE: 1 |
| 195 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 196 | + run: poetry run twine upload --skip-existing --verbose 'dist/*' |
| 197 | + |
| 198 | + - name: Upload new docs |
| 199 | + run: ./bin/task docs:deploy |
0 commit comments