Skip to content
366 changes: 363 additions & 3 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,378 @@
echo "This run is not a PR (branch: ${GITHUB_REF_NAME})"
fi

- name: Run pytest with multiple workers in parallel
- name: Install jq in micromamba env
shell: micromamba-shell {0}
run: micromamba install -y jq

- name: Install pytest-json-report
shell: micromamba-shell {0}
run: python -m pip install --upgrade pytest-json-report

- name: Check If Previous Artifacts Exist
id: check_artifacts
shell: micromamba-shell {0}
run: |
echo "Checking if previous artifacts exist for PR-${PR_ID}..."
ARTIFACTS_RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts")

ARTIFACT_COUNT=$(echo "$ARTIFACTS_RESPONSE" \
| jq -r --arg NAME "pr_${PR_ID}_macos_smoketest" \
'[.artifacts[] | select(.name==$NAME and .expired==false)] | length')

echo "Found ${ARTIFACT_COUNT} matching artifact(s)."
if [[ "$ARTIFACT_COUNT" -gt 0 ]]; then
echo "PREV_ARTIFACT_EXISTS=true" >> "$GITHUB_ENV"
else
echo "PREV_ARTIFACT_EXISTS=false" >> "$GITHUB_ENV"
fi

- name: Create smoketest file (pr_<id>/macos)
shell: bash
run: |
PR_DIR="pr_${PR_ID}"
mkdir -p "artifacts/${PR_DIR}/macos"
{
echo "workflow: macOS"
echo "event: ${{ github.event_name }}"
echo "branch: ${GITHUB_REF_NAME}"
echo "pr_id: ${PR_ID}"
echo "timestamp: $(date -Iseconds)"
} > "artifacts/${PR_DIR}/macos/smoketest.txt"

- name: Upload smoketest artifact
uses: actions/upload-artifact@v4
with:
name: pr_${{ env.PR_ID }}_macos_smoketest
path: artifacts/pr_${{ env.PR_ID }}/macos/smoketest.txt
retention-days: 3

- name: Download smoketest artifact (to verify upload)
uses: actions/download-artifact@v4
with:
name: pr_${{ env.PR_ID }}_macos_smoketest
path: retrieved

- name: Show downloaded artifact contents
shell: bash
run: |
echo "==== Retrieved Artifact Files ===="
find retrieved -type f
echo "----------------------------------"
echo "Content of smoketest.txt:"
cat retrieved/smoketest.txt || echo "No smoketest file found."

# - name: Run pytest with multiple workers in parallel
# shell: micromamba-shell {0}
# run: |
# PYTHONPATH="$(grass --config python_path):${PYTHONPATH}"
# LD_LIBRARY_PATH="$(grass --config path)/lib:${LD_LIBRARY_PATH}"
# export PYTHONPATH
# export LD_LIBRARY_PATH
# pytest \
# @.github/workflows/pytest_args_ci.txt \
# @.github/workflows/pytest_args_parallel.txt \
# --junitxml=pytest.xdist.junit.xml \
# -k 'not testsuite'

- name: Check If Previous macOS Parallel Artifacts Exist
shell: micromamba-shell {0}
run: |
echo "Checking previous artifacts for PR-${PR_ID}..."

ARTIFACTS_RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts")

ARTIFACT_COUNT=$(echo "$ARTIFACTS_RESPONSE" \
| jq -r --arg NAME "pr_${PR_ID}_macos_parallel_results" \
'[.artifacts[] | select(.name==$NAME and .expired==false)] | length')

echo "Found ${ARTIFACT_COUNT} matching artifact(s)."

if [[ "$ARTIFACT_COUNT" -gt 0 ]]; then
echo "PREV_ARTIFACT_EXISTS=true" >> "$GITHUB_ENV"
else
echo "PREV_ARTIFACT_EXISTS=false" >> "$GITHUB_ENV"
fi

- name: Retrieve Previous macOS Parallel Artifacts
if: env.PREV_ARTIFACT_EXISTS == 'true'
shell: micromamba-shell {0}
run: |
echo "Retrieving previous macOS parallel results for PR-${PR_ID}..."

ARTIFACT_URL=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts" \
| jq -r --arg NAME "pr_${PR_ID}_macos_parallel_results" \
'[.artifacts[] | select(.name==$NAME)] | sort_by(.created_at) | reverse | .[0].archive_download_url')

if [[ -z "$ARTIFACT_URL" || "$ARTIFACT_URL" == "null" ]]; then
echo "Artifact URL not found."
exit 0
fi

