Skip to content

Commit 18c3112

Browse files
authored
Adding tmate action to CI for debugging (openmc-dev#3138)
1 parent e9ddf88 commit 18c3112

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ jobs:
8888

8989
steps:
9090
- uses: actions/checkout@v4
91+
with:
92+
fetch-depth: 2
9193

9294
- name: Set up Python ${{ matrix.python-version }}
9395
uses: actions/setup-python@v5
@@ -98,7 +100,17 @@ jobs:
98100
run: |
99101
echo "OPENMC_CROSS_SECTIONS=$HOME/nndc_hdf5/cross_sections.xml" >> $GITHUB_ENV
100102
echo "OPENMC_ENDF_DATA=$HOME/endf-b-vii.1" >> $GITHUB_ENV
101-
103+
# get the sha of the last branch commit
104+
# for push and workflow_dispatch events, use the current reference head
105+
BRANCH_SHA=HEAD
106+
# for a pull_request event, use the last reference of the parents of the merge commit
107+
if [ "${{ github.event_name }}" == "pull_request" ]; then
108+
BRANCH_SHA=$(git rev-list --parents -n 1 HEAD | rev | cut -d" " -f 1 | rev)
109+
fi
110+
COMMIT_MESSAGE=$(git log $BRANCH_SHA -1 --pretty=%B)
111+
echo ${COMMIT_MESSAGE}
112+
echo "COMMIT_MESSAGE=${COMMIT_MESSAGE}" >> $GITHUB_ENV
113+
102114
- name: Apt dependencies
103115
shell: bash
104116
run: |
@@ -153,6 +165,12 @@ jobs:
153165
CTEST_OUTPUT_ON_FAILURE=1 make test -C $GITHUB_WORKSPACE/build/
154166
$GITHUB_WORKSPACE/tools/ci/gha-script.sh
155167
168+
- name: Setup tmate debug session
169+
continue-on-error: true
170+
if: ${{ contains(env.COMMIT_MESSAGE, '[gha-debug]') }}
171+
uses: mxschmitt/action-tmate@v3
172+
timeout-minutes: 10
173+
156174
- name: after_success
157175
shell: bash
158176
run: |

docs/source/devguide/tests.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,30 @@ that, consider the following:
8484
limit the number of threads that OpenBLAS uses internally; this can be done by
8585
setting the :envvar:`OPENBLAS_NUM_THREADS` environment variable to 1.
8686

87+
Debugging Tests in CI
88+
---------------------
89+
90+
.. _tmate: <https://github.com/mxschmitt/action-tmate?tab=readme-ov-file#debug-your-github-actions-by-using-tmate>`_
91+
92+
Tests can be debugged in CI using a feature called `tmate`_. CI debugging can be
93+
enabled by including "[gha-debug]" in the commit message. When the test fails, a
94+
link similar to the one shown below will be provided in the GitHub Actions
95+
output after failure occurs. Logging into the provided link will allow you to
96+
debug the test in the CI environment. The following is an example of the output
97+
shown in the CI log that provides the link to the tmate session:
98+
99+
.. code-block:: text
100+
:linenos:
101+
102+
Created new session successfully
103+
104+
https://tmate.io/t/2VcykjU7vNdvAzEjQcc839GM2
105+
Entering main loop
106+
Web shell: https://tmate.io/t/2VcykjU7vNdvAzEjQcc839GM2
107+
108+
...
109+
110+
87111
Generating XML Inputs
88112
---------------------
89113

0 commit comments

Comments
 (0)