|
| 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 | + outputs: |
| 36 | + unit-test-coverage: ${{ steps.run-unit-test.outputs.coverage }} |
| 37 | + steps: |
| 38 | + |
| 39 | + |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + |
| 42 | + |
| 43 | + - name: Set up Python ${{ matrix.python-version }} |
| 44 | + uses: actions/setup-python@v5 |
| 45 | + with: |
| 46 | + python-version: ${{ matrix.python-version }} |
| 47 | + |
| 48 | + |
| 49 | + - name: Install Dependencies |
| 50 | + run: | |
| 51 | + python -m pip install --upgrade pip |
| 52 | + pip install -r requirements.txt |
| 53 | + pip install -r requirements_test.txt |
| 54 | +
|
| 55 | +
|
| 56 | + - name: Run Tests |
| 57 | + id: run-unit-test |
| 58 | + shell: bash |
| 59 | + run: | |
| 60 | + cd app; |
| 61 | + pytest --cov --cov-report term --cov-report xml:../coverage.xml --cov-report html:../coverage/ --junit-xml=../unit.JUnit.xml **/tests/unit; |
| 62 | + echo "coverage=$(coverage report | awk '$1 == "TOTAL" {print $NF+0}')" > $GITHUB_OUTPUT |
| 63 | +
|
| 64 | +
|
| 65 | + - name: Upload Test Report |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + if: success() || failure() |
| 68 | + with: |
| 69 | + name: unit-test-results-${{ matrix.python-version }} |
| 70 | + path: unit.JUnit.xml |
| 71 | + |
| 72 | + |
| 73 | + - name: Upload Coverage Report |
| 74 | + uses: actions/upload-artifact@v4 |
| 75 | + if: success() || failure() |
| 76 | + with: |
| 77 | + name: coverage-report-${{ matrix.python-version }} |
| 78 | + path: coverage.xml |
| 79 | + |
| 80 | + |
| 81 | + - name: Upload Coverage |
| 82 | + uses: actions/upload-artifact@v4 |
| 83 | + if: success() || failure() |
| 84 | + with: |
| 85 | + name: coverage-${{ matrix.python-version }} |
| 86 | + path: coverage/* |
| 87 | + |
| 88 | + |
| 89 | + # should only run on dev/master and tag |
| 90 | + report: |
| 91 | + name: Create Test Reports |
| 92 | + needs: |
| 93 | + - unit-test |
| 94 | + runs-on: ubuntu-latest |
| 95 | + strategy: |
| 96 | + max-parallel: 4 |
| 97 | + matrix: |
| 98 | + python-version: ['3.10', '3.11', '3.12'] |
| 99 | + steps: |
| 100 | + |
| 101 | + |
| 102 | + - name: Test Report |
| 103 | + if: success() || failure() |
| 104 | + uses: dorny/test-reporter@v1 |
| 105 | + id: test-report |
| 106 | + with: |
| 107 | + artifact: unit-test-results-${{ matrix.python-version }} |
| 108 | + name: Unit Test Report [Python ${{ matrix.python-version }}] |
| 109 | + path: '*.xml' |
| 110 | + reporter: java-junit |
| 111 | + |
| 112 | + |
| 113 | + - name: Create Shields.io Endpoint.json |
| 114 | + if: success() || failure() |
| 115 | + shell: bash |
| 116 | + run: | |
| 117 | + echo ' |
| 118 | + { |
| 119 | + "schemaVersion": 1, |
| 120 | + "label": "Unit Test", |
| 121 | + "message": "${{ steps.test-report.outputs.passed }} passed | ${{ steps.test-report.outputs.skipped }} skipped", |
| 122 | + "logoSvg": "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 162.53 196.9\"><defs><linearGradient id=\"a\" x1=\"319.46\" y1=\"219.79\" x2=\"478.86\" y2=\"82.65\" gradientTransform=\"matrix(0.56, 0, 0, -0.57, -8.96, 287.06)\" gradientUnits=\"userSpaceOnUse\"><stop offset=\"0\" stop-color=\"#5a9fd4\"/><stop offset=\"1\" stop-color=\"#306998\"/></linearGradient><linearGradient id=\"b\" x1=\"540.48\" y1=\"-0.35\" x2=\"483.56\" y2=\"80.18\" gradientTransform=\"matrix(0.56, 0, 0, -0.57, -8.96, 287.06)\" gradientUnits=\"userSpaceOnUse\"><stop offset=\"0\" stop-color=\"#ffd43b\"/><stop offset=\"1\" stop-color=\"#ffe873\"/></linearGradient><radialGradient id=\"c\" cx=\"-809.2\" cy=\"196.83\" r=\"42.46\" gradientTransform=\"matrix(0, -0.24, -1.05, 0, 463.94, 150.1)\" gradientUnits=\"userSpaceOnUse\"><stop offset=\"0\" stop-color=\"#b8b8b8\" stop-opacity=\"0.5\"/><stop offset=\"1\" stop-color=\"#7f7f7f\" stop-opacity=\"0\"/></radialGradient></defs><title>python-logo</title><path d=\"M255,157.55a111.94,111.94,0,0,0-18.73,1.6c-16.59,2.93-19.6,9.07-19.6,20.38v14.94h39.2v5H202c-11.39,0-21.37,6.85-24.49,19.88-3.6,14.93-3.76,24.25,0,39.84,2.79,11.61,9.44,19.88,20.84,19.88h13.48V261.13c0-12.94,11.2-24.35,24.49-24.35h39.16a19.75,19.75,0,0,0,19.6-19.92V179.53c0-10.62-9-18.61-19.6-20.38A122.28,122.28,0,0,0,255,157.55Zm-21.2,12a7.47,7.47,0,1,1-7.36,7.49A7.44,7.44,0,0,1,233.83,169.57Z\" transform=\"translate(-174.73 -157.55)\" style=\"fill:url(#a)\"/><path d=\"M299.95,199.45v17.41c0,13.5-11.44,24.86-24.49,24.86H236.3c-10.73,0-19.6,9.18-19.6,19.92V299c0,10.62,9.24,16.87,19.6,19.92,12.41,3.65,24.31,4.31,39.16,0,9.87-2.86,19.6-8.61,19.6-19.92V284H255.9v-5h58.76c11.39,0,15.64-7.95,19.6-19.88,4.09-12.28,3.92-24.09,0-39.84-2.82-11.34-8.19-19.88-19.6-19.88Zm-22,94.54a7.47,7.47,0,1,1-7.36,7.45A7.4,7.4,0,0,1,277.92,294Z\" transform=\"translate(-174.73 -157.55)\" style=\"fill:url(#b)\"/><path d=\"M308.88,344.26c0,5.63-23.52,10.19-52.54,10.19s-52.54-4.56-52.54-10.19,23.52-10.19,52.54-10.19S308.88,338.64,308.88,344.26Z\" transform=\"translate(-174.73 -157.55)\" style=\"opacity:0.44382017850875854;isolation:isolate;fill:url(#c)\"/></svg>", |
| 123 | + "color": "#4584b6", |
| 124 | + "style": "plastic" |
| 125 | + }' > endpoint_${{ matrix.python-version }}.json |
| 126 | +
|
| 127 | +
|
| 128 | + - name: Upload Badge Endpoint json |
| 129 | + uses: actions/upload-artifact@v4 |
| 130 | + if: success() || failure() |
| 131 | + with: |
| 132 | + name: unit-test-shield-endpoint-${{ matrix.python-version }} |
| 133 | + path: endpoint_${{ matrix.python-version }}.json |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + coverage-report: |
| 138 | + name: Create Coverage report |
| 139 | + needs: |
| 140 | + - unit-test |
| 141 | + runs-on: ubuntu-latest |
| 142 | + strategy: |
| 143 | + max-parallel: 4 |
| 144 | + matrix: |
| 145 | + python-version: ['3.12'] |
| 146 | + steps: |
| 147 | + |
| 148 | + - name: Run Tests |
| 149 | + shell: bash |
| 150 | + run: | |
| 151 | + ls -l; |
| 152 | +
|
| 153 | + - name: Download Coverage Artifact |
| 154 | + uses: actions/download-artifact@v4 |
| 155 | + with: |
| 156 | + name: coverage-report-${{ matrix.python-version }} |
| 157 | + github-token: ${{ github.token }} |
| 158 | + |
| 159 | + - name: ls |
| 160 | + shell: bash |
| 161 | + if: success() || failure() |
| 162 | + run: | |
| 163 | + ls -l; |
| 164 | +
|
| 165 | + - name: Code Coverage Report |
| 166 | + uses: irongut/CodeCoverageSummary@v1.3.0 |
| 167 | + with: |
| 168 | + filename: coverage.xml |
| 169 | + badge: true |
| 170 | + fail_below_min: true |
| 171 | + format: markdown |
| 172 | + hide_branch_rate: false |
| 173 | + hide_complexity: false |
| 174 | + indicators: true |
| 175 | + output: both |
| 176 | + thresholds: '60 85' |
| 177 | + |
| 178 | + |
| 179 | + - name: ls |
| 180 | + shell: bash |
| 181 | + if: success() || failure() |
| 182 | + run: | |
| 183 | + ls -l; |
| 184 | +
|
| 185 | +
|
| 186 | + - name: create status check/comment for code coverage results |
| 187 | + id: jest_coverage_check |
| 188 | + uses: im-open/process-code-coverage-summary@v2.3.0 |
| 189 | + with: |
| 190 | + github-token: ${{ github.token }} |
| 191 | + summary-file: code-coverage-results.md |
| 192 | + create-pr-comment: true |
| 193 | + update-comment-if-one-exists: true |
| 194 | + update-comment-key: "${{ env.GITHUB-JOB }}_${{ env.GITHUB-ACTION }}" |
| 195 | + |
| 196 | + - name: Upload Coverage Summary |
| 197 | + uses: actions/upload-artifact@v4 |
| 198 | + if: success() || failure() |
| 199 | + with: |
| 200 | + name: code-coverage-results-${{ matrix.python-version }} |
| 201 | + path: code-coverage-results.md |
| 202 | + |
| 203 | + |
| 204 | + |
| 205 | + badge-endpoint: |
| 206 | + name: Publish Badge endpoint files |
| 207 | + if: ${{ github.ref_name == 'master' || github.ref_name == 'development' }} |
| 208 | + needs: |
| 209 | + - unit-test |
| 210 | + - report |
| 211 | + strategy: |
| 212 | + max-parallel: 4 |
| 213 | + matrix: |
| 214 | + python-version: ['3.12'] |
| 215 | + runs-on: ubuntu-latest |
| 216 | + steps: |
| 217 | + |
| 218 | + - name: Checkout Endpoint Repo |
| 219 | + uses: actions/checkout@v4 |
| 220 | + with: |
| 221 | + repository: 'nofusscomputing/.github' |
| 222 | + ref: 'master' |
| 223 | + token: ${{ secrets.WORKFLOW_TOKEN }} |
| 224 | + path: 'endpoint_publish' |
| 225 | + fetch-depth: '1' |
| 226 | + show-progress: true |
| 227 | + submodules: false |
| 228 | + |
| 229 | + |
| 230 | + - name: Create Publish Directories |
| 231 | + shell: bash |
| 232 | + run: | |
| 233 | + echo "[Debug] PWD[${PWD}]"; |
| 234 | + cd endpoint_publish; |
| 235 | + echo "[Debug] PWD[${PWD}]"; |
| 236 | + mkdir -p repositories/${{ github.repository }}/${{ github.ref_name }}; |
| 237 | + ls -la; |
| 238 | +
|
| 239 | +
|
| 240 | + - name: Create Publish Directories |
| 241 | + shell: bash |
| 242 | + run: | |
| 243 | + echo "[Debug] PWD[${PWD}]"; |
| 244 | + # cd repositories/${{ github.repository }}/${{ github.ref_name }}; |
| 245 | + echo "[Debug] PWD[${PWD}]"; |
| 246 | +
|
| 247 | +
|
| 248 | + - name: Download Badge Endpoint json |
| 249 | + uses: actions/download-artifact@v4 |
| 250 | + with: |
| 251 | + name: unit-test-shield-endpoint-${{ matrix.python-version }} |
| 252 | + |
| 253 | + |
| 254 | + - name: Add endpoint file |
| 255 | + shell: bash |
| 256 | + run: | |
| 257 | + echo "[Debug] PWD[${PWD}]"; |
| 258 | +
|
| 259 | + echo "[Debug] **************************** - cd endpoint_publish"; |
| 260 | +
|
| 261 | + cd endpoint_publish; |
| 262 | +
|
| 263 | + echo "[Debug] **************************** - ls -la"; |
| 264 | +
|
| 265 | + ls -la |
| 266 | +
|
| 267 | + echo "[Debug] ****************************"; |
| 268 | +
|
| 269 | + echo "[Debug] PWD[${PWD}]"; |
| 270 | +
|
| 271 | + echo "[Debug] **************************** - ls -la ../"; |
| 272 | +
|
| 273 | + ls -la ../ |
| 274 | +
|
| 275 | + echo "[Debug] **************************** - cp ../endpoint_${{ matrix.python-version }}.json repositories/${{ github.repository }}/${{ github.ref_name }}/badge_endpoint_unit_test.json"; |
| 276 | +
|
| 277 | + cp ../endpoint_${{ matrix.python-version }}.json repositories/${{ github.repository }}/${{ github.ref_name }}/badge_endpoint_unit_test.json; |
| 278 | +
|
| 279 | + echo "[Debug] **************************** - ls -la repositories/${{ github.repository }}/${{ github.ref_name }}/"; |
| 280 | +
|
| 281 | + ls -la repositories/${{ github.repository }}/${{ github.ref_name }}/; |
| 282 | +
|
| 283 | +
|
| 284 | +
|
| 285 | + - name: Create Shields.io Endpoint.json for coverage |
| 286 | + if: success() || failure() |
| 287 | + shell: bash |
| 288 | + run: | |
| 289 | + echo "[Debug] PWD[${PWD}]"; |
| 290 | + cd endpoint_publish; |
| 291 | + echo "[Debug] ****************************"; |
| 292 | +
|
| 293 | + echo "[Debug] PWD[${PWD}]"; |
| 294 | +
|
| 295 | + echo "[Debug] **************************** - create file"; |
| 296 | +
|
| 297 | + echo ' |
| 298 | + { |
| 299 | + "schemaVersion": 1, |
| 300 | + "label": "Unit Test Coverage", |
| 301 | + "message": "${{ needs.unit-test.outputs.unit-test-coverage }}%", |
| 302 | + "logoSvg": "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 162.53 196.9\"><defs><linearGradient id=\"a\" x1=\"319.46\" y1=\"219.79\" x2=\"478.86\" y2=\"82.65\" gradientTransform=\"matrix(0.56, 0, 0, -0.57, -8.96, 287.06)\" gradientUnits=\"userSpaceOnUse\"><stop offset=\"0\" stop-color=\"#5a9fd4\"/><stop offset=\"1\" stop-color=\"#306998\"/></linearGradient><linearGradient id=\"b\" x1=\"540.48\" y1=\"-0.35\" x2=\"483.56\" y2=\"80.18\" gradientTransform=\"matrix(0.56, 0, 0, -0.57, -8.96, 287.06)\" gradientUnits=\"userSpaceOnUse\"><stop offset=\"0\" stop-color=\"#ffd43b\"/><stop offset=\"1\" stop-color=\"#ffe873\"/></linearGradient><radialGradient id=\"c\" cx=\"-809.2\" cy=\"196.83\" r=\"42.46\" gradientTransform=\"matrix(0, -0.24, -1.05, 0, 463.94, 150.1)\" gradientUnits=\"userSpaceOnUse\"><stop offset=\"0\" stop-color=\"#b8b8b8\" stop-opacity=\"0.5\"/><stop offset=\"1\" stop-color=\"#7f7f7f\" stop-opacity=\"0\"/></radialGradient></defs><title>python-logo</title><path d=\"M255,157.55a111.94,111.94,0,0,0-18.73,1.6c-16.59,2.93-19.6,9.07-19.6,20.38v14.94h39.2v5H202c-11.39,0-21.37,6.85-24.49,19.88-3.6,14.93-3.76,24.25,0,39.84,2.79,11.61,9.44,19.88,20.84,19.88h13.48V261.13c0-12.94,11.2-24.35,24.49-24.35h39.16a19.75,19.75,0,0,0,19.6-19.92V179.53c0-10.62-9-18.61-19.6-20.38A122.28,122.28,0,0,0,255,157.55Zm-21.2,12a7.47,7.47,0,1,1-7.36,7.49A7.44,7.44,0,0,1,233.83,169.57Z\" transform=\"translate(-174.73 -157.55)\" style=\"fill:url(#a)\"/><path d=\"M299.95,199.45v17.41c0,13.5-11.44,24.86-24.49,24.86H236.3c-10.73,0-19.6,9.18-19.6,19.92V299c0,10.62,9.24,16.87,19.6,19.92,12.41,3.65,24.31,4.31,39.16,0,9.87-2.86,19.6-8.61,19.6-19.92V284H255.9v-5h58.76c11.39,0,15.64-7.95,19.6-19.88,4.09-12.28,3.92-24.09,0-39.84-2.82-11.34-8.19-19.88-19.6-19.88Zm-22,94.54a7.47,7.47,0,1,1-7.36,7.45A7.4,7.4,0,0,1,277.92,294Z\" transform=\"translate(-174.73 -157.55)\" style=\"fill:url(#b)\"/><path d=\"M308.88,344.26c0,5.63-23.52,10.19-52.54,10.19s-52.54-4.56-52.54-10.19,23.52-10.19,52.54-10.19S308.88,338.64,308.88,344.26Z\" transform=\"translate(-174.73 -157.55)\" style=\"opacity:0.44382017850875854;isolation:isolate;fill:url(#c)\"/></svg>", |
| 303 | + "color": "#4584b6", |
| 304 | + "style": "plastic" |
| 305 | + }' > repositories/${{ github.repository }}/${{ github.ref_name }}/badge_endpoint_coverage.json; |
| 306 | +
|
| 307 | + echo "[Debug] **************************** cat repositories/${{ github.repository }}/${{ github.ref_name }}/badge_endpoint_coverage.json"; |
| 308 | +
|
| 309 | + cat repositories/${{ github.repository }}/${{ github.ref_name }}/badge_endpoint_coverage.json; |
| 310 | +
|
| 311 | +
|
| 312 | +
|
| 313 | + - name: Configure git |
| 314 | + shell: bash |
| 315 | + run: | |
| 316 | + git config --global user.email "helpdesk@nofusscomputing.com"; |
| 317 | + git config --global user.name "nfc-bot"; |
| 318 | +
|
| 319 | +
|
| 320 | + - name: Git add |
| 321 | + shell: bash |
| 322 | + run: | |
| 323 | + echo "[Debug] PWD[${PWD}]"; |
| 324 | + echo "[Debug] ****************************"; |
| 325 | + cd endpoint_publish; |
| 326 | + echo "[Debug] ****************************"; |
| 327 | + ls -la |
| 328 | + echo "[Debug] ****************************"; |
| 329 | + echo "[Debug] PWD[${PWD}]"; |
| 330 | + echo "[Debug] ****************************"; |
| 331 | + git status; |
| 332 | + echo "[Debug] ****************************"; |
| 333 | + git add . |
| 334 | +
|
| 335 | + - name: Git commit |
| 336 | + shell: bash |
| 337 | + run: | |
| 338 | + echo "[Debug] PWD[${PWD}]"; |
| 339 | + echo "[Debug] ****************************"; |
| 340 | + cd endpoint_publish; |
| 341 | + echo "[Debug] ****************************"; |
| 342 | + ls -la |
| 343 | + echo "[Debug] ****************************"; |
| 344 | + echo "[Debug] PWD[${PWD}]"; |
| 345 | + echo "[Debug] ****************************"; |
| 346 | + git commit -m "chore: add badge endpount file ${{ github.repository }}/${{ github.ref_name }}" |
| 347 | +
|
| 348 | +
|
| 349 | + - name: git push |
| 350 | + shell: bash |
| 351 | + run: | |
| 352 | + echo "[Debug] PWD[${PWD}]"; |
| 353 | + echo "[Debug] ****************************"; |
| 354 | + cd endpoint_publish; |
| 355 | + echo "[Debug] ****************************"; |
| 356 | + ls -la |
| 357 | + echo "[Debug] ****************************"; |
| 358 | + echo "[Debug] PWD[${PWD}]"; |
| 359 | + echo "[Debug] ****************************"; |
| 360 | + git push |
0 commit comments