mkdir -p artifacts/pr_${PR_ID}/macos_prev
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-o artifacts/pr_${PR_ID}/macos_prev/results.zip "$ARTIFACT_URL"

unzip -o artifacts/pr_${PR_ID}/macos_prev/results.zip -d artifacts/pr_${PR_ID}/macos_prev

echo "===== Previous macOS parallel test results ====="
cat artifacts/pr_${PR_ID}/macos_prev/test_results.json || echo "No previous JSON found"
echo "================================================"

- name: Run previously failed tests first (macOS)
shell: micromamba-shell {0}
run: |
PYTHONPATH="$(grass --config python_path):${PYTHONPATH}"
LD_LIBRARY_PATH="$(grass --config path)/lib:${LD_LIBRARY_PATH}"
export PYTHONPATH
export LD_LIBRARY_PATH

PR_DIR="pr_${PR_ID}"
PREV_DIR="artifacts/${PR_DIR}/macos_prev"
CURR_DIR="artifacts/${PR_DIR}/macos"

mkdir -p "${CURR_DIR}"

FAILED_TESTS_FILE="${PREV_DIR}/failed_tests.txt"
TEMP_RESULTS="${CURR_DIR}/temp_test_results.json"

if [[ -s "${FAILED_TESTS_FILE}" ]]; then
echo "Re-running previously failed tests first:"
cat "${FAILED_TESTS_FILE}"

pytest \
@.github/workflows/pytest_args_ci.txt \
@.github/workflows/pytest_args_parallel.txt \
--json-report --json-report-file="${TEMP_RESULTS}" \
$(cat "${FAILED_TESTS_FILE}") || true
else
echo "No previously failed tests found."
# create empty JSON file so next steps never break
echo '{"tests": []}' > "${TEMP_RESULTS}"
fi

- name: Check if any tests failed again (macOS)
shell: micromamba-shell {0}
run: |
PR_DIR="pr_${PR_ID}"
CURR_DIR="artifacts/${PR_DIR}/macos"
TEMP_RESULTS="${CURR_DIR}/temp_test_results.json"
FAILED_AGAIN_FILE="${CURR_DIR}/failed_again.txt"

if [[ -f "${TEMP_RESULTS}" ]]; then
echo "Checking if any previously failed tests are still failing..."
jq -r '.tests | map(select(.outcome == "failed")) | .[].nodeid' \
"${TEMP_RESULTS}" > "${FAILED_AGAIN_FILE}" || true
else
echo "No temp JSON results found, assuming no tests failed again."
: > "${FAILED_AGAIN_FILE}"
fi

if [[ -s "${FAILED_AGAIN_FILE}" ]]; then
echo "Some tests failed again. Stopping execution."
echo "Tests failing again:"
cat "${FAILED_AGAIN_FILE}"
exit 1
else
echo "No tests failed again. Continuing with remaining tests..."
fi


- name: Collect all test cases (parallel macOS)
shell: micromamba-shell {0}
run: |
PYTHONPATH="$(grass --config python_path):${PYTHONPATH}"
LD_LIBRARY_PATH="$(grass --config path)/lib:${LD_LIBRARY_PATH}"
export PYTHONPATH
export LD_LIBRARY_PATH

PR_DIR="pr_${PR_ID}"
CURR_DIR="artifacts/${PR_DIR}/macos"
mkdir -p "${CURR_DIR}"

RAW_COLLECT="${CURR_DIR}/raw_collect.txt"
ALL_TESTS_FILE="${CURR_DIR}/all_tests.txt"

echo "Collecting test nodeids..."
# 1) Capture ALL output (stdout + stderr)
pytest \
@.github/workflows/pytest_args_ci.txt \
@.github/workflows/pytest_args_parallel.txt \
--junitxml=pytest.xdist.junit.xml \
-k 'not testsuite'
--collect-only -q \
-k 'not testsuite' > "${RAW_COLLECT}" 2>&1 || true

echo "===== DEBUG: raw_collect (first 40 lines) ====="
head -n 40 "${RAW_COLLECT}" || true
echo "==============================================="

# 2) Extract lines that look like nodeids
grep "::" "${RAW_COLLECT}" > "${ALL_TESTS_FILE}" || true

echo "===== DEBUG: all_tests.txt ====="
wc -l "${ALL_TESTS_FILE}" || true
head -n 10 "${ALL_TESTS_FILE}" || true
echo "================================"


