Merge pull request #33 from Raster-Lab/copilot/work-on-next-task-492f… #115
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| jobs: | |
| build-and-test: | |
| name: Build & Test (Swift 6.2+) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install Swift 6.2 | |
| run: | | |
| wget -q https://download.swift.org/swift-6.2-release/ubuntu2204/swift-6.2-RELEASE/swift-6.2-RELEASE-ubuntu22.04.tar.gz | |
| tar xzf swift-6.2-RELEASE-ubuntu22.04.tar.gz | |
| rm swift-6.2-RELEASE-ubuntu22.04.tar.gz | |
| echo "$PWD/swift-6.2-RELEASE-ubuntu22.04/usr/bin" >> $GITHUB_PATH | |
| - name: Verify Swift installation | |
| run: swift --version | |
| - name: Build | |
| run: swift build 2>&1 | tee build.log | |
| - name: Run tests with coverage | |
| run: swift test --enable-code-coverage | |
| - name: Check code coverage | |
| run: | | |
| CODECOV_JSON=$(swift test --show-codecov-path) | |
| if [ ! -f "$CODECOV_JSON" ]; then | |
| echo "Could not find coverage JSON at $CODECOV_JSON" | |
| exit 1 | |
| fi | |
| COVERAGE=$(python3 -c " | |
| import json, sys | |
| with open('$CODECOV_JSON') as f: | |
| data = json.load(f) | |
| files = data.get('data', [{}])[0].get('files', []) | |
| covered = 0 | |
| total = 0 | |
| for f in files: | |
| if '/Sources/' in f['filename']: | |
| covered += f['summary']['lines']['covered'] | |
| total += f['summary']['lines']['count'] | |
| pct = (covered / total * 100) if total else 0 | |
| print(f'{pct:.2f}') | |
| ") | |
| echo "Source code coverage: ${COVERAGE}%" | |
| THRESHOLD=95 | |
| if [ "$(echo "$COVERAGE < $THRESHOLD" | bc -l)" -eq 1 ]; then | |
| echo "FAIL: Code coverage ${COVERAGE}% is below the ${THRESHOLD}% threshold." | |
| exit 1 | |
| else | |
| echo "PASS: Code coverage ${COVERAGE}% meets the ${THRESHOLD}% threshold." | |
| fi |