Merge pull request #50 from zasexton/main #5
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: Basic smoke test | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| build-and-test: | |
| if: github.actor != 'github-actions[bot]' | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| python-version: ["3.9", "3.10", "3.11", "3.12"] | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install Python dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Build svVascularize | |
| env: | |
| SVV_BUILD_MMG: "1" | |
| run: | | |
| pip install . | |
| - name: Run basic smoke test | |
| run: | | |
| python .github/scripts/basic_smoke_test.py | |
| - name: Record job status | |
| if: always() | |
| run: | | |
| echo "${{ matrix.os }}=${{ job.status }}" > smoke-status.txt | |
| - name: Upload status artifact | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: smoke-status-${{ matrix.os }}-py${{ matrix.python-version }} | |
| path: smoke-status.txt | |
| update-smoke-badge: | |
| if: ${{ github.actor != 'github-actions[bot]' && always() }} | |
| needs: build-and-test | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download status artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: smoke-status-* | |
| path: smoke-status | |
| - name: Update README smoke test badge | |
| run: | | |
| set -euo pipefail | |
| linux="unknown" | |
| macos="unknown" | |
| windows="unknown" | |
| # If no smoke-status artifacts were downloaded, skip badge update. | |
| if ! compgen -G "smoke-status/*/smoke-status.txt" > /dev/null; then | |
| echo "No smoke-status artifacts found; skipping badge update." | |
| exit 0 | |
| fi | |
| # Each artifact directory contains a single smoke-status.txt file. | |
| for f in smoke-status/*/smoke-status.txt; do | |
| line=$(cat "$f") | |
| os="${line%%=*}" | |
| status="${line#*=}" | |
| case "$os" in | |
| ubuntu-latest) | |
| if [ "$status" = "success" ]; then | |
| if [ "$linux" = "unknown" ]; then | |
| linux="ok" | |
| fi | |
| else | |
| linux="fail" | |
| fi | |
| ;; | |
| macos-latest) | |
| if [ "$status" = "success" ]; then | |
| if [ "$macos" = "unknown" ]; then | |
| macos="ok" | |
| fi | |
| else | |
| macos="fail" | |
| fi | |
| ;; | |
| windows-latest) | |
| if [ "$status" = "success" ]; then | |
| if [ "$windows" = "unknown" ]; then | |
| windows="ok" | |
| fi | |
| else | |
| windows="fail" | |
| fi | |
| ;; | |
| esac | |
| done | |
| label="linux_${linux}-macos_${macos}-windows_${windows}" | |
| if [ "$linux" = "ok" ] && [ "$macos" = "ok" ] && [ "$windows" = "ok" ]; then | |
| color="brightgreen" | |
| elif [ "$linux" = "fail" ] || [ "$macos" = "fail" ] || [ "$windows" = "fail" ]; then | |
| color="red" | |
| else | |
| color="lightgrey" | |
| fi | |
| badge_url="https://img.shields.io/badge/svv_passing-${label}-${color}" | |
| link="https://github.com/${GITHUB_REPOSITORY}/actions/workflows/basic-smoke-test.yml?query=branch%3A${GITHUB_REF_NAME}" | |
| new_badge="[](${link})" | |
| BADGE_URL="${badge_url}" BADGE_LINK="${link}" BADGE_MD="${new_badge}" python - << 'PY' | |
| import os | |
| import re | |
| from pathlib import Path | |
| readme_path = Path("README.md") | |
| text = readme_path.read_text(encoding="utf-8") | |
| badge_url = os.environ["BADGE_URL"] | |
| link = os.environ["BADGE_LINK"] | |
| badge_md = os.environ["BADGE_MD"] | |
| pattern = re.compile(r"<!-- smoke-test-badge -->.*?<!-- /smoke-test-badge -->", re.S) | |
| replacement = f"<!-- smoke-test-badge -->\n{badge_md}\n<!-- /smoke-test-badge -->" | |
| new_text, n = pattern.subn(replacement, text) | |
| if n == 0: | |
| raise SystemExit("smoke-test-badge markers not found in README.md") | |
| readme_path.write_text(new_text, encoding="utf-8") | |
| PY | |
| - name: Commit README badge update | |
| run: | | |
| if git diff --quiet README.md; then | |
| echo "No README changes to commit." | |
| else | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add README.md | |
| git commit -m "Update smoke test status badge" | |
| git push | |
| fi |