Improved gh action #1
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
| name: Build and Test (Ubuntu 22.04) | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build: | |
| if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'Pull Request - Ready for CI') | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| contents: read | |
| issues: read | |
| checks: write | |
| pull-requests: write | |
| env: | |
| OPENSTUDIO_BUILD_NAME: OS-build-release-v2 | |
| MAX_SAFE_THREADS: $(( ($(nproc) * 80 + 50) / 100 )) | |
| CMAKE_CXX_COMPILER_LAUNCHER: ccache | |
| MAKEFLAGS: "-j$(( ($(nproc) * 80 + 50) / 100 ))" | |
| container: # Define the Docker container for the job. All subsequent steps run inside it. | |
| image: kuangwenyi/openstudio-cmake-tools:jammy | |
| options: -u root -e "LANG=en_US.UTF-8" # These options are passed to the 'docker run' command internally | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history for all branches and tags | |
| - name: Clean workspace | |
| run: | | |
| # make safe repository | |
| git config --global --add safe.directory /__w/OpenStudio/OpenStudio | |
| git clean -fdx | |
| - name: Install ccache | |
| run: | | |
| # Fix Kitware GPG key issue | |
| wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null | |
| echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu jammy main' | tee /etc/apt/sources.list.d/kitware.list >/dev/null | |
| apt-get update && apt-get install -y ccache | |
| - name: Set default compiler | |
| run: | | |
| update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 --slave /usr/bin/g++ g++ /usr/bin/g++-11 | |
| update-alternatives --set gcc /usr/bin/gcc-11 | |
| - name: Cache ccache | |
| uses: actions/cache@v4 | |
| with: | |
| path: /root/.ccache | |
| key: ${{ runner.os }}-ccache-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-ccache- | |
| - name: Cache Conan packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: /github/home/.conan2 | |
| key: ${{ runner.os }}-conan-${{ hashFiles('**/conanfile.py') }} | |
| restore-keys: | | |
| ${{ runner.os }}-conan- | |
| - name: Cache build directory | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.OPENSTUDIO_BUILD_NAME }} | |
| key: ${{ runner.os }}-build-${{ github.head_ref || github.ref_name }}-${{ hashFiles('**/*.cpp', '**/*.hpp', '**/CMakeLists.txt', 'src/**/*', 'conanfile.py') }} | |
| restore-keys: | | |
| ${{ runner.os }}-build-${{ github.head_ref || github.ref_name }}- | |
| ${{ runner.os }}-build- | |
| - name: Create build directory | |
| run: mkdir -p ${{ env.OPENSTUDIO_BUILD_NAME }} | |
| - name: Install dependencies | |
| run: | | |
| conan remote add conancenter https://center.conan.io --force | |
| conan remote add nrel-v2 https://conan.openstudio.net/artifactory/api/conan/conan-v2 --force | |
| if [ ! -f "/github/home/.conan2/profiles/default" ]; then | |
| conan profile detect | |
| fi | |
| conan install . --output-folder=${{ env.OPENSTUDIO_BUILD_NAME }} --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja -s compiler.cppstd=20 -s build_type=Release | |
| - name: Configure with CMake | |
| working-directory: ${{ env.OPENSTUDIO_BUILD_NAME }} | |
| run: | | |
| . ./conanbuild.sh | |
| cmake -G Ninja \ | |
| -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake \ | |
| -DCMAKE_BUILD_TYPE:STRING=Release \ | |
| -DBUILD_TESTING:BOOL=ON \ | |
| -DCPACK_BINARY_DEB:BOOL=ON \ | |
| -DCPACK_BINARY_TGZ:BOOL=ON \ | |
| -DCPACK_BINARY_IFW:BOOL=OFF \ | |
| -DCPACK_BINARY_NSIS:BOOL=OFF \ | |
| -DCPACK_BINARY_RPM:BOOL=OFF \ | |
| -DCPACK_BINARY_STGZ:BOOL=OFF \ | |
| -DCPACK_BINARY_TBZ2:BOOL=OFF \ | |
| -DCPACK_BINARY_TXZ:BOOL=OFF \ | |
| -DCPACK_BINARY_TZ:BOOL=OFF \ | |
| -DBUILD_PYTHON_BINDINGS:BOOL=ON \ | |
| -DBUILD_PYTHON_PIP_PACKAGE:BOOL=OFF \ | |
| -DPYTHON_VERSION:STRING=3.12.2 \ | |
| -DBUILD_RUBY_BINDINGS:BOOL=ON \ | |
| -DBUILD_CLI:BOOL=ON \ | |
| .. | |
| - name: Build with Ninja | |
| working-directory: ${{ env.OPENSTUDIO_BUILD_NAME }} | |
| run: | | |
| . ./conanbuild.sh | |
| ninja -j ${{ env.MAX_SAFE_THREADS }} package | |
| - name: Run CTests with enhanced error handling | |
| working-directory: ${{ env.OPENSTUDIO_BUILD_NAME }} | |
| run: | | |
| set +e # Don't exit on first failure | |
| mkdir -p Testing/run{1,2,3} | |
| echo "Starting first test run..." | |
| ctest -j ${{ env.MAX_SAFE_THREADS }} --no-compress-output --output-on-failure --output-junit Testing/run1/results.xml | |
| RESULT1=$? | |
| if [ $RESULT1 -ne 0 ]; then | |
| echo "First test run failed (exit code: $RESULT1), retrying failed tests..." | |
| ctest -j ${{ env.MAX_SAFE_THREADS }} --rerun-failed --no-compress-output --output-on-failure --output-junit Testing/run2/results.xml | |
| RESULT2=$? | |
| if [ $RESULT2 -ne 0 ]; then | |
| echo "Second test run failed (exit code: $RESULT2), final attempt with verbose output..." | |
| ctest -j ${{ env.MAX_SAFE_THREADS }} --rerun-failed --no-compress-output -VV --output-junit Testing/run3/results.xml | |
| RESULT3=$? | |
| else | |
| RESULT3=0 | |
| fi | |
| else | |
| echo "First test run passed" | |
| RESULT2=0 | |
| RESULT3=0 | |
| fi | |
| # Report results | |
| echo "Test run results: Run1=$RESULT1, Run2=$RESULT2, Run3=$RESULT3" | |
| # Set job status based on results | |
| if [ $RESULT1 -eq 0 ] || [ $RESULT2 -eq 0 ] || [ $RESULT3 -eq 0 ]; then | |
| echo "Tests passed (some may have required retries)" | |
| exit 0 | |
| else | |
| echo "All test attempts failed" | |
| exit 1 | |
| fi | |
| continue-on-error: true | |
| - name: Test Summary | |
| uses: test-summary/action@v2 | |
| with: | |
| paths: "${{ env.OPENSTUDIO_BUILD_NAME }}/Testing/run*/results.xml" # Path to your JUnit output file | |
| output: "${{ env.OPENSTUDIO_BUILD_NAME }}/Testing/test-summary.md" | |
| if: always() | |
| - name: Upload test summary | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-summary | |
| path: ${{ env.OPENSTUDIO_BUILD_NAME }}/Testing/test-summary.md | |
| if: always() | |
| - name: Upload build artifacts with metadata | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ubuntu-2204-${{ github.head_ref || github.ref_name }}-${{ github.sha }} | |
| path: | | |
| ${{ env.OPENSTUDIO_BUILD_NAME }}/*.deb | |
| ${{ env.OPENSTUDIO_BUILD_NAME }}/_CPack_Packages/Linux/TGZ/*.tar.gz | |
| retention-days: 30 | |
| if: always() |