- name: Debug all_tests count (macOS)
shell: micromamba-shell {0}
run: |
PR_DIR="pr_${PR_ID}"
CURR_DIR="artifacts/${PR_DIR}/macos"
ALL_TESTS_FILE="${CURR_DIR}/all_tests.txt"

echo "===== DEBUG: all_tests.txt ====="
if [[ -f "${ALL_TESTS_FILE}" ]]; then
wc -l "${ALL_TESTS_FILE}" || true
echo "Sample lines:"
head -n 5 "${ALL_TESTS_FILE}" || true
else
echo "all_tests.txt not found"
fi
echo "================================"

- name: Debug remaining_tests count (macOS)
shell: micromamba-shell {0}
run: |
PR_DIR="pr_${PR_ID}"
CURR_DIR="artifacts/${PR_DIR}/macos"
REMAINING_TESTS_FILE="${CURR_DIR}/remaining_tests.txt"

echo "===== DEBUG: remaining_tests.txt ====="
if [[ -f "${REMAINING_TESTS_FILE}" ]]; then
wc -l "${REMAINING_TESTS_FILE}" || true
echo "Sample lines:"
head -n 5 "${REMAINING_TESTS_FILE}" || true
else
echo "remaining_tests.txt not found"
fi
echo "======================================"



Check failure on line 362 in .github/workflows/macos.yml

View workflow job for this annotation

GitHub Actions / Additional checks

362:1 [empty-lines] too many blank lines (3 > 2)
- name: Identify remaining tests to run (macOS)
shell: micromamba-shell {0}
run: |
PYTHONPATH="$(grass --config python_path):${PYTHONPATH}"
LD_LIBRARY_PATH="$(grass --config path)/lib:${LD_LIBRARY_PATH}"
export PYTHONPATH
export LD_LIBRARY_PATH

PR_DIR="pr_${PR_ID}"
PREV_DIR="artifacts/${PR_DIR}/macos_prev"
CURR_DIR="artifacts/${PR_DIR}/macos"

ALL_TESTS_FILE="${CURR_DIR}/all_tests.txt"
FAILED_PREV="${PREV_DIR}/failed_tests.txt"
REMAINING_TESTS_FILE="${CURR_DIR}/remaining_tests.txt"

mkdir -p "${CURR_DIR}"

if [[ -f "${FAILED_PREV}" && -s "${FAILED_PREV}" ]]; then
echo "Computing remaining tests (excluding previously failed ones)..."
grep -v -F -f "${FAILED_PREV}" "${ALL_TESTS_FILE}" > "${REMAINING_TESTS_FILE}" || true
else
echo "No previous failed tests list found or it is empty."
echo "Treating all collected tests as remaining."
cp "${ALL_TESTS_FILE}" "${REMAINING_TESTS_FILE}" || true
fi

echo "Remaining tests to run:"
cat "${REMAINING_TESTS_FILE}" || echo "No remaining tests found."



Check failure on line 394 in .github/workflows/macos.yml

View workflow job for this annotation

GitHub Actions / Additional checks

394:1 [empty-lines] too many blank lines (3 > 2)
# - name: Run pytest with multiple workers in parallel (JSON report)
# shell: micromamba-shell {0}
# run: |
# PYTHONPATH="$(grass --config python_path):${PYTHONPATH}"
# LD_LIBRARY_PATH="$(grass --config path)/lib:${LD_LIBRARY_PATH}"
# export PYTHONPATH
# export LD_LIBRARY_PATH

# PR_DIR="pr_${PR_ID}"
# mkdir -p "artifacts/${PR_DIR}/macos"

# OUT_JSON="artifacts/${PR_DIR}/macos/test_results.json"

# pytest \
# @.github/workflows/pytest_args_ci.txt \
# @.github/workflows/pytest_args_parallel.txt \
# --junitxml=pytest.xdist.junit.xml \
# --json-report --json-report-file="${OUT_JSON}" \
# -k 'not testsuite' || true

- name: Run pytest with multiple workers in parallel (JSON report)
shell: micromamba-shell {0}
run: |
PYTHONPATH="$(grass --config python_path):${PYTHONPATH}"
LD_LIBRARY_PATH="$(grass --config path)/lib:${LD_LIBRARY_PATH}"
export PYTHONPATH
export LD_LIBRARY_PATH

PR_DIR="pr_${PR_ID}"
CURR_DIR="artifacts/${PR_DIR}/macos"
mkdir -p "${CURR_DIR}"

OUT_JSON="${CURR_DIR}/test_results.json"
REMAINING_TESTS_FILE="${CURR_DIR}/remaining_tests.txt"

