From 9e93bf8428f5b5417f104a62a38555386de99da4 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 18 Jun 2024 21:55:52 -0700 Subject: [PATCH] Update CI * Bump up actions' version * Use ccache and github cache --- .github/workflows/c-linter.yml | 4 +- .github/workflows/ci.yml | 41 ++++++++++++-- .github/workflows/cleanup-cache-postpr.yml | 40 ++++++++++++++ .github/workflows/cleanup-cache.yml | 63 ++++++++++++++++++++++ .github/workflows/cuda-ci.yml | 36 ++++++++++++- .github/workflows/docs.yml | 2 +- .github/workflows/gcc.yml | 37 ++++++++++++- .github/workflows/hip.yml | 40 ++++++++++++-- .github/workflows/macos.yml | 35 +++++++++++- .github/workflows/post-pr.yml | 20 +++++++ .github/workflows/style.yml | 4 +- .github/workflows/sycl.yml | 40 +++++++++++++- .github/workflows/windows.yml | 2 +- 13 files changed, 347 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/cleanup-cache-postpr.yml create mode 100644 .github/workflows/cleanup-cache.yml create mode 100644 .github/workflows/post-pr.yml diff --git a/.github/workflows/c-linter.yml b/.github/workflows/c-linter.yml index 179e0f98..2a7d447b 100644 --- a/.github/workflows/c-linter.yml +++ b/.github/workflows/c-linter.yml @@ -5,7 +5,7 @@ jobs: cpp-linter: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true @@ -30,7 +30,7 @@ jobs: run: python3 Submodules/cpp-linter-action/run_on_changed_files.py ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -header-filter=Source/ -ignore-files="AMReX|GoogleTest" -run-linter - name: Archive clang tidy report - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v4 with: name: clang-tidy-report path: clang-tidy-report.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aff4f6b8..9859100f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true @@ -39,12 +39,24 @@ jobs: # Install MPI ${{matrix.install_deps}} + - name: Install CCache + run: Submodules/AMReX/.github/workflows/dependencies/dependencies_ccache.sh + + - name: Set Up Cache + uses: actions/cache@v4 + with: + path: ~/.cache/ccache + key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }} + restore-keys: | + ccache-${{ github.workflow }}-${{ github.job }}-git- + - name: Configure CMake run: | cmake \ -B${{runner.workspace}}/REMORA/build-${{matrix.os}} \ -DCMAKE_INSTALL_PREFIX:PATH=${{runner.workspace}}/REMORA/install \ -DCMAKE_BUILD_TYPE:STRING=Debug \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DREMORA_DIM:STRING=3 \ -DREMORA_ENABLE_MPI:BOOL=ON \ -DREMORA_ENABLE_TESTS:BOOL=ON \ @@ -56,8 +68,16 @@ jobs: - name: Build run: | + export CCACHE_COMPRESS=1 + export CCACHE_COMPRESSLEVEL=10 + export CCACHE_MAXSIZE=600M + ccache -z + cmake --build ${{runner.workspace}}/REMORA/build-${{matrix.os}} --parallel ${{env.NPROCS}}; + ccache -s + du -hs ~/.cache/ccache + - name: Regression Tests run: | ctest -L regression -VV @@ -74,16 +94,31 @@ jobs: # cd .. # gcovr -g -k -r . --xml regressioncov.html # -v # - name: Success artifacts - # uses: actions/upload-artifact@v3 + # uses: actions/upload-artifact@v4 # if: success() # with: # name: build-and-test # path: | # ${{runner.workspace}}/REMORA/regressioncov.html # - name: Failing test artifacts - # uses: actions/upload-artifact@v3 + # uses: actions/upload-artifact@v4 # if: failure() # with: # name: build-and-test # path: | # ${{runner.workspace}}/REMORA/regressioncov.html + + save_pr_number: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: Save PR number + env: + PR_NUMBER: ${{ github.event.number }} + run: | + echo $PR_NUMBER > pr_number.txt + - uses: actions/upload-artifact@v4 + with: + name: pr_number + path: pr_number.txt + retention-days: 1 diff --git a/.github/workflows/cleanup-cache-postpr.yml b/.github/workflows/cleanup-cache-postpr.yml new file mode 100644 index 00000000..9a2ffb0f --- /dev/null +++ b/.github/workflows/cleanup-cache-postpr.yml @@ -0,0 +1,40 @@ +name: CleanUpCachePostPR + +on: + workflow_run: + workflows: [PostPR] + types: + - completed + +jobs: + CleanUpCcacheCachePostPR: + name: Clean Up Ccache Cache Post PR + runs-on: ubuntu-latest + permissions: + actions: write + contents: read + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + - name: Clean up ccache + run: | + gh extension install actions/gh-actions-cache + + REPO=${{ github.repository }} + + gh run download ${{ github.event.workflow_run.id }} -n pr_number + pr_number=`cat pr_number.txt` + BRANCH=refs/pull/${pr_number}/merge + + # Setting this to not fail the workflow while deleting cache keys. + set +e + + keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH | cut -f 1) + # $keys might contain spaces. Thus we set IFS to \n. + IFS=$'\n' + for k in $keys + do + gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm + done + unset IFS diff --git a/.github/workflows/cleanup-cache.yml b/.github/workflows/cleanup-cache.yml new file mode 100644 index 00000000..3cf2c548 --- /dev/null +++ b/.github/workflows/cleanup-cache.yml @@ -0,0 +1,63 @@ +name: CleanUpCache + +on: + workflow_run: + workflows: [REMORA CI, REMORA CUDA CI, REMORA CI (hip), REMORA CI (sycl), Linux GCC, MacOS] + types: + - completed + +jobs: + CleanUpCcacheCache: + name: Clean Up Ccache Cache for ${{ github.event.workflow_run.name }} + runs-on: ubuntu-latest + permissions: + actions: write + contents: read + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + - name: Clean up ccache + run: | + gh extension install actions/gh-actions-cache + + REPO=${{ github.repository }} + + # push or pull_request or schedule or ... + EVENT=${{ github.event.workflow_run.event }} + + # Triggering workflow run name (e.g., LinuxClang) + WORKFLOW_NAME="${{ github.event.workflow_run.name }}" + + if [[ $EVENT == "pull_request" ]]; then + gh run download ${{ github.event.workflow_run.id }} -n pr_number + pr_number=`cat pr_number.txt` + BRANCH=refs/pull/${pr_number}/merge + else + BRANCH=refs/heads/${{ github.event.workflow_run.head_branch }} + fi + + # Setting this to not fail the workflow while deleting cache keys. + set +e + + # In our cache keys, substring after `-git-` is git hash, substring + # before that is a unique id for jobs (e.g., `ccache-LinuxClang-configure-2d`). + # The goal is to keep the last used key of each job and delete all others. + + # something like ccache-LinuxClang- + keyprefix="ccache-${WORKFLOW_NAME}-" + + cached_jobs=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "$keyprefix" | awk -F '-git-' '{print $1}' | sort | uniq) + + # cached_jobs is something like "ccache-LinuxClang-configure-1d ccache-LinuxClang-configure-2d". + # It might also contain spaces. Thus we set IFS to \n. + IFS=$'\n' + for j in $cached_jobs + do + old_keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "${j}-git-" --sort last-used | cut -f 1 | tail -n +2) + for k in $old_keys + do + gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm + done + done + unset IFS diff --git a/.github/workflows/cuda-ci.yml b/.github/workflows/cuda-ci.yml index 0ef6f48f..9fc77e1d 100644 --- a/.github/workflows/cuda-ci.yml +++ b/.github/workflows/cuda-ci.yml @@ -23,21 +23,55 @@ jobs: uses: styfle/cancel-workflow-action@0.6.0 with: access_token: ${{github.token}} - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Prepare CUDA environment run: Submodules/AMReX/.github/workflows/dependencies/dependencies_nvcc.sh ${{matrix.cuda_ver}} + - name: Install CCache + run: Submodules/AMReX/.github/workflows/dependencies/dependencies_ccache.sh + - name: Set Up Cache + uses: actions/cache@v4 + with: + path: ~/.cache/ccache + key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }} + restore-keys: | + ccache-${{ github.workflow }}-${{ github.job }}-git- - name: Configure and build run: | + export CCACHE_COMPRESS=1 + export CCACHE_COMPRESSLEVEL=10 + export CCACHE_MAXSIZE=600M + ccache -z + export PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:/usr/local/cuda/lib64:${LD_LIBRARY_PATH} which nvcc || echo "nvcc not in PATH!" cmake -Bbuild-${{matrix.cuda_pkg}} \ -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache \ -DAMReX_CUDA_ERROR_CROSS_EXECUTION_SPACE_CALL=ON \ -DAMReX_CUDA_ERROR_CAPTURE_THIS=ON \ -DREMORA_DIM:STRING=3 \ -DREMORA_ENABLE_MPI:BOOL=OFF \ -DREMORA_ENABLE_CUDA:BOOL=ON . cmake --build build-${{matrix.cuda_pkg}} -- -j $(nproc) + + ccache -s + du -hs ~/.cache/ccache + + save_pr_number: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: Save PR number + env: + PR_NUMBER: ${{ github.event.number }} + run: | + echo $PR_NUMBER > pr_number.txt + - uses: actions/upload-artifact@v4 + with: + name: pr_number + path: pr_number.txt + retention-days: 1 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 1ecbfdfd..039c1059 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Dependencies run: | diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index d884a188..89a7d178 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -12,19 +12,36 @@ jobs: runs-on: ubuntu-20.04 # env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual"} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Install Dependencies run: Submodules/AMReX/.github/workflows/dependencies/dependencies.sh + - name: Install CCache + run: Submodules/AMReX/.github/workflows/dependencies/dependencies_ccache.sh + + - name: Set Up Cache + uses: actions/cache@v4 + with: + path: ~/.cache/ccache + key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }} + restore-keys: | + ccache-${{ github.workflow }}-${{ github.job }}-git- + - name: Configure Project and Generate Build System run: | + export CCACHE_COMPRESS=1 + export CCACHE_COMPRESSLEVEL=10 + export CCACHE_MAXSIZE=300M + ccache -z + cmake \ -B${{runner.workspace}}/REMORA/build \ -DCMAKE_INSTALL_PREFIX:PATH=${{runner.workspace}}/REMORA/install \ -DCMAKE_BUILD_TYPE:STRING=Debug \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DREMORA_DIM:STRING=3 \ -DREMORA_ENABLE_MPI:BOOL=ON \ -DREMORA_ENABLE_TESTS:BOOL=ON \ @@ -32,6 +49,9 @@ jobs: -DREMORA_ENABLE_FCOMPARE:BOOL=ON \ ${{github.workspace}}; + ccache -s + du -hs ~/.cache/ccache + - name: Compile and Link run: | cmake --build ${{runner.workspace}}/REMORA/build --parallel 2 --verbose @@ -40,3 +60,18 @@ jobs: run: | ctest -L regression -VV working-directory: ${{runner.workspace}}/REMORA/build + + save_pr_number: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: Save PR number + env: + PR_NUMBER: ${{ github.event.number }} + run: | + echo $PR_NUMBER > pr_number.txt + - uses: actions/upload-artifact@v4 + with: + name: pr_number + path: pr_number.txt + retention-days: 1 diff --git a/.github/workflows/hip.yml b/.github/workflows/hip.yml index 068a0739..a9a06fde 100644 --- a/.github/workflows/hip.yml +++ b/.github/workflows/hip.yml @@ -28,15 +28,31 @@ jobs: # NOTE: -Werror was removed because REMORA specifically had a lot of warnings. It will be a separate task to go through and fix them all... env: {CXXFLAGS: "-Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wno-deprecated-declarations -Wno-gnu-zero-variadic-macro-arguments -Wno-pass-failed"} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Dependencies run: Submodules/AMReX/.github/workflows/dependencies/dependencies_hip.sh + - name: Install CCache + run: Submodules/AMReX/.github/workflows/dependencies/dependencies_ccache.sh + + - name: Set Up Cache + uses: actions/cache@v4 + with: + path: ~/.cache/ccache + key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }} + restore-keys: | + ccache-${{ github.workflow }}-${{ github.job }}-git- + - name: Build & Install run: | + export CCACHE_COMPRESS=1 + export CCACHE_COMPRESSLEVEL=10 + export CCACHE_MAXSIZE=300M + ccache -z + source /etc/profile.d/rocm.sh hipcc --version which clang @@ -52,6 +68,7 @@ jobs: -DCMAKE_VERBOSE_MAKEFILE=ON \ -DCMAKE_INSTALL_PREFIX:PATH=${{runner.workspace}}/REMORA/install \ -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DREMORA_DIM:STRING=3 \ -DREMORA_ENABLE_MPI:BOOL=ON \ -DREMORA_ENABLE_HIP:BOOL=ON \ @@ -74,6 +91,9 @@ jobs: # make -j ${{env.NPROCS}}; make -j 2; + ccache -s + du -hs ~/.cache/ccache + # - name: Regression Tests # run: | # ctest -L regression -VV @@ -99,17 +119,31 @@ jobs: # directory: ${{runner.workspace}}/REMORA - name: Success artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: success() with: name: build-and-test path: | ${{runner.workspace}}/REMORA/regressioncov.xml - name: Failing test artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: failure() with: name: build-and-test path: | ${{runner.workspace}}/REMORA/regressioncov.xml + save_pr_number: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: Save PR number + env: + PR_NUMBER: ${{ github.event.number }} + run: | + echo $PR_NUMBER > pr_number.txt + - uses: actions/upload-artifact@v4 + with: + name: pr_number + path: pr_number.txt + retention-days: 1 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 8b2af2f2..fbd65c5c 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -12,13 +12,21 @@ jobs: runs-on: macos-latest # env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual"} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Install Dependencies run: Submodules/AMReX/.github/workflows/dependencies/dependencies_mac.sh + - name: Set Up Cache + uses: actions/cache@v4 + with: + path: ~/Library/Caches/ccache + key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }} + restore-keys: | + ccache-${{ github.workflow }}-${{ github.job }}-git- + - name: Configure Project and Generate Build System run: | cmake \ @@ -26,6 +34,7 @@ jobs: -DBUILD_SHARED_LIBS:BOOL=TRUE \ -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ -DCMAKE_BUILD_TYPE:STRING=Debug \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DREMORA_DIM:STRING=3 \ -DREMORA_ENABLE_MPI:BOOL=TRUE \ -DREMORA_ENABLE_TESTS:BOOL=TRUE \ @@ -35,9 +44,33 @@ jobs: - name: Compile and Link run: | + export CCACHE_COMPRESS=1 + export CCACHE_COMPRESSLEVEL=10 + export CCACHE_MAXSIZE=250M + export CCACHE_SLOPPINESS=time_macros + ccache -z + cmake --build ${{runner.workspace}}/REMORA/build --parallel 2 --verbose + du -hs ~/Library/Caches/ccache + ccache -s + - name: CMake Tests # see file REMORA/Tests/CTestList.cmake run: | ctest -L regression -VV working-directory: ${{runner.workspace}}/REMORA/build + + save_pr_number: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: Save PR number + env: + PR_NUMBER: ${{ github.event.number }} + run: | + echo $PR_NUMBER > pr_number.txt + - uses: actions/upload-artifact@v4 + with: + name: pr_number + path: pr_number.txt + retention-days: 1 diff --git a/.github/workflows/post-pr.yml b/.github/workflows/post-pr.yml new file mode 100644 index 00000000..2768ef37 --- /dev/null +++ b/.github/workflows/post-pr.yml @@ -0,0 +1,20 @@ +name: PostPR +on: + pull_request: + types: + - closed + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Save PR number + env: + PR_NUMBER: ${{ github.event.number }} + run: | + echo $PR_NUMBER > pr_number.txt + - uses: actions/upload-artifact@v4 + with: + name: pr_number + path: pr_number.txt + retention-days: 1 diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index c699f2a6..223ce0f6 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -10,13 +10,13 @@ jobs: tabs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Tabs run: .github/workflows/style/check_tabs.sh trailing_whitespaces: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Trailing Whitespaces run: .github/workflows/style/check_trailing_whitespaces.sh diff --git a/.github/workflows/sycl.yml b/.github/workflows/sycl.yml index e8d8ed75..9046421c 100644 --- a/.github/workflows/sycl.yml +++ b/.github/workflows/sycl.yml @@ -13,15 +13,32 @@ jobs: name: oneAPI SYCL runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Dependencies run: Submodules/AMReX/.github/workflows/dependencies/dependencies_dpcpp.sh + - name: Install CCache + run: Submodules/AMReX/.github/workflows/dependencies/dependencies_ccache.sh + + - name: Set Up Cache + uses: actions/cache@v4 + with: + path: ~/.cache/ccache + key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }} + restore-keys: | + ccache-${{ github.workflow }}-${{ github.job }}-git- + - name: Build run: | + export CCACHE_COMPRESS=1 + export CCACHE_COMPRESSLEVEL=10 + export CCACHE_MAXSIZE=250M + export CCACHE_DEPEND=1 + ccache -z + set +e source /opt/intel/oneapi/setvars.sh set -e @@ -31,6 +48,7 @@ jobs: -DCMAKE_VERBOSE_MAKEFILE=ON \ -DCMAKE_INSTALL_PREFIX:PATH=${{runner.workspace}}/REMORA/install \ -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DREMORA_DIM:STRING=3 \ -DREMORA_ENABLE_MPI:BOOL=ON \ -DREMORA_ENABLE_SYCL:BOOL=ON \ @@ -40,4 +58,22 @@ jobs: -DCMAKE_C_COMPILER=$(which icx) \ -DCMAKE_CXX_COMPILER=$(which icpx) \ -DCMAKE_CXX_STANDARD=17 - make -j 2; + make -j 2 + + ccache -s + du -hs ~/.cache/ccache + + save_pr_number: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: Save PR number + env: + PR_NUMBER: ${{ github.event.number }} + run: | + echo $PR_NUMBER > pr_number.txt + - uses: actions/upload-artifact@v4 + with: + name: pr_number + path: pr_number.txt + retention-days: 1 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 30d9d921..ee4f629b 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -11,7 +11,7 @@ jobs: name: WIN32 MSVC@19.29 runs-on: windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true