From b9b88c17145d63bc7638dc8580b1abc168d2495f Mon Sep 17 00:00:00 2001 From: cgilet Date: Thu, 12 Sep 2024 11:54:44 +0200 Subject: [PATCH] Squashed commit of the following: commit d792c63027cc2f1ecf74d74a118802e262af1541 Author: Weiqun Zhang Date: Wed Sep 11 10:07:00 2024 -0500 Simplify cache cleanup actions (#129) In our old approach, a workflow file contains a job that uploads the PR number as an artifact. While the PR is still open, the workflow_run triggered by it will download the artifact and use the information to clean up all except the last used cache associated with that original workflow. When a PR is merged or closed, there will be a post-pr workflow that uploads the PR number as an artifact and triggers a workflow_run that clean up all caches associated with the PR. The reason we did it this way was in the cache cleanup workflows, we did not find an easy way to get the number of the PR triggering them. This is not convenient because we have to add jobs uploading artifacts to workflow files. After some experiments, we have found a reliable way to find the PR number without using artifacts. The workflow_run's payload always contains the head SHA of the commit that triggers it, whether the PR comes from a fork or not. We can then use `gh pr list` to search for that head and obtain the PR number. commit a007c21a941c5fe959e8f1de1b1d3b08fb970231 Author: Candace Gilet Date: Wed Sep 11 16:57:56 2024 +0200 Fix case of multiple tracers with default initial conditions. Issue (#132) introduced in PR#131 --- .github/workflows/cleanup-cache-postpr.yml | 16 +++++++++----- .github/workflows/cleanup-cache.yml | 25 ++++++++++++++-------- .github/workflows/cuda.yml | 15 ------------- .github/workflows/gcc.yml | 15 ------------- .github/workflows/hip.yml | 15 ------------- .github/workflows/post-pr.yml | 18 ++++++---------- .github/workflows/sycl.yml | 15 ------------- src/setup/init.cpp | 20 +++++++++-------- 8 files changed, 45 insertions(+), 94 deletions(-) diff --git a/.github/workflows/cleanup-cache-postpr.yml b/.github/workflows/cleanup-cache-postpr.yml index d352d47a9..5e9a70cd5 100644 --- a/.github/workflows/cleanup-cache-postpr.yml +++ b/.github/workflows/cleanup-cache-postpr.yml @@ -8,7 +8,7 @@ on: jobs: CleanUpCcacheCachePostPR: - name: Clean Up Ccahe Cache Post PR + name: Clean Up Ccache Cache Post PR runs-on: ubuntu-latest permissions: actions: write @@ -17,21 +17,27 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v4 - - name: Clean up ccahe + - 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` + # For debugging cat ${GITHUB_EVENT_PATH} to see the payload. + + pr_head_sha=${{ github.event.workflow_run.head_sha }} + pr_number=$(gh pr list --state all --search $pr_head_sha --json number --jq '.[0].number') + echo "Post-PR cache cleanup for PR ${pr_number}" 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 + 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 index 3448d88bc..41882334e 100644 --- a/.github/workflows/cleanup-cache.yml +++ b/.github/workflows/cleanup-cache.yml @@ -8,7 +8,7 @@ on: jobs: CleanUpCcacheCache: - name: Clean Up Ccahe Cache for ${{ github.event.workflow_run.name }} + name: Clean Up Ccache Cache for ${{ github.event.workflow_run.name }} runs-on: ubuntu-latest permissions: actions: write @@ -17,7 +17,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v4 - - name: Clean up ccahe + - name: Clean up ccache run: | gh extension install actions/gh-actions-cache @@ -27,11 +27,14 @@ jobs: EVENT=${{ github.event.workflow_run.event }} # Triggering workflow run name (e.g., LinuxClang) - WORKFLOW_NAME=${{ github.event.workflow_run.name }} + WORKFLOW_NAME="${{ github.event.workflow_run.name }}" + + # For debugging, cat ${GITHUB_EVENT_PATH} to see the payload. if [[ $EVENT == "pull_request" ]]; then - gh run download ${{ github.event.workflow_run.id }} -n pr_number - pr_number=`cat pr_number.txt` + pr_head_sha=${{ github.event.workflow_run.head_sha }} + pr_number=$(gh pr list --search $pr_head_sha --json number --jq '.[0].number') + echo "Clean up cache for PR ${pr_number}" BRANCH=refs/pull/${pr_number}/merge else BRANCH=refs/heads/${{ github.event.workflow_run.head_branch }} @@ -45,16 +48,20 @@ jobs: # The goal is to keep the last used key of each job and delete all others. # something like ccache-LinuxClang- - keyprefix=ccache-${WORKFLOW_NAME}- + 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=$(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) + # Delete all entries except the last used one + 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 + gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm done done + unset IFS diff --git a/.github/workflows/cuda.yml b/.github/workflows/cuda.yml index 0a0a7f3ed..460cee020 100644 --- a/.github/workflows/cuda.yml +++ b/.github/workflows/cuda.yml @@ -143,18 +143,3 @@ jobs: 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/gcc.yml b/.github/workflows/gcc.yml index cb539a9aa..808280bf0 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -322,18 +322,3 @@ jobs: export OMP_NUM_THREADS=2 cd ${{ github.workspace }}/incflo build/incflo.ex test_no_eb_2d/benchmark.bouss_bubble_god max_step=10 incflo.verbose=1 mac_proj.verbose=1 nodal_proj.verbose=1 - - 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 31d1b89f2..cce95161b 100644 --- a/.github/workflows/hip.yml +++ b/.github/workflows/hip.yml @@ -75,18 +75,3 @@ jobs: 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/post-pr.yml b/.github/workflows/post-pr.yml index 2768ef376..5f0b15349 100644 --- a/.github/workflows/post-pr.yml +++ b/.github/workflows/post-pr.yml @@ -4,17 +4,13 @@ on: types: - closed +# This workflow does not have the permission to clean up cache for PRs +# originated from a fork. The purpose here is to trigger a workflow_run +# cleanup-cache-postpr.yml that has the right permission. + jobs: - cleanup: + noop: 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 + - name: No OP + run: echo "This workflow is going to trigger CleanUpCachePostPR." diff --git a/.github/workflows/sycl.yml b/.github/workflows/sycl.yml index 678ac755f..d5c339801 100644 --- a/.github/workflows/sycl.yml +++ b/.github/workflows/sycl.yml @@ -74,18 +74,3 @@ jobs: 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/src/setup/init.cpp b/src/setup/init.cpp index c3ce88477..8325201bd 100644 --- a/src/setup/init.cpp +++ b/src/setup/init.cpp @@ -123,13 +123,23 @@ void incflo::ReadParameters () amrex::Abort("We currently require cfl <= 1.0 when using this advection scheme"); } + pp.query("ntrac", m_ntrac); + + if (m_ntrac <= 0) m_advect_tracer = false; + + if (m_ntrac < 1) { + amrex::Abort("We currently require at least one tracer"); + } + // Initial conditions pp.query("probtype", m_probtype); pp.query("ic_u", m_ic_u); pp.query("ic_v", m_ic_v); pp.query("ic_w", m_ic_w); pp.query("ic_p", m_ic_p); - pp.queryarr("ic_t", m_ic_t); + if ( !pp.queryarr("ic_t", m_ic_t, 0, m_ntrac) ) { + m_ic_t.resize(m_ntrac, 0.); + } // Viscosity (if constant) pp.query("mu", m_mu); @@ -138,14 +148,6 @@ void incflo::ReadParameters () pp.query("ro_0", m_ro_0); AMREX_ALWAYS_ASSERT(m_ro_0 >= 0.0); - pp.query("ntrac", m_ntrac); - - if (m_ntrac <= 0) m_advect_tracer = false; - - if (m_ntrac < 1) { - amrex::Abort("We currently require at least one tracer"); - } - // Scalar diffusion coefficients m_mu_s.resize(m_ntrac, 0.0); pp.queryarr("mu_s", m_mu_s, 0, m_ntrac );