|
| 1 | +# .github/workflows/base.yml |
| 2 | +name: Build |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '*' |
| 7 | + branches: |
| 8 | + - main |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | +jobs: |
| 13 | + # pre-job to read nox tests matrix - see https://stackoverflow.com/q/66747359/7262247 |
| 14 | + list_nox_test_sessions: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v2 |
| 18 | + - uses: actions/setup-python@v1 |
| 19 | + with: |
| 20 | + python-version: 3.7 |
| 21 | + architecture: x64 |
| 22 | + |
| 23 | + - name: Install noxfile requirements |
| 24 | + shell: bash -l {0} |
| 25 | + run: pip install -r noxfile-requirements.txt |
| 26 | + |
| 27 | + - name: List 'tests' nox sessions |
| 28 | + id: set-matrix |
| 29 | + run: echo "::set-output name=matrix::$(nox -s gha_list -- tests)" |
| 30 | + outputs: |
| 31 | + matrix: ${{ steps.set-matrix.outputs.matrix }} # save nox sessions list to outputs |
| 32 | + |
| 33 | + run_all_tests: |
| 34 | + needs: list_nox_test_sessions |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + os: [ ubuntu-latest ] # , macos-latest, windows-latest] |
| 39 | + # all nox sessions: manually > dynamically from previous job |
| 40 | + # nox_session: ["tests-2.7(env='pytest2.x')", "tests-3.7(env='pytest-latest')"] |
| 41 | + nox_session: ${{ fromJson(needs.list_nox_test_sessions.outputs.matrix) }} |
| 42 | + |
| 43 | + name: ${{ matrix.os }} ${{ matrix.nox_session }} # ${{ matrix.name_suffix }} |
| 44 | + runs-on: ${{ matrix.os }} |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v2 |
| 47 | + |
| 48 | + # Conda install |
| 49 | + - name: Install conda v3.7 |
| 50 | + uses: conda-incubator/setup-miniconda@v2 |
| 51 | + with: |
| 52 | + # auto-update-conda: true |
| 53 | + python-version: 3.7 |
| 54 | + activate-environment: noxenv |
| 55 | + - run: conda info |
| 56 | + shell: bash -l {0} # so that conda works |
| 57 | + - run: conda list |
| 58 | + shell: bash -l {0} # so that conda works |
| 59 | + |
| 60 | + # Nox install + run |
| 61 | + - name: Install noxfile requirements |
| 62 | + shell: bash -l {0} # so that conda works |
| 63 | + run: pip install -r noxfile-requirements.txt |
| 64 | + - run: conda list |
| 65 | + shell: bash -l {0} # so that conda works |
| 66 | + - run: nox -s "${{ matrix.nox_session }}" |
| 67 | + shell: bash -l {0} # so that conda works |
| 68 | + |
| 69 | + # Share ./docs/reports so that they can be deployed with doc in next job |
| 70 | + - name: Share reports with other jobs |
| 71 | + # if: matrix.nox_session == '...': not needed, if empty wont be shared |
| 72 | + uses: actions/upload-artifact@master |
| 73 | + with: |
| 74 | + name: reports_dir |
| 75 | + path: ./docs/reports |
| 76 | + |
| 77 | + publish_release: |
| 78 | + needs: run_all_tests |
| 79 | + runs-on: ubuntu-latest |
| 80 | + steps: |
| 81 | + - name: GitHub context to debug conditional steps |
| 82 | + env: |
| 83 | + GITHUB_CONTEXT: ${{ toJSON(github) }} |
| 84 | + run: echo "$GITHUB_CONTEXT" |
| 85 | + |
| 86 | + - uses: actions/checkout@v2 |
| 87 | + with: |
| 88 | + fetch-depth: 0 # so that gh-deploy works |
| 89 | + |
| 90 | + # 1) retrieve the reports generated previously |
| 91 | + - name: Retrieve reports |
| 92 | + uses: actions/download-artifact@master |
| 93 | + with: |
| 94 | + name: reports_dir |
| 95 | + path: ./docs/reports |
| 96 | + |
| 97 | + # Conda install |
| 98 | + - name: Install conda v3.7 |
| 99 | + uses: conda-incubator/setup-miniconda@v2 |
| 100 | + with: |
| 101 | + # auto-update-conda: true |
| 102 | + python-version: 3.7 |
| 103 | + activate-environment: noxenv |
| 104 | + - run: conda info |
| 105 | + shell: bash -l {0} # so that conda works |
| 106 | + - run: conda list |
| 107 | + shell: bash -l {0} # so that conda works |
| 108 | + |
| 109 | + # Nox install |
| 110 | + - name: Install noxfile requirements |
| 111 | + shell: bash -l {0} # so that conda works |
| 112 | + run: pip install -r noxfile-requirements.txt |
| 113 | + - run: conda list |
| 114 | + shell: bash -l {0} # so that conda works |
| 115 | + |
| 116 | + |
| 117 | + # -------------- only on Ubuntu + MAIN PUSH (no pull request, no tag) ----------- |
| 118 | + |
| 119 | + # 5) Publish the doc and test reports |
| 120 | + - name: \[not on TAG\] Publish documentation, tests and coverage reports |
| 121 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads') # startsWith(matrix.os,'ubuntu') |
| 122 | + shell: bash -l {0} # so that conda works |
| 123 | + run: nox -s publish |
| 124 | + |
| 125 | + # 6) Publish coverage report |
| 126 | + - name: \[not on TAG\] Create codecov.yaml with correct paths |
| 127 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads') |
| 128 | + shell: bash |
| 129 | + run: | |
| 130 | + cat << EOF > codecov.yml |
| 131 | + # codecov.yml |
| 132 | + fixes: |
| 133 | + - "/home/runner/work/smarie/python-pytest-cases/::" # Correct paths |
| 134 | + EOF |
| 135 | + - name: \[not on TAG\] Publish coverage report |
| 136 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads') |
| 137 | + uses: codecov/codecov-action@v1 |
| 138 | + with: |
| 139 | + files: ./docs/reports/coverage/coverage.xml |
| 140 | + |
| 141 | + # -------------- only on Ubuntu + TAG PUSH (no pull request) ----------- |
| 142 | + |
| 143 | + # 7) Create github release and build the wheel |
| 144 | + - name: \[TAG only\] Build wheel and create github release |
| 145 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 146 | + shell: bash -l {0} # so that conda works |
| 147 | + run: nox -s release -- ${{ secrets.GITHUB_TOKEN }} |
| 148 | + |
| 149 | + # 8) Publish the wheel on PyPi |
| 150 | + - name: \[TAG only\] Deploy on PyPi |
| 151 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 152 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 153 | + with: |
| 154 | + user: __token__ |
| 155 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 156 | + |
| 157 | + delete-artifacts: |
| 158 | + needs: publish_release |
| 159 | + runs-on: ubuntu-latest |
| 160 | + steps: |
| 161 | + - uses: kolpav/purge-artifacts-action@v1 |
| 162 | + with: |
| 163 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 164 | + expire-in: 0 # Setting this to 0 will delete all artifacts |
0 commit comments