Skip to content

Commit

Permalink
Merge pull request xsuite#214 from szymonlopaciuk/main
Browse files Browse the repository at this point in the history
workflows: add a UUID to image id to avoid collisions in concurrent runs
  • Loading branch information
szymonlopaciuk authored Nov 1, 2022
2 parents d04a250 + a44c0c8 commit 198c382
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/cron_test_gpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ on:
schedule:
- cron: '00 19 * * *' # run at 19:00 UTC daily

# This workflow calls the test_gh.yaml workflow passing the default
# branches as inputs
# This workflow calls the test_gpu.yaml workflow passing the default
# branches as inputs. The cron workflow will not run on forks.
jobs:
run-tests-cron-gh:
run-tests-cron-gpu:
if: github.repository == 'xsuite/xsuite'
uses: ./.github/workflows/test_gpu.yaml
with:
xobjects_location: 'xsuite:main'
Expand Down
50 changes: 32 additions & 18 deletions .github/workflows/test_gpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,55 @@ on:
# The jobs are all run in independent environments. Here we will run a separate job
# for each of the test suites specified in the matrix below.
jobs:
# First, we build our test image based on the instructions on Gitlab
# First, we build our test image
build-test-image:
runs-on: ['self-hosted']
outputs:
image_id: ${{ steps.build-image.outputs.image_id }}
steps:
- name: Checkout the repo
- id: checkout-repo
name: Checkout the repo
uses: actions/checkout@v3
- name: Build the test image
- id: build-image
name: Build the test image
env:
config_repo: ${{ secrets.XSUITE_TEST_CONFIGS_GIT }}
xobjects_branch: ${{ inputs.xobjects_location }}
xdeps_branch: ${{ inputs.xdeps_location }}
xpart_branch: ${{ inputs.xpart_location }}
xtrack_branch: ${{ inputs.xtrack_location }}
xfields_branch: ${{ inputs.xfields_location }}
run: |
IMAGE="xsuite-test-runner-$(cat /proc/sys/kernel/random/uuid)"
echo "image_id=$IMAGE" >> $GITHUB_OUTPUT
docker build \
--no-cache=true \
--build-arg xobjects_branch=${xobjects_branch} \
--build-arg xdeps_branch=${xdeps_branch} \
--build-arg xpart_branch=${xpart_branch} \
--build-arg xtrack_branch=${xtrack_branch} \
--build-arg xfields_branch=${xfields_branch} \
-t xsuite-test-runner .
-t $IMAGE .
# Print out some stuff about the test environment
image-sanity-checks:
runs-on: ['self-hosted']
needs: build-test-image
env:
image_id: ${{ needs.build-test-image.outputs.image_id }}
steps:
- name: CUDA info
run: docker run --rm --gpus all xsuite-test-runner nvidia-smi
run: docker run --rm --gpus all ${image_id} nvidia-smi
- name: OpenCL info
run: docker run --rm --gpus all xsuite-test-runner clinfo
run: docker run --rm --gpus all ${image_id} clinfo
- name: Package paths
run: docker run --rm --gpus all xsuite-test-runner python3 /opt/xsuite/xtrack/examples/print_package_paths.py
run: docker run --rm --gpus all ${image_id} python3 /opt/xsuite/xtrack/examples/print_package_paths.py
- name: List dependencies
run: docker run --rm --gpus all xsuite-test-runner pip freeze
run: docker run --rm --gpus all ${image_id} pip freeze

# Run the tests for each repo in parallel in a test container
run-tests:
runs-on: ['self-hosted']
needs: image-sanity-checks
needs: [build-test-image, image-sanity-checks]
strategy:
fail-fast: false
matrix:
Expand All @@ -80,21 +87,28 @@ jobs:

steps:
- name: Run pytest
env:
image_id: ${{ needs.build-test-image.outputs.image_id }}
test_contexts: 'ContextCpu;ContextCupy;ContextPyopencl'
run: |
docker run --rm --gpus all \
--env XOBJECTS_TEST_CONTEXTS='ContextCpu;ContextCupy;ContextPyopencl' xsuite-test-runner \
--env XOBJECTS_TEST_CONTEXTS="${test_contexts}" \
${image_id} \
pytest --color=yes -v /opt/xsuite/${{ matrix.test-suite }}/tests
# Cleanup after the tests by removing the image and making sure there are
# no unused images and stopped containers
teardown:
runs-on: ['self-hosted']
needs: run-tests
needs: [build-test-image, run-tests]
env:
image_id: ${{ needs.build-test-image.outputs.image_id }}
if: always()
steps:
- name: Stop any containers lagging behind
run: docker kill $(docker ps -q --filter ancestor=xsuite-test-runner) || true
- name: Remove the test image
run: docker image rm xsuite-test-runner
- name: Prune containers and images
run: docker system prune -f
- name: Stop the containers and remove the image
run: |
docker container stop \
$(docker ps -q --filter ancestor=${image_id}) || true
docker container rm --volumes \
$(docker ps -qa --filter ancestor=${image_id}) || true
docker image rm ${image_id}

0 comments on commit 198c382

Please sign in to comment.