-
Notifications
You must be signed in to change notification settings - Fork 20
Containerize CAM-SIMA unit tests and clean up CI infrastructure #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kuanchihwang
merged 17 commits into
ESCOMP:development
from
kuanchihwang:staging/containerize-cam-sima-ftn-ci
Jul 17, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ab0d1fe
Clean up stale and unused test infrastructure
kuanchihwang 4ee2923
Migrate lightweight CI jobs to run on `ubuntu-slim`
kuanchihwang e7fd08a
Update GitHub actions to latest versions
kuanchihwang f29fb02
Break long commands into separate lines for better readability
kuanchihwang dc26af4
Rearrange YAML keys for better readability
kuanchihwang 43b9b77
Update container image version
kuanchihwang 88d3377
Rename CI workflow for better organization and future expansion
kuanchihwang 5604dad
Standardize workflow-level CI configuration between CAM-SIMA and MPAS…
kuanchihwang fa49f23
Standardize job-level CI configuration between CAM-SIMA and MPAS dycore
kuanchihwang aa86e62
Containerize CAM-SIMA unit tests
kuanchihwang dbf8f82
Add conditional check to CAM-SIMA Fortran CI for future expansion
kuanchihwang 9f3c095
Only set code coverage flags for GCC
kuanchihwang affd009
Work around Intel compiler issue
kuanchihwang 22f6be8
Remove hard-coded include paths from unit test build infrastructure
kuanchihwang 7475480
Merge branch 'development' into develop/containerize-cam-sima-ftn-ci
kuanchihwang 6448f6b
Merge branch 'development' into develop/containerize-cam-sima-ftn-ci
kuanchihwang d7d7505
Merge branch 'development' into develop/containerize-cam-sima-ftn-ci
kuanchihwang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,300 @@ | ||
| name: CAM-SIMA Fortran CI | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
| push: | ||
| branches: | ||
| - staging/** | ||
| - development | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| cancel-in-progress: true | ||
| group: ${{ github.workflow }} - ${{ github.ref }} | ||
|
|
||
| jobs: | ||
| # This check is the stepped leader to determine if the rest of jobs should run. We unfortunately cannot use path filtering | ||
| # due to the peculiar limitations of GitHub Actions, quoted below for reference: | ||
| # | ||
| # "If a workflow is skipped due to path filtering, then checks associated with that workflow will remain in a "Pending" state. | ||
| # A pull request that requires those checks to be successful will be blocked from merging." | ||
| conditional-check: | ||
| name: Check if jobs should run | ||
| runs-on: ubuntu-slim | ||
| outputs: | ||
| should-run: ${{ steps.conditional.outputs.result }} | ||
| timeout-minutes: 1 | ||
| steps: | ||
| - name: Checkout CAM-SIMA | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Check if there are changes to Fortran source code | ||
| id: conditional | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| write_result_and_exit() { | ||
| case "$1" in | ||
| false) | ||
| echo "Result: Skip jobs." | ||
| echo "result=$1" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| ;; | ||
| true) | ||
| echo "Result: Run jobs." | ||
| echo "result=$1" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| ;; | ||
| error|*) | ||
| echo "Error occurred!" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| case "${{ github.event_name }}" in | ||
| pull_request) | ||
| echo "Event is pull request." | ||
|
|
||
| HEAD_COMMIT="${{ github.sha }}" | ||
|
|
||
| if [ -z "$HEAD_COMMIT" ]; then | ||
| echo "HEAD_COMMIT is empty." | ||
| write_result_and_exit false | ||
| fi | ||
|
|
||
| echo "Fetching $HEAD_COMMIT with parents..." | ||
| git fetch --depth=2 origin "$HEAD_COMMIT" || write_result_and_exit error | ||
|
|
||
| BASE_COMMIT="$(git rev-parse $HEAD_COMMIT^1)" || write_result_and_exit error | ||
| ;; | ||
| push) | ||
| echo "Event is push." | ||
|
|
||
| BASE_COMMIT="${{ github.event.before }}" | ||
| HEAD_COMMIT="${{ github.event.after }}" | ||
|
|
||
| if [ -z "$BASE_COMMIT" ] || [ -z "$HEAD_COMMIT" ]; then | ||
| echo "BASE_COMMIT or HEAD_COMMIT is empty." | ||
| write_result_and_exit false | ||
| fi | ||
|
|
||
| if [ -z "${BASE_COMMIT//0/}" ] || [ -z "${HEAD_COMMIT//0/}" ]; then | ||
| echo "BASE_COMMIT or HEAD_COMMIT is null." | ||
| write_result_and_exit false | ||
| fi | ||
|
|
||
| echo "Fetching $BASE_COMMIT..." | ||
| git fetch --depth=1 origin "$BASE_COMMIT" || write_result_and_exit error | ||
|
|
||
| echo "Fetching $HEAD_COMMIT..." | ||
| git fetch --depth=1 origin "$HEAD_COMMIT" || write_result_and_exit error | ||
| ;; | ||
| workflow_dispatch) | ||
| echo "Event is workflow dispatch." | ||
|
|
||
| # Always run jobs when triggered manually. | ||
| write_result_and_exit true | ||
| ;; | ||
| *) | ||
| echo "Event is unknown." | ||
|
|
||
| # Always skip jobs for any other events. | ||
| write_result_and_exit false | ||
| ;; | ||
| esac | ||
|
|
||
| echo "Finding changed paths between $BASE_COMMIT..$HEAD_COMMIT..." | ||
| git diff --name-only "$BASE_COMMIT..$HEAD_COMMIT" | tee changed-paths.txt || write_result_and_exit error | ||
|
|
||
| if grep -E -q '(^\.github\/workflows\/cam_sima_fortran_ci\.yml$|^share$|^src\/.+$|^test\/unit\/.+$)' changed-paths.txt; then | ||
| write_result_and_exit true | ||
| else | ||
| write_result_and_exit false | ||
| fi | ||
| # This job evaluates the overall status of CAM-SIMA Fortran CI for the purpose of inclusion as a required status check. | ||
| # It exists solely due to, again, the peculiar limitations of GitHub Actions, quoted below for reference: | ||
| # | ||
| # "The `jobs.<job_id>.if` conditional is evaluated before `jobs.<job_id>.strategy.matrix` is applied." This implies that | ||
| # when a matrix job is set as a required status check, skipping it due to the conditional will cause a pull request to be | ||
| # blocked from merging. | ||
| overall-status: | ||
| name: Overall status (CAM-SIMA Fortran CI) | ||
| needs: | ||
| - conditional-check | ||
| - unit-tests | ||
| if: ${{ always() }} | ||
| runs-on: ubuntu-slim | ||
| timeout-minutes: 1 | ||
| steps: | ||
| - name: Evaluate overall status | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| write_result_and_exit() { | ||
| case "$1" in | ||
| false) | ||
| echo "Result: Failure." | ||
| exit 1 | ||
| ;; | ||
| true) | ||
| echo "Result: Success." | ||
| exit 0 | ||
| ;; | ||
| error|*) | ||
| echo "Error occurred!" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| case "${{ needs.conditional-check.result }}" in | ||
| success) | ||
| : | ||
| ;; | ||
| cancelled|failure|skipped) | ||
| write_result_and_exit false | ||
| ;; | ||
| *) | ||
| write_result_and_exit error | ||
| ;; | ||
| esac | ||
|
|
||
| case "${{ needs.unit-tests.result }}" in | ||
| skipped|success) | ||
| : | ||
| ;; | ||
| cancelled|failure) | ||
| write_result_and_exit false | ||
| ;; | ||
| *) | ||
| write_result_and_exit error | ||
| ;; | ||
| esac | ||
|
|
||
| write_result_and_exit true | ||
| unit-tests: | ||
| name: Build and run unit tests (${{ matrix.compiler }}) | ||
| needs: conditional-check | ||
| if: ${{ needs.conditional-check.outputs.should-run == 'true' }} | ||
| runs-on: ubuntu-24.04 | ||
| container: | ||
| image: ghcr.io/kuanchihwang/atm-sci-container:2026-06-12_${{ matrix.compiler }}_${{ matrix.mpi }} | ||
| env: | ||
| CONTAINER_PRESET: cesm | ||
| CONTAINER_ENVIRONMENT: pfunit | ||
| RRTMGP_DATA_REFERENCE: v1.9 | ||
| UNIT_TESTS_BUILD_TYPE: Debug | ||
| UNIT_TESTS_PATH: ${{ github.workspace }}/test/unit/fortran | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| compiler: | ||
| - gnu-11 | ||
| - gnu-12 | ||
| - gnu-13 | ||
| - gnu-14 | ||
| - gnu-15 | ||
| - intel-2024 | ||
| - intel-2025 | ||
| # Uncomment the following lines to test with more MPI implementations. Currently only `open-mpi-5` | ||
| # (Open MPI 5.0.x series) is enabled. We may expand this matrix as our test coverage grows in the future. | ||
| mpi: | ||
| # - mpich-4 | ||
| # - open-mpi-4 | ||
| - open-mpi-5 | ||
| # include: | ||
| # - compiler: intel-2024 | ||
| # mpi: intel-mpi | ||
| # - compiler: intel-2025 | ||
| # mpi: intel-mpi | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - name: Checkout CAM-SIMA | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Checkout dependencies | ||
| run: | | ||
| ./bin/git-fleximod update ncar-physics share | ||
|
|
||
| - name: Checkout rrtmgp-data for PIO file reader tests | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| repository: earth-system-radiation/rrtmgp-data | ||
| ref: ${{ env.RRTMGP_DATA_REFERENCE }} | ||
| path: ${{ env.UNIT_TESTS_PATH }}/rrtmgp-data | ||
|
|
||
| - name: Build unit tests | ||
| run: | | ||
| source "$(command -v container-entrypoint-hook.sh)" | ||
| cmake \ | ||
| -D CMAKE_BUILD_TYPE="$UNIT_TESTS_BUILD_TYPE" \ | ||
| -D CAM_SIMA_ENABLE_CODE_COVERAGE=ON \ | ||
| -D CAM_SIMA_ENABLE_IO_TESTS=ON \ | ||
| -D CAM_SIMA_ENABLE_TESTS=ON \ | ||
| -B "$UNIT_TESTS_PATH/build" \ | ||
| -S "$UNIT_TESTS_PATH" | ||
| cmake \ | ||
| --build "$UNIT_TESTS_PATH/build" \ | ||
| --config "$UNIT_TESTS_BUILD_TYPE" | ||
|
|
||
| - name: Run unit tests | ||
| run: | | ||
| source "$(command -v container-entrypoint-hook.sh)" | ||
| ctest \ | ||
| --build-config "$UNIT_TESTS_BUILD_TYPE" \ | ||
| --output-junit "$UNIT_TESTS_PATH/build/unit-tests.xml" \ | ||
| --output-on-failure \ | ||
| --test-dir "$UNIT_TESTS_PATH/build" \ | ||
| --test-output-size-failed 524288 \ | ||
| --test-output-size-passed 524288 \ | ||
| --verbose | ||
|
|
||
| - name: Upload unit test results | ||
| if: ${{ always() }} | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| if-no-files-found: ignore | ||
| name: unit-tests-xml-${{ matrix.compiler }} | ||
| path: ${{ env.UNIT_TESTS_PATH }}/build/unit-tests.xml | ||
| retention-days: 7 | ||
|
|
||
| # Code coverage analysis only works reliably with the GNU Compiler Collection. | ||
| # Do it only with the latest version to save CI time. | ||
|
|
||
| - name: Install Gcovr | ||
| if: ${{ matrix.compiler == 'gnu-15' }} | ||
| run: | | ||
| python3 -m venv venv-gcovr | ||
| source venv-gcovr/bin/activate | ||
| python3 -m pip install --upgrade pip | ||
| python3 -m pip install gcovr | ||
|
|
||
| - name: Run Gcovr | ||
| if: ${{ matrix.compiler == 'gnu-15' }} | ||
| run: | | ||
| source venv-gcovr/bin/activate | ||
| export SOURCE_PATH="$PWD" | ||
| cd "$UNIT_TESTS_PATH/build" | ||
| gcovr \ | ||
| --filter "$SOURCE_PATH/src" \ | ||
| --html code-coverage.html \ | ||
| --root "$SOURCE_PATH" \ | ||
| --verbose \ | ||
| . | ||
|
|
||
| - name: Upload code coverage results | ||
| if: ${{ always() && matrix.compiler == 'gnu-15' }} | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| if-no-files-found: ignore | ||
| name: code-coverage-html | ||
| path: ${{ env.UNIT_TESTS_PATH }}/build/code-coverage.html | ||
| retention-days: 7 | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.