|
| 1 | +name: CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + release: |
| 9 | + types: [published] |
| 10 | + |
| 11 | +defaults: |
| 12 | + run: |
| 13 | + shell: bash |
| 14 | + |
| 15 | +jobs: |
| 16 | + test: |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + os: [ubuntu-latest] |
| 20 | + python-version: ["3.8", "3.12"] |
| 21 | + fail-fast: false |
| 22 | + runs-on: ${{ matrix.os }} |
| 23 | + defaults: |
| 24 | + run: |
| 25 | + shell: bash -l {0} |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v2 |
| 29 | + - name: Unset header |
| 30 | + # checkout@v2 adds a header that makes branch protection report errors |
| 31 | + # because the Github action bot is not a collaborator on the repo |
| 32 | + run: git config --local --unset http.https://github.com/.extraheader |
| 33 | + - name: Fetch tags |
| 34 | + run: git fetch --prune --unshallow |
| 35 | + - name: Disable etelemetry |
| 36 | + run: echo "NO_ET=TRUE" >> $GITHUB_ENV |
| 37 | + - name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }} |
| 38 | + uses: actions/setup-python@v2 |
| 39 | + with: |
| 40 | + python-version: ${{ matrix.python-version }} |
| 41 | + - name: Update build tools |
| 42 | + run: python3 -m pip install --upgrade pip |
| 43 | + - name: Install Package |
| 44 | + run: python3 -m pip install -e related-packages/fileformats[test] -e related-packages/fileformats-extras[test] |
| 45 | + - name: Pytest |
| 46 | + run: pytest -vvs --cov fileformats.medimage_CHANGEME --cov-config .coveragerc --cov-report xml . |
| 47 | + - name: Upload coverage to Codecov |
| 48 | + uses: codecov/codecov-action@v2 |
| 49 | + with: |
| 50 | + fail_ci_if_error: true |
| 51 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 52 | + |
| 53 | + build: |
| 54 | + needs: [test] |
| 55 | + runs-on: ubuntu-latest |
| 56 | + strategy: |
| 57 | + matrix: |
| 58 | + pkg: |
| 59 | + - ["main", "related-packages/fileformats"] |
| 60 | + - ["extras", "related-packages/fileformats-extras"] |
| 61 | + steps: |
| 62 | + - uses: actions/checkout@v3 |
| 63 | + with: |
| 64 | + submodules: recursive |
| 65 | + fetch-depth: 0 |
| 66 | + - name: Unset header |
| 67 | + # checkout@v2 adds a header that makes branch protection report errors |
| 68 | + # because the Github action bot is not a collaborator on the repo |
| 69 | + run: git config --local --unset http.https://github.com/.extraheader |
| 70 | + - name: Set up Python |
| 71 | + uses: actions/setup-python@v4 |
| 72 | + with: |
| 73 | + python-version: '3.12' |
| 74 | + - name: Install build tools |
| 75 | + run: python3 -m pip install build twine |
| 76 | + - name: Build source and wheel distributions |
| 77 | + run: python3 -m build ${{ matrix.pkg[1] }} |
| 78 | + - name: Check distributions |
| 79 | + run: twine check ${{ matrix.pkg[1] }}/dist/* |
| 80 | + - uses: actions/upload-artifact@v3 |
| 81 | + with: |
| 82 | + name: built-${{ matrix.pkg[0] }} |
| 83 | + path: ${{ matrix.pkg[1] }}/dist |
| 84 | + |
| 85 | + deploy: |
| 86 | + needs: [build] |
| 87 | + runs-on: ubuntu-latest |
| 88 | + steps: |
| 89 | + - name: Download build |
| 90 | + uses: actions/download-artifact@v3 |
| 91 | + with: |
| 92 | + name: built-main |
| 93 | + path: dist |
| 94 | + - name: Check for PyPI token on tag |
| 95 | + id: deployable |
| 96 | + if: github.event_name == 'release' |
| 97 | + env: |
| 98 | + PYPI_API_TOKEN: "${{ secrets.FILEFORMATS_PYPI_API_TOKEN }}" |
| 99 | + run: if [ -n "$PYPI_API_TOKEN" ]; then echo "DEPLOY=true" >> $GITHUB_OUTPUT; fi |
| 100 | + - name: Upload to PyPI |
| 101 | + if: steps.deployable.outputs.DEPLOY |
| 102 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 103 | + with: |
| 104 | + user: __token__ |
| 105 | + password: ${{ secrets.FILEFORMATS_PYPI_API_TOKEN }} |
| 106 | + |
| 107 | + deploy-extras: |
| 108 | + needs: [build, deploy] |
| 109 | + runs-on: ubuntu-latest |
| 110 | + steps: |
| 111 | + - name: Download build |
| 112 | + uses: actions/download-artifact@v3 |
| 113 | + with: |
| 114 | + name: built-extras |
| 115 | + path: dist |
| 116 | + - name: Check for PyPI token on tag |
| 117 | + id: deployable |
| 118 | + if: github.event_name == 'release' |
| 119 | + env: |
| 120 | + EXTRAS_PYPI_API_TOKEN: "${{ secrets.FILEFORMATS_EXTRAS_PYPI_API_TOKEN }}" |
| 121 | + run: if [ -n "$EXTRAS_PYPI_API_TOKEN" ]; then echo "DEPLOY=true" >> $GITHUB_OUTPUT; fi |
| 122 | + - name: Upload to PyPI |
| 123 | + if: steps.deployable.outputs.DEPLOY |
| 124 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 125 | + with: |
| 126 | + user: __token__ |
| 127 | + password: ${{ secrets.FILEFORMATS_EXTRAS_PYPI_API_TOKEN }} |
| 128 | + |
| 129 | +# Deploy on tags if PYPI_API_TOKEN is defined in the repository secrets. |
| 130 | +# Secrets are not accessible in the if: condition [0], so set an output variable [1] |
| 131 | +# [0] https://github.community/t/16928 |
| 132 | +# [1] https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter |
0 commit comments