if [[ -s "${REMAINING_TESTS_FILE}" ]]; then
echo "Running remaining test cases (macOS)..."
pytest \
@.github/workflows/pytest_args_ci.txt \
@.github/workflows/pytest_args_parallel.txt \
--junitxml=pytest.xdist.junit.xml \
--json-report --json-report-file="${OUT_JSON}" \
$(cat "${REMAINING_TESTS_FILE}") || true
else
echo "No remaining test cases to run. Writing empty JSON."
echo '{"tests": []}' > "${OUT_JSON}"
fi

- name: Extract failed and passed tests (parallel macOS)
shell: micromamba-shell {0}
run: |
PR_DIR="pr_${PR_ID}"
BASE_DIR="artifacts/${PR_DIR}/macos"
RESULTS="${BASE_DIR}/test_results.json"
FAILED="${BASE_DIR}/failed_tests.txt"
PASSED="${BASE_DIR}/passed_tests.txt"

if [[ -f "${RESULTS}" ]]; then
jq -r '.tests | map(select(.outcome == "failed")) | .[].nodeid' \
"${RESULTS}" > "${FAILED}" || true
jq -r '.tests | map(select(.outcome == "passed")) | .[].nodeid' \
"${RESULTS}" > "${PASSED}" || true
else
: > "${FAILED}"
: > "${PASSED}"
fi

echo "Failed tests:"
cat "${FAILED}" || true
echo "Passed tests:"
cat "${PASSED}" || true


- name: Upload macOS parallel test artifacts
uses: actions/upload-artifact@v4
with:
name: pr_${{ env.PR_ID }}_macos_parallel_results
path: |
artifacts/pr_${{ env.PR_ID }}/macos/all_tests.txt
artifacts/pr_${{ env.PR_ID }}/macos/failed_tests.txt
artifacts/pr_${{ env.PR_ID }}/macos/passed_tests.txt
artifacts/pr_${{ env.PR_ID }}/macos/test_results.json
retention-days: 7


- name: Run pytest with a single worker (for tests marked with needs_solo_run)
shell: micromamba-shell {0}
run: |
Expand Down
3 changes: 2 additions & 1 deletion general/g.version/tests/g_version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"build_platform",
"build_off_t_size",
]

def test_priotestci_force_fail():

Check failure on line 11 in general/g.version/tests/g_version_test.py

View workflow job for this annotation

GitHub Actions / Python Code Quality Checks (ubuntu-24.04)

Ruff (E302)

general/g.version/tests/g_version_test.py:11:1: E302 Expected 2 blank lines, found 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ruff] reported by reviewdog 🐶

Suggested change
def test_priotestci_force_fail():
def test_priotestci_force_fail():

assert False, "Intentional failure to test PrioTestCI artifacts"

Check failure on line 12 in general/g.version/tests/g_version_test.py

View workflow job for this annotation

GitHub Actions / Python Code Quality Checks (ubuntu-24.04)

Ruff (B011)

general/g.version/tests/g_version_test.py:12:12: B011 Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`

Check failure on line 12 in general/g.version/tests/g_version_test.py

View workflow job for this annotation

GitHub Actions / Python Code Quality Checks (ubuntu-24.04)

Ruff (PT015)

general/g.version/tests/g_version_test.py:12:5: PT015 Assertion always fails, replace with `pytest.fail()`

Check failure on line 12 in general/g.version/tests/g_version_test.py

View workflow job for this annotation

GitHub Actions / pytest (ubuntu-24.04, 3.10)

test_priotestci_force_fail AssertionError: Intentional failure to test PrioTestCI artifacts assert False

Check failure on line 12 in general/g.version/tests/g_version_test.py

View workflow job for this annotation

GitHub Actions / pytest (ubuntu-24.04, 3.13)

test_priotestci_force_fail AssertionError: Intentional failure to test PrioTestCI artifacts assert False
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ruff] reported by reviewdog 🐶

Suggested change
assert False, "Intentional failure to test PrioTestCI artifacts"
msg = "Intentional failure to test PrioTestCI artifacts"
raise AssertionError(msg)


def curly_brackets_paired(text):

Check failure on line 14 in general/g.version/tests/g_version_test.py

View workflow job for this annotation

GitHub Actions / Python Code Quality Checks (ubuntu-24.04)

Ruff (E302)

general/g.version/tests/g_version_test.py:14:1: E302 Expected 2 blank lines, found 1
"""Check whether all curly brackets in the given text are properly paired."""
counter = 0
for character in text:
Expand Down
Loading