|
| 1 | +name: linux |
| 2 | + |
| 3 | +# Only build PRs, the main branch, and releases. |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + release: |
| 10 | + types: |
| 11 | + - published |
| 12 | + schedule: |
| 13 | + - cron: "14 14 20 * *" |
| 14 | + |
| 15 | +# Use bash by default in all jobs |
| 16 | +defaults: |
| 17 | + run: |
| 18 | + # Using "-l {0}" is necessary for conda environments to be activated |
| 19 | + # But this breaks on MacOS if using actions/setup-python: |
| 20 | + # https://github.com/actions/setup-python/issues/132 |
| 21 | + shell: bash |
| 22 | + |
| 23 | +# Cancel any previous run of the test job. |
| 24 | +concurrency: |
| 25 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 26 | + cancel-in-progress: true |
| 27 | + |
| 28 | +jobs: |
| 29 | + test: |
| 30 | + |
| 31 | + name: basic |
| 32 | + runs-on: ubuntu-latest |
| 33 | + |
| 34 | + steps: |
| 35 | + |
| 36 | + # Checks-out your repository under $GITHUB_WORKSPACE |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + # Need to fetch more than the last commit so that setuptools-scm can |
| 41 | + # create the correct version string. If the number of commits since |
| 42 | + # the last release is greater than this, the version still be wrong. |
| 43 | + # Increase if necessary. |
| 44 | + fetch-depth: 100 |
| 45 | + # The GitHub token is preserved by default but this job doesn't need |
| 46 | + # to be able to push to GitHub. |
| 47 | + persist-credentials: false |
| 48 | + |
| 49 | + # Need the tags so that setuptools-scm can form a valid version number |
| 50 | + - name: Fetch git tags |
| 51 | + run: git fetch origin 'refs/tags/*:refs/tags/*' |
| 52 | + |
| 53 | + - name: Setup Python |
| 54 | + uses: actions/setup-python@v5 |
| 55 | + with: |
| 56 | + python-version: "3.11" |
| 57 | + |
| 58 | + - name: Install dependencies |
| 59 | + shell: bash -l {0} |
| 60 | + run: | |
| 61 | + python -m pip install --upgrade pip |
| 62 | + python -m pip install -r requirements-dev.txt |
| 63 | +
|
| 64 | + - name: Flake8 |
| 65 | + shell: bash -l {0} |
| 66 | + run: flake8 docs/conf.py setup.py resmda/ tests/ |
| 67 | + |
| 68 | + - name: Test with pytest |
| 69 | + shell: bash -l {0} |
| 70 | + run: | |
| 71 | + python -m pip install . |
| 72 | + pytest --cov=resmda |
| 73 | +
|
| 74 | + deploy: |
| 75 | + needs: test |
| 76 | + name: Deploy to PyPI |
| 77 | + runs-on: ubuntu-latest |
| 78 | + # Only from the origin repository, not forks; only main and tags. |
| 79 | + if: github.repository_owner == 'tuda' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) |
| 80 | + |
| 81 | + steps: |
| 82 | + # Checks-out your repository under $GITHUB_WORKSPACE |
| 83 | + - name: Checkout |
| 84 | + uses: actions/checkout@v4 |
| 85 | + with: |
| 86 | + # Need to fetch more than the last commit so that setuptools-scm can |
| 87 | + # create the correct version string. If the number of commits since |
| 88 | + # the last release is greater than this, the version will still be |
| 89 | + # wrong. Increase if necessary. |
| 90 | + fetch-depth: 100 |
| 91 | + # The GitHub token is preserved by default but this job doesn't need |
| 92 | + # to be able to push to GitHub. |
| 93 | + persist-credentials: false |
| 94 | + |
| 95 | + # Need the tags so that setuptools-scm can form a valid version number |
| 96 | + - name: Fetch git tags |
| 97 | + run: git fetch origin 'refs/tags/*:refs/tags/*' |
| 98 | + |
| 99 | + - name: Setup Python |
| 100 | + uses: actions/setup-python@v5 |
| 101 | + with: |
| 102 | + python-version: "3.11" |
| 103 | + |
| 104 | + - name: Install dependencies |
| 105 | + run: | |
| 106 | + python -m pip install --upgrade pip |
| 107 | + python -m pip install build setuptools-scm |
| 108 | +
|
| 109 | + - name: Build source and wheel distributions |
| 110 | + if: github.ref == 'refs/heads/main' |
| 111 | + run: | |
| 112 | + # Change setuptools-scm local_scheme to "no-local-version" so the |
| 113 | + # local part of the version isn't included, making the version string |
| 114 | + # compatible with Test PyPI. |
| 115 | + sed --in-place 's/"root"/"local_scheme":"no-local-version","root"/g' setup.py |
| 116 | +
|
| 117 | + - name: Build source and wheel distributions |
| 118 | + run: | |
| 119 | + # Build source and wheel packages |
| 120 | + python -m build |
| 121 | + echo "" |
| 122 | + echo "Generated files:" |
| 123 | + ls -lh dist/ |
| 124 | +
|
| 125 | + - name: Publish to Test PyPI |
| 126 | + if: success() |
| 127 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 128 | + with: |
| 129 | + user: __token__ |
| 130 | + password: ${{ secrets.TEST_PYPI_PASSWORD }} |
| 131 | + repository_url: https://test.pypi.org/legacy/ |
| 132 | + # Allow existing releases on test PyPI without errors. |
| 133 | + # NOT TO BE USED in PyPI! |
| 134 | + skip_existing: true |
| 135 | + |
| 136 | + - name: Publish to PyPI |
| 137 | + # Only for releases |
| 138 | + if: success() && github.event_name == 'release' |
| 139 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 140 | + with: |
| 141 | + user: __token__ |
| 142 | + password: ${{ secrets.PYPI_PASSWORD }} |
0 commit comments