|
| 1 | +name: Basic smoke test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-test: |
| 13 | + if: github.actor != 'github-actions[bot]' |
| 14 | + runs-on: ${{ matrix.os }} |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 19 | + python-version: ["3.9", "3.10", "3.11", "3.12"] |
| 20 | + defaults: |
| 21 | + run: |
| 22 | + shell: bash |
| 23 | + steps: |
| 24 | + - name: Check out code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up Python |
| 28 | + uses: actions/setup-python@v5 |
| 29 | + with: |
| 30 | + python-version: ${{ matrix.python-version }} |
| 31 | + |
| 32 | + - name: Install Python dependencies |
| 33 | + run: | |
| 34 | + python -m pip install --upgrade pip |
| 35 | + pip install -r requirements.txt |
| 36 | +
|
| 37 | + - name: Build svVascularize |
| 38 | + env: |
| 39 | + SVV_BUILD_MMG: "1" |
| 40 | + run: | |
| 41 | + pip install . |
| 42 | +
|
| 43 | + - name: Run basic smoke test |
| 44 | + run: | |
| 45 | + python .github/scripts/basic_smoke_test.py |
| 46 | +
|
| 47 | + - name: Record job status |
| 48 | + if: always() |
| 49 | + run: | |
| 50 | + echo "${{ matrix.os }}=${{ job.status }}" > smoke-status.txt |
| 51 | +
|
| 52 | + - name: Upload status artifact |
| 53 | + if: always() |
| 54 | + uses: actions/upload-artifact@v4 |
| 55 | + with: |
| 56 | + name: smoke-status-${{ matrix.os }}-py${{ matrix.python-version }} |
| 57 | + path: smoke-status.txt |
| 58 | + |
| 59 | + update-smoke-badge: |
| 60 | + if: github.actor != 'github-actions[bot]' |
| 61 | + needs: build-and-test |
| 62 | + runs-on: ubuntu-latest |
| 63 | + defaults: |
| 64 | + run: |
| 65 | + shell: bash |
| 66 | + steps: |
| 67 | + - name: Check out code |
| 68 | + uses: actions/checkout@v4 |
| 69 | + with: |
| 70 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + |
| 72 | + - name: Download status artifacts |
| 73 | + uses: actions/download-artifact@v4 |
| 74 | + with: |
| 75 | + pattern: smoke-status-* |
| 76 | + path: smoke-status |
| 77 | + merge-multiple: true |
| 78 | + |
| 79 | + - name: Update README smoke test badge |
| 80 | + run: | |
| 81 | + set -euo pipefail |
| 82 | +
|
| 83 | + linux="unknown" |
| 84 | + macos="unknown" |
| 85 | + windows="unknown" |
| 86 | +
|
| 87 | + # If no smoke-status artifacts were downloaded, skip badge update. |
| 88 | + if ! compgen -G "smoke-status/*/*" > /dev/null; then |
| 89 | + echo "No smoke-status artifacts found; skipping badge update." |
| 90 | + exit 0 |
| 91 | + fi |
| 92 | +
|
| 93 | + # Each artifact directory contains a single smoke-status.txt file. |
| 94 | + for f in smoke-status/*/*; do |
| 95 | + line=$(cat "$f") |
| 96 | + os="${line%%=*}" |
| 97 | + status="${line#*=}" |
| 98 | +
|
| 99 | + case "$os" in |
| 100 | + ubuntu-latest) |
| 101 | + if [ "$status" = "success" ]; then |
| 102 | + if [ "$linux" = "unknown" ]; then |
| 103 | + linux="ok" |
| 104 | + fi |
| 105 | + else |
| 106 | + linux="fail" |
| 107 | + fi |
| 108 | + ;; |
| 109 | + macos-latest) |
| 110 | + if [ "$status" = "success" ]; then |
| 111 | + if [ "$macos" = "unknown" ]; then |
| 112 | + macos="ok" |
| 113 | + fi |
| 114 | + else |
| 115 | + macos="fail" |
| 116 | + fi |
| 117 | + ;; |
| 118 | + windows-latest) |
| 119 | + if [ "$status" = "success" ]; then |
| 120 | + if [ "$windows" = "unknown" ]; then |
| 121 | + windows="ok" |
| 122 | + fi |
| 123 | + else |
| 124 | + windows="fail" |
| 125 | + fi |
| 126 | + ;; |
| 127 | + esac |
| 128 | + done |
| 129 | +
|
| 130 | + label="linux_${linux}-macos_${macos}-windows_${windows}" |
| 131 | +
|
| 132 | + if [ "$linux" = "ok" ] && [ "$macos" = "ok" ] && [ "$windows" = "ok" ]; then |
| 133 | + color="brightgreen" |
| 134 | + elif [ "$linux" = "fail" ] || [ "$macos" = "fail" ] || [ "$windows" = "fail" ]; then |
| 135 | + color="red" |
| 136 | + else |
| 137 | + color="lightgrey" |
| 138 | + fi |
| 139 | +
|
| 140 | + badge_url="https://img.shields.io/badge/svv_passing-${label}-${color}" |
| 141 | + link="https://github.com/${GITHUB_REPOSITORY}/actions/workflows/basic-smoke-test.yml?query=branch%3A${GITHUB_REF_NAME}" |
| 142 | + new_badge="[](${link})" |
| 143 | +
|
| 144 | + BADGE_URL="${badge_url}" BADGE_LINK="${link}" BADGE_MD="${new_badge}" python - << 'PY' |
| 145 | + import os |
| 146 | + import re |
| 147 | + from pathlib import Path |
| 148 | +
|
| 149 | + readme_path = Path("README.md") |
| 150 | + text = readme_path.read_text(encoding="utf-8") |
| 151 | +
|
| 152 | + badge_url = os.environ["BADGE_URL"] |
| 153 | + link = os.environ["BADGE_LINK"] |
| 154 | + badge_md = os.environ["BADGE_MD"] |
| 155 | +
|
| 156 | + pattern = re.compile(r"<!-- smoke-test-badge -->.*?<!-- /smoke-test-badge -->", re.S) |
| 157 | + replacement = f"<!-- smoke-test-badge -->\n{badge_md}\n<!-- /smoke-test-badge -->" |
| 158 | + new_text, n = pattern.subn(replacement, text) |
| 159 | + if n == 0: |
| 160 | + raise SystemExit("smoke-test-badge markers not found in README.md") |
| 161 | +
|
| 162 | + readme_path.write_text(new_text, encoding="utf-8") |
| 163 | + PY |
| 164 | +
|
| 165 | + - name: Commit README badge update |
| 166 | + run: | |
| 167 | + if git diff --quiet README.md; then |
| 168 | + echo "No README changes to commit." |
| 169 | + else |
| 170 | + git config user.name "github-actions[bot]" |
| 171 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 172 | + git add README.md |
| 173 | + git commit -m "Update smoke test status badge" |
| 174 | + git push |
| 175 | + fi |
0 commit comments