|
| 1 | +--- |
| 2 | +name: 'Python' |
| 3 | + |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_call: |
| 7 | + secrets: |
| 8 | + WORKFLOW_TOKEN: |
| 9 | + description: "token to clone with" |
| 10 | + required: true |
| 11 | + |
| 12 | + |
| 13 | +jobs: |
| 14 | + |
| 15 | + |
| 16 | + lint: |
| 17 | + name: Lint |
| 18 | + if: ${{ false }} |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + |
| 22 | + - name: Create lint job |
| 23 | + shell: bash |
| 24 | + run: | |
| 25 | + echo "Job does not exists as it needs to be created." |
| 26 | +
|
| 27 | +
|
| 28 | + unit-test: |
| 29 | + name: Unit Test |
| 30 | + runs-on: ubuntu-latest |
| 31 | + strategy: |
| 32 | + max-parallel: 4 |
| 33 | + matrix: |
| 34 | + python-version: ['3.10', '3.11', '3.12'] |
| 35 | + |
| 36 | + steps: |
| 37 | + |
| 38 | + |
| 39 | + - uses: actions/checkout@v4 |
| 40 | + |
| 41 | + |
| 42 | + - name: Set up Python ${{ matrix.python-version }} |
| 43 | + uses: actions/setup-python@v5 |
| 44 | + with: |
| 45 | + python-version: ${{ matrix.python-version }} |
| 46 | + |
| 47 | + |
| 48 | + - name: Install Dependencies |
| 49 | + run: | |
| 50 | + python -m pip install --upgrade pip |
| 51 | + pip install -r requirements.txt |
| 52 | + pip install -r requirements_test.txt |
| 53 | +
|
| 54 | +
|
| 55 | + - name: Run Tests |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + cd app; |
| 59 | + pytest --cov --cov-report term --cov-report xml:../coverage.xml --cov-report html:../coverage/ --junit-xml=../unit.JUnit.xml **/tests/unit; |
| 60 | +
|
| 61 | +
|
| 62 | + - name: Upload Test Report |
| 63 | + uses: actions/upload-artifact@v4 |
| 64 | + if: success() || failure() |
| 65 | + with: |
| 66 | + name: unit-test-results-${{ matrix.python-version }} |
| 67 | + path: unit.JUnit.xml |
| 68 | + |
| 69 | + |
| 70 | + - name: Upload Coverage Report |
| 71 | + uses: actions/upload-artifact@v4 |
| 72 | + if: success() || failure() |
| 73 | + with: |
| 74 | + name: coverage-report-${{ matrix.python-version }} |
| 75 | + path: coverage.xml |
| 76 | + |
| 77 | + |
| 78 | + - name: Upload Coverage |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + if: success() || failure() |
| 81 | + with: |
| 82 | + name: coverage-${{ matrix.python-version }} |
| 83 | + path: coverage/* |
| 84 | + |
| 85 | + |
| 86 | + # should only run on dev/master and tag |
| 87 | + report: |
| 88 | + name: Create Test Reports |
| 89 | + needs: |
| 90 | + - unit-test |
| 91 | + runs-on: ubuntu-latest |
| 92 | + strategy: |
| 93 | + max-parallel: 4 |
| 94 | + matrix: |
| 95 | + python-version: ['3.10', '3.11', '3.12'] |
| 96 | + steps: |
| 97 | + |
| 98 | + |
| 99 | + - name: Test Report |
| 100 | + if: success() || failure() |
| 101 | + uses: dorny/test-reporter@v1 |
| 102 | + id: test-report |
| 103 | + with: |
| 104 | + artifact: unit-test-results-${{ matrix.python-version }} |
| 105 | + name: Unit Test Report [Python ${{ matrix.python-version }}] |
| 106 | + path: '*.xml' |
| 107 | + reporter: java-junit |
| 108 | + |
| 109 | + |
| 110 | + - name: Create Shields.io Endpoint.json |
| 111 | + if: success() || failure() |
| 112 | + shell: bash |
| 113 | + run: | |
| 114 | + echo ' |
| 115 | + { |
| 116 | + "schemaVersion": 1, |
| 117 | + "label": "Unit Test", |
| 118 | + "message": "${{ steps.test-report.outputs.passed }} passed | ${{ steps.test-report.outputs.skipped }} skipped", |
| 119 | + "namedLogo": "github", |
| 120 | + "color": "#000", |
| 121 | + "style": "plastic" |
| 122 | + }' > endpoint_${{ matrix.python-version }}.json |
| 123 | +
|
| 124 | +
|
| 125 | + - name: Upload Badge Endpoint json |
| 126 | + uses: actions/upload-artifact@v4 |
| 127 | + if: success() || failure() |
| 128 | + with: |
| 129 | + name: unit-test-shield-endpoint-${{ matrix.python-version }} |
| 130 | + path: endpoint_${{ matrix.python-version }}.json |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + coverage-report: |
| 135 | + name: Create Coverage report |
| 136 | + needs: |
| 137 | + - unit-test |
| 138 | + runs-on: ubuntu-latest |
| 139 | + strategy: |
| 140 | + max-parallel: 4 |
| 141 | + matrix: |
| 142 | + python-version: ['3.12'] |
| 143 | + name: Coverage |
| 144 | + steps: |
| 145 | + |
| 146 | + - name: Run Tests |
| 147 | + shell: bash |
| 148 | + run: | |
| 149 | + ls -l; |
| 150 | +
|
| 151 | + - name: Download Coverage Artifact |
| 152 | + uses: actions/download-artifact@v4 |
| 153 | + with: |
| 154 | + name: coverage-report-${{ matrix.python-version }} |
| 155 | + github-token: ${{ github.token }} |
| 156 | + |
| 157 | + - name: ls |
| 158 | + shell: bash |
| 159 | + if: success() || failure() |
| 160 | + run: | |
| 161 | + ls -l; |
| 162 | +
|
| 163 | + - name: Code Coverage Report |
| 164 | + |
| 165 | + with: |
| 166 | + filename: coverage.xml |
| 167 | + badge: true |
| 168 | + fail_below_min: true |
| 169 | + format: markdown |
| 170 | + hide_branch_rate: false |
| 171 | + hide_complexity: false |
| 172 | + indicators: true |
| 173 | + output: both |
| 174 | + thresholds: '60 85' |
| 175 | + |
| 176 | + |
| 177 | + - name: ls |
| 178 | + shell: bash |
| 179 | + if: success() || failure() |
| 180 | + run: | |
| 181 | + ls -l; |
| 182 | +
|
| 183 | +
|
| 184 | + - name: create status check/comment for code coverage results |
| 185 | + id: jest_coverage_check |
| 186 | + |
| 187 | + with: |
| 188 | + github-token: ${{ github.token }} |
| 189 | + summary-file: code-coverage-results.md |
| 190 | + create-pr-comment: true |
| 191 | + update-comment-if-one-exists: true |
| 192 | + update-comment-key: "${{ env.GITHUB-JOB }}_${{ env.GITHUB-ACTION }}" |
| 193 | + |
| 194 | + - name: Upload Coverage Summary |
| 195 | + uses: actions/upload-artifact@v4 |
| 196 | + if: success() || failure() |
| 197 | + with: |
| 198 | + name: code-coverage-results-${{ matrix.python-version }} |
| 199 | + path: code-coverage-results.md |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | + badge-endpoint: |
| 204 | + name: Publish Badge endpoint files |
| 205 | + if: ${{ github.ref_name == 'master' || github.ref_name == 'development' }} |
| 206 | + needs: |
| 207 | + - report |
| 208 | + strategy: |
| 209 | + max-parallel: 4 |
| 210 | + matrix: |
| 211 | + python-version: ['3.12'] |
| 212 | + runs-on: ubuntu-latest |
| 213 | + steps: |
| 214 | + |
| 215 | + - name: Checkout Endpoint Repo |
| 216 | + uses: actions/checkout@v4 |
| 217 | + with: |
| 218 | + repository: 'nofusscomputing/.github' |
| 219 | + ref: 'master' |
| 220 | + token: ${{ secrets.WORKFLOW_TOKEN }} |
| 221 | + path: 'endpoint_publish' |
| 222 | + fetch-depth: '1' |
| 223 | + show-progress: true |
| 224 | + submodules: false |
| 225 | + |
| 226 | + |
| 227 | + - name: Create Publish Directories |
| 228 | + shell: bash |
| 229 | + run: | |
| 230 | + echo "[Debug] PWD[${PWD}]"; |
| 231 | + cd endpoint_publish; |
| 232 | + echo "[Debug] PWD[${PWD}]"; |
| 233 | + mkdir -p repositories/${{ github.repository }}/${{ github.ref_name }}; |
| 234 | + ls -la; |
| 235 | +
|
| 236 | +
|
| 237 | + - name: Create Publish Directories |
| 238 | + shell: bash |
| 239 | + run: | |
| 240 | + echo "[Debug] PWD[${PWD}]"; |
| 241 | + # cd repositories/${{ github.repository }}/${{ github.ref_name }}; |
| 242 | + echo "[Debug] PWD[${PWD}]"; |
| 243 | +
|
| 244 | +
|
| 245 | + - name: Download Badge Endpoint json |
| 246 | + uses: actions/download-artifact@v4 |
| 247 | + with: |
| 248 | + name: unit-test-shield-endpoint-${{ matrix.python-version }} |
| 249 | + |
| 250 | + |
| 251 | + - name: Add endpoint file |
| 252 | + shell: bash |
| 253 | + run: | |
| 254 | + echo "[Debug] PWD[${PWD}]"; |
| 255 | +
|
| 256 | + echo "[Debug] **************************** - cd endpoint_publish"; |
| 257 | +
|
| 258 | + cd endpoint_publish; |
| 259 | +
|
| 260 | + echo "[Debug] **************************** - ls -la"; |
| 261 | +
|
| 262 | + ls -la |
| 263 | +
|
| 264 | + echo "[Debug] ****************************"; |
| 265 | +
|
| 266 | + echo "[Debug] PWD[${PWD}]"; |
| 267 | +
|
| 268 | + echo "[Debug] **************************** - ls -la ../"; |
| 269 | +
|
| 270 | + ls -la ../ |
| 271 | +
|
| 272 | + echo "[Debug] **************************** - cp ../endpoint_${{ matrix.python-version }}.json repositories/${{ github.repository }}/${{ github.ref_name }}/badge_endpoint_unit_test.json"; |
| 273 | +
|
| 274 | + cp ../endpoint_${{ matrix.python-version }}.json repositories/${{ github.repository }}/${{ github.ref_name }}/badge_endpoint_unit_test.json; |
| 275 | +
|
| 276 | + echo "[Debug] **************************** - ls -la repositories/${{ github.repository }}/${{ github.ref_name }}/"; |
| 277 | +
|
| 278 | + ls -la repositories/${{ github.repository }}/${{ github.ref_name }}/; |
| 279 | +
|
| 280 | +
|
| 281 | + - name: Configure git |
| 282 | + shell: bash |
| 283 | + run: | |
| 284 | + git config --global user.email "[email protected]"; |
| 285 | + git config --global user.name "nfc-bot"; |
| 286 | +
|
| 287 | +
|
| 288 | + - name: Git add |
| 289 | + shell: bash |
| 290 | + run: | |
| 291 | + echo "[Debug] PWD[${PWD}]"; |
| 292 | + echo "[Debug] ****************************"; |
| 293 | + cd endpoint_publish; |
| 294 | + echo "[Debug] ****************************"; |
| 295 | + ls -la |
| 296 | + echo "[Debug] ****************************"; |
| 297 | + echo "[Debug] PWD[${PWD}]"; |
| 298 | + echo "[Debug] ****************************"; |
| 299 | + git status; |
| 300 | + echo "[Debug] ****************************"; |
| 301 | + git add . |
| 302 | +
|
| 303 | + - name: Git commit |
| 304 | + shell: bash |
| 305 | + run: | |
| 306 | + echo "[Debug] PWD[${PWD}]"; |
| 307 | + echo "[Debug] ****************************"; |
| 308 | + cd endpoint_publish; |
| 309 | + echo "[Debug] ****************************"; |
| 310 | + ls -la |
| 311 | + echo "[Debug] ****************************"; |
| 312 | + echo "[Debug] PWD[${PWD}]"; |
| 313 | + echo "[Debug] ****************************"; |
| 314 | + git commit -m "chore: add badge endpount file ${{ github.repository }}/${{ github.ref_name }}" |
| 315 | +
|
| 316 | +
|
| 317 | + - name: git push |
| 318 | + shell: bash |
| 319 | + run: | |
| 320 | + echo "[Debug] PWD[${PWD}]"; |
| 321 | + echo "[Debug] ****************************"; |
| 322 | + cd endpoint_publish; |
| 323 | + echo "[Debug] ****************************"; |
| 324 | + ls -la |
| 325 | + echo "[Debug] ****************************"; |
| 326 | + echo "[Debug] PWD[${PWD}]"; |
| 327 | + echo "[Debug] ****************************"; |
| 328 | + git push |
0 commit comments