|
| 1 | +#This workflow will install Python dependencies, run tests and lint with a variety of Python versions |
| 2 | +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions |
| 3 | + |
| 4 | +# For deployment, it will be necessary to create a PyPI API token and store it as a secret |
| 5 | +# https://docs.github.com/en/actions/reference/encrypted-secrets |
| 6 | + |
| 7 | +name: CI/CD |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: [ main, develop ] |
| 12 | + tags: [ '*' ] |
| 13 | + pull_request: |
| 14 | + branches: [ main, develop ] |
| 15 | + |
| 16 | +jobs: |
| 17 | + devcheck: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + strategy: |
| 20 | + matrix: |
| 21 | + python-version: ['3.8', '3.12'] # Check oldest and newest versions |
| 22 | + pip-flags: ['', '--editable'] |
| 23 | + pydra: |
| 24 | + - 'pydra' |
| 25 | + - '--editable git+https://github.com/nipype/pydra.git#egg=pydra' |
| 26 | + |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + - name: Set up Python ${{ matrix.python-version }} |
| 30 | + uses: actions/setup-python@v5 |
| 31 | + with: |
| 32 | + python-version: ${{ matrix.python-version }} |
| 33 | + - name: Install build dependencies |
| 34 | + run: | |
| 35 | + python -m pip install --upgrade pip |
| 36 | + - name: Install Pydra |
| 37 | + run: | |
| 38 | + pip install ${{ matrix.pydra }} |
| 39 | + python -c "import pydra as m; print(f'{m.__name__} {m.__version__} @ {m.__file__}')" |
| 40 | + - name: Install task package |
| 41 | + run: | |
| 42 | + pip install ${{ matrix.pip-flags }} ".[dev]" |
| 43 | + python -c "import pydra.workers.CHANGEME as m; print(f'{m.__name__} {m.__version__} @ {m.__file__}')" |
| 44 | + python -c "import pydra as m; print(f'{m.__name__} {m.__version__} @ {m.__file__}')" |
| 45 | +
|
| 46 | + test: |
| 47 | + runs-on: ubuntu-latest |
| 48 | + strategy: |
| 49 | + matrix: |
| 50 | + python-version: [3.7, 3.8, 3.9, '3.10'] |
| 51 | + |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v4 |
| 54 | + - name: Set up Python ${{ matrix.python-version }} |
| 55 | + uses: actions/setup-python@v5 |
| 56 | + with: |
| 57 | + python-version: ${{ matrix.python-version }} |
| 58 | + - name: Install build dependencies |
| 59 | + run: | |
| 60 | + python -m pip install --upgrade pip |
| 61 | + - name: Install task package |
| 62 | + run: | |
| 63 | + pip install ".[test]" |
| 64 | + python -c "import pydra.workers.CHANGEME as m; print(f'{m.__name__} {m.__version__} @ {m.__file__}')" |
| 65 | + python -c "import pydra as m; print(f'{m.__name__} {m.__version__} @ {m.__file__}')" |
| 66 | + - name: Test with pytest |
| 67 | + run: | |
| 68 | + pytest -sv --doctest-modules pydra/workers/CHANGEME \ |
| 69 | + --cov pydra.workers.CHANGEME --cov-report xml |
| 70 | + - uses: codecov/codecov-action@v3 |
| 71 | + if: ${{ always() }} |
| 72 | + |
| 73 | + |
| 74 | + deploy: |
| 75 | + needs: [devcheck, test] |
| 76 | + runs-on: ubuntu-latest |
| 77 | + strategy: |
| 78 | + matrix: |
| 79 | + python-version: [3.9] |
| 80 | + steps: |
| 81 | + - uses: actions/checkout@v4 |
| 82 | + with: |
| 83 | + submodules: recursive |
| 84 | + fetch-depth: 0 |
| 85 | + - name: Set up Python ${{ matrix.python-version }} |
| 86 | + uses: actions/setup-python@v5 |
| 87 | + with: |
| 88 | + python-version: ${{ matrix.python-version }} |
| 89 | + - name: Install build tools |
| 90 | + run: python -m pip install build twine |
| 91 | + - name: Build source and wheel distributions |
| 92 | + run: python -m build |
| 93 | + - name: Check distributions |
| 94 | + run: twine check dist/* |
| 95 | + - uses: actions/upload-artifact@v4 |
| 96 | + with: |
| 97 | + name: distributions |
| 98 | + path: dist/ |
| 99 | + # Deploy on tags if PYPI_API_TOKEN is defined in the repository secrets. |
| 100 | + # Secrets are not accessible in the if: condition [0], so set an output variable [1] |
| 101 | + # [0] https://github.community/t/16928 |
| 102 | + # [1] https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter |
| 103 | + - name: Check for PyPI token on tag |
| 104 | + id: deployable |
| 105 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 106 | + env: |
| 107 | + PYPI_API_TOKEN: "${{ secrets.PYPI_API_TOKEN }}" |
| 108 | + run: if [ -n "$PYPI_API_TOKEN" ]; then echo "DEPLOY=true" >> $GITHUB_OUTPUT; fi |
| 109 | + - name: Upload to PyPI |
| 110 | + if: steps.deployable.outputs.DEPLOY |
| 111 | + uses: pypa/gh-action-pypi-publish@37f50c210e3d2f9450da2cd423303d6a14a6e29f # v1.5.1 |
| 112 | + with: |
| 113 | + user: __token__ |
| 114 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments