Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,40 +140,66 @@ jobs:
check_integration_label:
runs-on: ubuntu-latest
needs: [build]
permissions:
pull-requests: read
outputs:
has_geos_integration_label: ${{ steps.set-label.outputs.has_label }}
steps:
- name: Check if PR has '${{ env.LABEL_TEST_GEOS_INTEGRATION }}' label
id: set-label
# Fetch labels live from the GitHub REST API rather than reading
# github.event.pull_request.labels. The event payload is a snapshot
# frozen at the time the workflow was first triggered, so labels
# added after that first run are invisible to re-runs.
env:
GITHUB_TOKEN: ${{ github.token }}
REQUIRED_LABEL: ${{ env.LABEL_TEST_GEOS_INTEGRATION }}
run: |
echo "Checking for label..."
LABEL_FOUND=false
LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}'
PR_JSON=$(curl --fail --silent --show-error \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}")
LABELS=$(echo "${PR_JSON}" | jq -crM '[.labels[].name]')
echo "PR Labels: $LABELS"
if echo "$LABELS" | grep -q "${{ env.LABEL_TEST_GEOS_INTEGRATION }}"; then
if echo "$LABELS" | jq -e --arg label "${REQUIRED_LABEL}" 'index($label) != null' > /dev/null; then
LABEL_FOUND=true
echo "Label '${{ env.LABEL_TEST_GEOS_INTEGRATION }}' found"
echo "Label '${REQUIRED_LABEL}' found"
fi
echo "has_label=$LABEL_FOUND" >> $GITHUB_OUTPUT
echo "has_label=$LABEL_FOUND" >> "$GITHUB_OUTPUT"

check_force_integration_label:
runs-on: ubuntu-latest
# needs: [build]
permissions:
pull-requests: read
outputs:
has_geos_integration_force_label: ${{ steps.set-label.outputs.has_label }}
steps:
- name: Check if PR has '${{ env.LABEL_FORCE_GEOS_INTEGRATION }}' label
id: set-label
# Fetch labels live from the GitHub REST API rather than reading
# github.event.pull_request.labels. The event payload is a snapshot
# frozen at the time the workflow was first triggered, so labels
# added after that first run are invisible to re-runs.
env:
GITHUB_TOKEN: ${{ github.token }}
REQUIRED_LABEL: ${{ env.LABEL_FORCE_GEOS_INTEGRATION }}
run: |
echo "Checking for label..."
LABEL_FOUND=false
LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}'
PR_JSON=$(curl --fail --silent --show-error \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}")
LABELS=$(echo "${PR_JSON}" | jq -crM '[.labels[].name]')
echo "PR Labels: $LABELS"
if echo "$LABELS" | grep -q "${{ env.LABEL_FORCE_GEOS_INTEGRATION }}"; then
if echo "$LABELS" | jq -e --arg label "${REQUIRED_LABEL}" 'index($label) != null' > /dev/null; then
LABEL_FOUND=true
echo "Label '${{ env.LABEL_FORCE_GEOS_INTEGRATION }}' found"
echo "Label '${REQUIRED_LABEL}' found"
fi
echo "has_label=$LABEL_FOUND" >> $GITHUB_OUTPUT
echo "has_label=$LABEL_FOUND" >> "$GITHUB_OUTPUT"

# Step 3: Check if GEOS integration is required based on changed files
check_geos_integration_required:
Expand Down
49 changes: 48 additions & 1 deletion geos-ats/src/geos/ats/baseline_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import tempfile
import shutil
import subprocess
import yaml
import time
import requests
Expand Down Expand Up @@ -161,6 +162,51 @@ def collect_baselines( bucket_name: str,
raise Exception( f'Could not find baseline files to unpack: expected={archive_name}' )


def _available_cpu_count() -> int:
if hasattr( os, 'sched_getaffinity' ):
return len( os.sched_getaffinity( 0 ) )
return os.cpu_count() or 1


def _pack_baselines_with_parallel_gzip( archive_name: str, baseline_path: str ) -> bool:
tar_bin = shutil.which( 'tar' )
pigz_bin = shutil.which( 'pigz' )
if not tar_bin or not pigz_bin:
logger.info( 'tar and pigz were not both found; using Python gztar archiver' )
return False

archive_path = f'{archive_name}.tar.gz'
threads = str( _available_cpu_count() )
logger.info( f'Archiving baseline files with tar and pigz -9 ({threads} threads)...' )

try:
with open( archive_path, 'wb' ) as output:
tar_process = subprocess.Popen( [ tar_bin, '-C', baseline_path, '-cf', '-', '.' ], stdout=subprocess.PIPE )
if tar_process.stdout is None:
raise RuntimeError( 'failed to capture tar output' )
pigz_process = subprocess.Popen( [ pigz_bin, '-9', '-p', threads ],
stdin=tar_process.stdout,
stdout=output )
tar_process.stdout.close()

pigz_status = pigz_process.wait()
tar_status = tar_process.wait()

if tar_status != 0 or pigz_status != 0:
try:
os.remove( archive_path )
except FileNotFoundError:
pass
raise RuntimeError( f'tar exited with {tar_status}; pigz exited with {pigz_status}' )

except Exception as e:
logger.warning( 'Parallel baseline archive creation failed; using Python gztar archiver' )
logger.warning( repr( e ) )
return False
Comment on lines +182 to +205
Comment on lines +192 to +205

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pigz_status = pigz_process.wait()
tar_status = tar_process.wait()
if tar_status != 0 or pigz_status != 0:
try:
os.remove( archive_path )
except FileNotFoundError:
pass
raise RuntimeError( f'tar exited with {tar_status}; pigz exited with {pigz_status}' )
except Exception as e:
logger.warning( 'Parallel baseline archive creation failed; using Python gztar archiver' )
logger.warning( repr( e ) )
return False
pigz_status = pigz_process.wait()
if pigz_status != 0:
tar_process.kill()
tar_process.wait()
raise RuntimeError(f'pigz exited with {pigz_status}')
tar_status = tar_process.wait()
if tar_status != 0:
raise RuntimeError(f'tar exited with {tar_status}')
except Exception as e:
for proc in (pigz_process, tar_process):
if proc is not None and proc.poll() is None:
try:
proc.kill()
except ProcessLookupError:
pass
proc.wait()
try:
os.remove(archive_path)
except FileNotFoundError:
pass
logger.warning('Parallel baseline archive creation failed; using Python gztar archiver')
logger.warning(repr(e))
return False

@jafranc jafranc Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@rrsettgast Suggest adding a zombie process clean-up if fail in this context


return True


def pack_baselines( archive_name: str, baseline_path: str, log_path: str = '' ):
"""
Pack and upload baselines to GCP
Expand Down Expand Up @@ -201,7 +247,8 @@ def pack_baselines( archive_name: str, baseline_path: str, log_path: str = '' ):

try:
logger.info( 'Archiving baseline files...' )
shutil.make_archive( archive_name, format='gztar', root_dir=baseline_path )
if not _pack_baselines_with_parallel_gzip( archive_name, baseline_path ):
shutil.make_archive( archive_name, format='gztar', root_dir=baseline_path )
logger.info( f'Created {archive_name}.tar.gz' )
except Exception as e:
logger.error( 'Failed to create baseline archive' )
Expand Down
4 changes: 3 additions & 1 deletion geos-ats/src/geos/ats/helpers/restart_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

RTOL_DEFAULT = 0.0
ATOL_DEFAULT = 0.0
EXCLUDE_DEFAULT = [ ".*/commandLine", ".*/schema$", ".*/globalToLocalMap", ".*/timeHistoryOutput.*/restart" ]
EXCLUDE_DEFAULT = [
".*/commandLine", ".*/schema$", ".*/globalToLocalMap", ".*/timeHistoryOutput.*/restart", ".*/dNdX", ".*/detJ"
]
logger = logging.getLogger( 'geos-ats' )


Expand Down
Loading