From dc894f743d6d564212640effa6f33209185c41a1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 17:21:05 +0000 Subject: [PATCH 01/12] Initial plan From 5e0ac239beb3d38b7ee574fe54404c9d7ee5e688 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 17:24:58 +0000 Subject: [PATCH 02/12] Add cleanup-buildcache workflow for PR close/merge Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com> --- .github/workflows/cleanup-buildcache.yml | 62 ++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/cleanup-buildcache.yml diff --git a/.github/workflows/cleanup-buildcache.yml b/.github/workflows/cleanup-buildcache.yml new file mode 100644 index 00000000..67a0426e --- /dev/null +++ b/.github/workflows/cleanup-buildcache.yml @@ -0,0 +1,62 @@ +name: Cleanup Buildcache + +on: + pull_request: + types: [closed] + branches: + - master + +permissions: + packages: write + +jobs: + cleanup-buildcache: + name: Cleanup buildcache for PR ${{ github.event.pull_request.number }} + runs-on: ubuntu-latest + steps: + - name: Cleanup buildcache tags from ghcr.io + env: + GH_TOKEN: ${{ secrets.GHCR_REGISTRY_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + # Delete buildcache tags for this PR from ghcr.io + # The buildcache image is at ghcr.io/eic/buildcache + # Tags follow the pattern: {BUILD_IMAGE}-{PR_NUMBER}-{arch} + + echo "Cleaning up buildcache tags for PR #${PR_NUMBER}" + + # List all versions of the buildcache package + echo "Fetching buildcache package versions..." + VERSIONS=$(gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/orgs/eic/packages/container/buildcache/versions?per_page=100" \ + --paginate \ + --jq '.[] | select(.metadata.container.tags[]? | contains("-'"${PR_NUMBER}"'-")) | .id') + + if [ -z "$VERSIONS" ]; then + echo "No buildcache versions found for PR #${PR_NUMBER}" + exit 0 + fi + + # Delete each matching version + echo "Found buildcache versions to delete:" + for version_id in $VERSIONS; do + # Get the tags for this version for logging + TAGS=$(gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/orgs/eic/packages/container/buildcache/versions/${version_id}" \ + --jq '.metadata.container.tags[]? | select(. != null)' 2>/dev/null | tr '\n' ',' | sed 's/,$//') + + echo " Deleting version ${version_id} with tags: ${TAGS}" + + gh api \ + --method DELETE \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/orgs/eic/packages/container/buildcache/versions/${version_id}" \ + || echo " Warning: Failed to delete version ${version_id}" + done + + echo "Buildcache cleanup completed for PR #${PR_NUMBER}" From cb82752f958ea2c426a7a2ab2994494fd1825003 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 17:27:39 +0000 Subject: [PATCH 03/12] Add eicweb registry cleanup and update documentation Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com> --- .github/workflows/cleanup-buildcache.yml | 93 ++++++++++++++++++------ docs/build-pipeline.md | 10 +++ 2 files changed, 80 insertions(+), 23 deletions(-) diff --git a/.github/workflows/cleanup-buildcache.yml b/.github/workflows/cleanup-buildcache.yml index 67a0426e..f3941cd8 100644 --- a/.github/workflows/cleanup-buildcache.yml +++ b/.github/workflows/cleanup-buildcache.yml @@ -23,7 +23,7 @@ jobs: # The buildcache image is at ghcr.io/eic/buildcache # Tags follow the pattern: {BUILD_IMAGE}-{PR_NUMBER}-{arch} - echo "Cleaning up buildcache tags for PR #${PR_NUMBER}" + echo "Cleaning up buildcache tags for PR #${PR_NUMBER} from ghcr.io" # List all versions of the buildcache package echo "Fetching buildcache package versions..." @@ -35,28 +35,75 @@ jobs: --jq '.[] | select(.metadata.container.tags[]? | contains("-'"${PR_NUMBER}"'-")) | .id') if [ -z "$VERSIONS" ]; then - echo "No buildcache versions found for PR #${PR_NUMBER}" + echo "No buildcache versions found for PR #${PR_NUMBER} in ghcr.io" + else + # Delete each matching version + echo "Found buildcache versions to delete from ghcr.io:" + for version_id in $VERSIONS; do + # Get the tags for this version for logging + TAGS=$(gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/orgs/eic/packages/container/buildcache/versions/${version_id}" \ + --jq '.metadata.container.tags[]? | select(. != null)' 2>/dev/null | tr '\n' ',' | sed 's/,$//') + + echo " Deleting version ${version_id} with tags: ${TAGS}" + + gh api \ + --method DELETE \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/orgs/eic/packages/container/buildcache/versions/${version_id}" \ + || echo " Warning: Failed to delete version ${version_id}" + done + fi + + echo "Buildcache cleanup from ghcr.io completed for PR #${PR_NUMBER}" + + - name: Cleanup buildcache tags from eicweb.phy.anl.gov + env: + GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + # Delete buildcache tags for this PR from eicweb.phy.anl.gov GitLab Container Registry + # The buildcache image is at eicweb.phy.anl.gov/containers/eic_container/buildcache + # Tags follow the pattern: {BUILD_IMAGE}-{PR_NUMBER}-{arch} + + echo "Cleaning up buildcache tags for PR #${PR_NUMBER} from eicweb.phy.anl.gov" + + GITLAB_API="https://eicweb.phy.anl.gov/api/v4" + PROJECT_ID="290" # containers/eic_container project ID + + # List all repository tags for the buildcache image + echo "Fetching buildcache repository tags..." + REPOSITORY_ID=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ + "${GITLAB_API}/projects/${PROJECT_ID}/registry/repositories" \ + | jq -r '.[] | select(.name == "buildcache") | .id') + + if [ -z "$REPOSITORY_ID" ]; then + echo "Warning: Could not find buildcache repository in GitLab registry" exit 0 fi - # Delete each matching version - echo "Found buildcache versions to delete:" - for version_id in $VERSIONS; do - # Get the tags for this version for logging - TAGS=$(gh api \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "/orgs/eic/packages/container/buildcache/versions/${version_id}" \ - --jq '.metadata.container.tags[]? | select(. != null)' 2>/dev/null | tr '\n' ',' | sed 's/,$//') - - echo " Deleting version ${version_id} with tags: ${TAGS}" - - gh api \ - --method DELETE \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "/orgs/eic/packages/container/buildcache/versions/${version_id}" \ - || echo " Warning: Failed to delete version ${version_id}" - done - - echo "Buildcache cleanup completed for PR #${PR_NUMBER}" + echo "Found buildcache repository ID: ${REPOSITORY_ID}" + + # Fetch all tags and filter for this PR + TAGS_TO_DELETE=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ + "${GITLAB_API}/projects/${PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags?per_page=100" \ + | jq -r '.[] | select(.name | contains("-'"${PR_NUMBER}"'-")) | .name') + + if [ -z "$TAGS_TO_DELETE" ]; then + echo "No buildcache tags found for PR #${PR_NUMBER} in eicweb.phy.anl.gov" + else + # Delete each matching tag + echo "Found buildcache tags to delete from eicweb.phy.anl.gov:" + for tag in $TAGS_TO_DELETE; do + echo " Deleting tag: ${tag}" + + curl -s -X DELETE --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ + "${GITLAB_API}/projects/${PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags/${tag}" \ + || echo " Warning: Failed to delete tag ${tag}" + done + fi + + echo "Buildcache cleanup from eicweb.phy.anl.gov completed for PR #${PR_NUMBER}" diff --git a/docs/build-pipeline.md b/docs/build-pipeline.md index 8d8a77d1..58cf66b5 100644 --- a/docs/build-pipeline.md +++ b/docs/build-pipeline.md @@ -130,6 +130,8 @@ cache-from: | cache-to: type=registry,ref=ghcr.io/eic/buildcache:{image}-{branch}-{arch},mode=max ``` +**Buildcache Cleanup**: When a pull request is closed or merged, the `cleanup-buildcache` workflow automatically removes all buildcache tags associated with that PR from both ghcr.io and eicweb.phy.anl.gov registries. This prevents buildcache accumulation and keeps the registries clean. + ### Build Mount Cache Uses [buildkit-cache-dance](https://github.com/reproducible-containers/buildkit-cache-dance) to persist mount caches: @@ -150,6 +152,8 @@ Pre-built binaries are stored in OCI registries: ## Workflow Triggers +### build-push workflow + | Trigger | Behavior | |---------|----------| | Schedule (cron) | Every 6 hours - nightly builds | @@ -157,6 +161,12 @@ Pre-built binaries are stored in OCI registries: | Pull Request | Build with `unstable-pr-*` tag | | Manual Dispatch | Allows overriding EDM4EIC, EICRECON, JUGGLER versions | +### cleanup-buildcache workflow + +| Trigger | Behavior | +|---------|----------| +| Pull Request closed | Automatically removes all buildcache tags for the PR from ghcr.io and eicweb.phy.anl.gov | + ## Environment Matrix The EIC job builds the following matrix: From 77ecd1cd7bd076eae169447d7550bbf9dffd4e60 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 17:29:13 +0000 Subject: [PATCH 04/12] Address code review feedback: use jq --arg and clarify variable names Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com> --- .github/workflows/cleanup-buildcache.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cleanup-buildcache.yml b/.github/workflows/cleanup-buildcache.yml index f3941cd8..ad080835 100644 --- a/.github/workflows/cleanup-buildcache.yml +++ b/.github/workflows/cleanup-buildcache.yml @@ -32,7 +32,7 @@ jobs: -H "X-GitHub-Api-Version: 2022-11-28" \ "/orgs/eic/packages/container/buildcache/versions?per_page=100" \ --paginate \ - --jq '.[] | select(.metadata.container.tags[]? | contains("-'"${PR_NUMBER}"'-")) | .id') + --jq --arg pr_num "${PR_NUMBER}" '.[] | select(.metadata.container.tags[]? | contains("-\($pr_num)-")) | .id') if [ -z "$VERSIONS" ]; then echo "No buildcache versions found for PR #${PR_NUMBER} in ghcr.io" @@ -72,12 +72,12 @@ jobs: echo "Cleaning up buildcache tags for PR #${PR_NUMBER} from eicweb.phy.anl.gov" GITLAB_API="https://eicweb.phy.anl.gov/api/v4" - PROJECT_ID="290" # containers/eic_container project ID + GITLAB_PROJECT_ID="290" # containers/eic_container project ID # List all repository tags for the buildcache image echo "Fetching buildcache repository tags..." REPOSITORY_ID=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ - "${GITLAB_API}/projects/${PROJECT_ID}/registry/repositories" \ + "${GITLAB_API}/projects/${GITLAB_PROJECT_ID}/registry/repositories" \ | jq -r '.[] | select(.name == "buildcache") | .id') if [ -z "$REPOSITORY_ID" ]; then @@ -89,8 +89,8 @@ jobs: # Fetch all tags and filter for this PR TAGS_TO_DELETE=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ - "${GITLAB_API}/projects/${PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags?per_page=100" \ - | jq -r '.[] | select(.name | contains("-'"${PR_NUMBER}"'-")) | .name') + "${GITLAB_API}/projects/${GITLAB_PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags?per_page=100" \ + | jq -r --arg pr_num "${PR_NUMBER}" '.[] | select(.name | contains("-\($pr_num)-")) | .name') if [ -z "$TAGS_TO_DELETE" ]; then echo "No buildcache tags found for PR #${PR_NUMBER} in eicweb.phy.anl.gov" @@ -101,7 +101,7 @@ jobs: echo " Deleting tag: ${tag}" curl -s -X DELETE --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ - "${GITLAB_API}/projects/${PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags/${tag}" \ + "${GITLAB_API}/projects/${GITLAB_PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags/${tag}" \ || echo " Warning: Failed to delete tag ${tag}" done fi From 3ab7b6e5688e3e60f2c2a603a6c53e9c93ac1e2f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 17:58:23 +0000 Subject: [PATCH 05/12] Use github-slug-action to ensure GITHUB_REF_POINT_SLUG is set Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com> --- .github/workflows/cleanup-buildcache.yml | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cleanup-buildcache.yml b/.github/workflows/cleanup-buildcache.yml index ad080835..c3777c4f 100644 --- a/.github/workflows/cleanup-buildcache.yml +++ b/.github/workflows/cleanup-buildcache.yml @@ -14,16 +14,20 @@ jobs: name: Cleanup buildcache for PR ${{ github.event.pull_request.number }} runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Inject enhanced GitHub environment variables + uses: rlespinasse/github-slug-action@v5 - name: Cleanup buildcache tags from ghcr.io env: GH_TOKEN: ${{ secrets.GHCR_REGISTRY_TOKEN }} - PR_NUMBER: ${{ github.event.pull_request.number }} run: | # Delete buildcache tags for this PR from ghcr.io # The buildcache image is at ghcr.io/eic/buildcache - # Tags follow the pattern: {BUILD_IMAGE}-{PR_NUMBER}-{arch} + # Tags follow the pattern: {BUILD_IMAGE}-{GITHUB_REF_POINT_SLUG}-{arch} + # For PRs, GITHUB_REF_POINT_SLUG is the PR number (e.g., "123") - echo "Cleaning up buildcache tags for PR #${PR_NUMBER} from ghcr.io" + echo "Cleaning up buildcache tags for PR #${GITHUB_REF_POINT_SLUG} from ghcr.io" # List all versions of the buildcache package echo "Fetching buildcache package versions..." @@ -32,10 +36,10 @@ jobs: -H "X-GitHub-Api-Version: 2022-11-28" \ "/orgs/eic/packages/container/buildcache/versions?per_page=100" \ --paginate \ - --jq --arg pr_num "${PR_NUMBER}" '.[] | select(.metadata.container.tags[]? | contains("-\($pr_num)-")) | .id') + --jq --arg pr_num "${GITHUB_REF_POINT_SLUG}" '.[] | select(.metadata.container.tags[]? | contains("-\($pr_num)-")) | .id') if [ -z "$VERSIONS" ]; then - echo "No buildcache versions found for PR #${PR_NUMBER} in ghcr.io" + echo "No buildcache versions found for PR #${GITHUB_REF_POINT_SLUG} in ghcr.io" else # Delete each matching version echo "Found buildcache versions to delete from ghcr.io:" @@ -58,18 +62,18 @@ jobs: done fi - echo "Buildcache cleanup from ghcr.io completed for PR #${PR_NUMBER}" + echo "Buildcache cleanup from ghcr.io completed for PR #${GITHUB_REF_POINT_SLUG}" - name: Cleanup buildcache tags from eicweb.phy.anl.gov env: GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} - PR_NUMBER: ${{ github.event.pull_request.number }} run: | # Delete buildcache tags for this PR from eicweb.phy.anl.gov GitLab Container Registry # The buildcache image is at eicweb.phy.anl.gov/containers/eic_container/buildcache - # Tags follow the pattern: {BUILD_IMAGE}-{PR_NUMBER}-{arch} + # Tags follow the pattern: {BUILD_IMAGE}-{GITHUB_REF_POINT_SLUG}-{arch} + # For PRs, GITHUB_REF_POINT_SLUG is the PR number (e.g., "123") - echo "Cleaning up buildcache tags for PR #${PR_NUMBER} from eicweb.phy.anl.gov" + echo "Cleaning up buildcache tags for PR #${GITHUB_REF_POINT_SLUG} from eicweb.phy.anl.gov" GITLAB_API="https://eicweb.phy.anl.gov/api/v4" GITLAB_PROJECT_ID="290" # containers/eic_container project ID @@ -90,10 +94,10 @@ jobs: # Fetch all tags and filter for this PR TAGS_TO_DELETE=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ "${GITLAB_API}/projects/${GITLAB_PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags?per_page=100" \ - | jq -r --arg pr_num "${PR_NUMBER}" '.[] | select(.name | contains("-\($pr_num)-")) | .name') + | jq -r --arg pr_num "${GITHUB_REF_POINT_SLUG}" '.[] | select(.name | contains("-\($pr_num)-")) | .name') if [ -z "$TAGS_TO_DELETE" ]; then - echo "No buildcache tags found for PR #${PR_NUMBER} in eicweb.phy.anl.gov" + echo "No buildcache tags found for PR #${GITHUB_REF_POINT_SLUG} in eicweb.phy.anl.gov" else # Delete each matching tag echo "Found buildcache tags to delete from eicweb.phy.anl.gov:" @@ -106,4 +110,4 @@ jobs: done fi - echo "Buildcache cleanup from eicweb.phy.anl.gov completed for PR #${PR_NUMBER}" + echo "Buildcache cleanup from eicweb.phy.anl.gov completed for PR #${GITHUB_REF_POINT_SLUG}" From 965704e3b548db28523e3537ca8c8a89b1a93a7f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 18:00:37 +0000 Subject: [PATCH 06/12] Clarify buildcache tag pattern documentation Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com> --- .github/workflows/cleanup-buildcache.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cleanup-buildcache.yml b/.github/workflows/cleanup-buildcache.yml index c3777c4f..ffc6a7f5 100644 --- a/.github/workflows/cleanup-buildcache.yml +++ b/.github/workflows/cleanup-buildcache.yml @@ -24,8 +24,11 @@ jobs: run: | # Delete buildcache tags for this PR from ghcr.io # The buildcache image is at ghcr.io/eic/buildcache - # Tags follow the pattern: {BUILD_IMAGE}-{GITHUB_REF_POINT_SLUG}-{arch} + # Tags follow patterns: + # - Base images: {BUILD_IMAGE}-{GITHUB_REF_POINT_SLUG}-{arch} + # - EIC images: {BUILD_IMAGE}{ENV}-{BUILD_TYPE}-{GITHUB_REF_POINT_SLUG}-{arch} # For PRs, GITHUB_REF_POINT_SLUG is the PR number (e.g., "123") + # The pattern contains("-{PR_NUM}-") matches both formats echo "Cleaning up buildcache tags for PR #${GITHUB_REF_POINT_SLUG} from ghcr.io" @@ -70,8 +73,11 @@ jobs: run: | # Delete buildcache tags for this PR from eicweb.phy.anl.gov GitLab Container Registry # The buildcache image is at eicweb.phy.anl.gov/containers/eic_container/buildcache - # Tags follow the pattern: {BUILD_IMAGE}-{GITHUB_REF_POINT_SLUG}-{arch} + # Tags follow patterns: + # - Base images: {BUILD_IMAGE}-{GITHUB_REF_POINT_SLUG}-{arch} + # - EIC images: {BUILD_IMAGE}{ENV}-{BUILD_TYPE}-{GITHUB_REF_POINT_SLUG}-{arch} # For PRs, GITHUB_REF_POINT_SLUG is the PR number (e.g., "123") + # The pattern contains("-{PR_NUM}-") matches both formats echo "Cleaning up buildcache tags for PR #${GITHUB_REF_POINT_SLUG} from eicweb.phy.anl.gov" From 26ae7adfc9a1a3ef52315d7fce0e4ef6f2dfa35f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 18:14:15 +0000 Subject: [PATCH 07/12] Fix: Use branch slug (GITHUB_REF_POINT_SLUG) and add workflow_dispatch Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com> --- .github/workflows/cleanup-buildcache.yml | 54 +++++++++++++++++------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/.github/workflows/cleanup-buildcache.yml b/.github/workflows/cleanup-buildcache.yml index ffc6a7f5..4769e261 100644 --- a/.github/workflows/cleanup-buildcache.yml +++ b/.github/workflows/cleanup-buildcache.yml @@ -5,32 +5,53 @@ on: types: [closed] branches: - master + workflow_dispatch: + inputs: + ref_slug: + description: 'Branch slug (GITHUB_REF_POINT_SLUG) to clean up' + required: true + type: string permissions: packages: write jobs: cleanup-buildcache: - name: Cleanup buildcache for PR ${{ github.event.pull_request.number }} + name: Cleanup buildcache for ${{ github.event.pull_request.number || inputs.ref_slug }} runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref || github.ref }} - name: Inject enhanced GitHub environment variables uses: rlespinasse/github-slug-action@v5 + - name: Set ref slug + id: ref_slug + run: | + # For workflow_dispatch, use the input value + # For pull_request, use the GITHUB_REF_POINT_SLUG set by slug action + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + REF_SLUG="${{ inputs.ref_slug }}" + else + REF_SLUG="${GITHUB_REF_POINT_SLUG}" + fi + echo "ref_slug=${REF_SLUG}" >> $GITHUB_OUTPUT + echo "Using ref slug: ${REF_SLUG}" - name: Cleanup buildcache tags from ghcr.io env: GH_TOKEN: ${{ secrets.GHCR_REGISTRY_TOKEN }} + REF_SLUG: ${{ steps.ref_slug.outputs.ref_slug }} run: | - # Delete buildcache tags for this PR from ghcr.io + # Delete buildcache tags for this branch from ghcr.io # The buildcache image is at ghcr.io/eic/buildcache # Tags follow patterns: # - Base images: {BUILD_IMAGE}-{GITHUB_REF_POINT_SLUG}-{arch} # - EIC images: {BUILD_IMAGE}{ENV}-{BUILD_TYPE}-{GITHUB_REF_POINT_SLUG}-{arch} - # For PRs, GITHUB_REF_POINT_SLUG is the PR number (e.g., "123") - # The pattern contains("-{PR_NUM}-") matches both formats + # GITHUB_REF_POINT_SLUG is derived from the branch name (e.g., "my-feature" for branch "my-feature") + # The pattern contains("-{REF_SLUG}-") matches both formats - echo "Cleaning up buildcache tags for PR #${GITHUB_REF_POINT_SLUG} from ghcr.io" + echo "Cleaning up buildcache tags for branch slug '${REF_SLUG}' from ghcr.io" # List all versions of the buildcache package echo "Fetching buildcache package versions..." @@ -39,10 +60,10 @@ jobs: -H "X-GitHub-Api-Version: 2022-11-28" \ "/orgs/eic/packages/container/buildcache/versions?per_page=100" \ --paginate \ - --jq --arg pr_num "${GITHUB_REF_POINT_SLUG}" '.[] | select(.metadata.container.tags[]? | contains("-\($pr_num)-")) | .id') + --jq --arg ref_slug "${REF_SLUG}" '.[] | select(.metadata.container.tags[]? | contains("-\($ref_slug)-")) | .id') if [ -z "$VERSIONS" ]; then - echo "No buildcache versions found for PR #${GITHUB_REF_POINT_SLUG} in ghcr.io" + echo "No buildcache versions found for branch slug '${REF_SLUG}' in ghcr.io" else # Delete each matching version echo "Found buildcache versions to delete from ghcr.io:" @@ -65,21 +86,22 @@ jobs: done fi - echo "Buildcache cleanup from ghcr.io completed for PR #${GITHUB_REF_POINT_SLUG}" + echo "Buildcache cleanup from ghcr.io completed for branch slug '${REF_SLUG}'" - name: Cleanup buildcache tags from eicweb.phy.anl.gov env: GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} + REF_SLUG: ${{ steps.ref_slug.outputs.ref_slug }} run: | - # Delete buildcache tags for this PR from eicweb.phy.anl.gov GitLab Container Registry + # Delete buildcache tags for this branch from eicweb.phy.anl.gov GitLab Container Registry # The buildcache image is at eicweb.phy.anl.gov/containers/eic_container/buildcache # Tags follow patterns: # - Base images: {BUILD_IMAGE}-{GITHUB_REF_POINT_SLUG}-{arch} # - EIC images: {BUILD_IMAGE}{ENV}-{BUILD_TYPE}-{GITHUB_REF_POINT_SLUG}-{arch} - # For PRs, GITHUB_REF_POINT_SLUG is the PR number (e.g., "123") - # The pattern contains("-{PR_NUM}-") matches both formats + # GITHUB_REF_POINT_SLUG is derived from the branch name (e.g., "my-feature" for branch "my-feature") + # The pattern contains("-{REF_SLUG}-") matches both formats - echo "Cleaning up buildcache tags for PR #${GITHUB_REF_POINT_SLUG} from eicweb.phy.anl.gov" + echo "Cleaning up buildcache tags for branch slug '${REF_SLUG}' from eicweb.phy.anl.gov" GITLAB_API="https://eicweb.phy.anl.gov/api/v4" GITLAB_PROJECT_ID="290" # containers/eic_container project ID @@ -97,13 +119,13 @@ jobs: echo "Found buildcache repository ID: ${REPOSITORY_ID}" - # Fetch all tags and filter for this PR + # Fetch all tags and filter for this branch TAGS_TO_DELETE=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ "${GITLAB_API}/projects/${GITLAB_PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags?per_page=100" \ - | jq -r --arg pr_num "${GITHUB_REF_POINT_SLUG}" '.[] | select(.name | contains("-\($pr_num)-")) | .name') + | jq -r --arg ref_slug "${REF_SLUG}" '.[] | select(.name | contains("-\($ref_slug)-")) | .name') if [ -z "$TAGS_TO_DELETE" ]; then - echo "No buildcache tags found for PR #${GITHUB_REF_POINT_SLUG} in eicweb.phy.anl.gov" + echo "No buildcache tags found for branch slug '${REF_SLUG}' in eicweb.phy.anl.gov" else # Delete each matching tag echo "Found buildcache tags to delete from eicweb.phy.anl.gov:" @@ -116,4 +138,4 @@ jobs: done fi - echo "Buildcache cleanup from eicweb.phy.anl.gov completed for PR #${GITHUB_REF_POINT_SLUG}" + echo "Buildcache cleanup from eicweb.phy.anl.gov completed for branch slug '${REF_SLUG}'" From a299e119550093b368a27dd50e5843b01fca7d6c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 18:15:42 +0000 Subject: [PATCH 08/12] Only run slug action for pull_request events Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com> --- .github/workflows/cleanup-buildcache.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cleanup-buildcache.yml b/.github/workflows/cleanup-buildcache.yml index 4769e261..7d855397 100644 --- a/.github/workflows/cleanup-buildcache.yml +++ b/.github/workflows/cleanup-buildcache.yml @@ -22,10 +22,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.ref || github.ref }} - name: Inject enhanced GitHub environment variables uses: rlespinasse/github-slug-action@v5 + if: github.event_name == 'pull_request' - name: Set ref slug id: ref_slug run: | From 599290676ae078972aaa4f58889b64233c20b34e Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Sun, 14 Dec 2025 17:44:27 -0600 Subject: [PATCH 09/12] fix: allow for eicweb curl failure Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/cleanup-buildcache.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cleanup-buildcache.yml b/.github/workflows/cleanup-buildcache.yml index 7d855397..4dd24a37 100644 --- a/.github/workflows/cleanup-buildcache.yml +++ b/.github/workflows/cleanup-buildcache.yml @@ -107,10 +107,14 @@ jobs: # List all repository tags for the buildcache image echo "Fetching buildcache repository tags..." - REPOSITORY_ID=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ + REPOSITORY_ID=$(curl -s --fail --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ "${GITLAB_API}/projects/${GITLAB_PROJECT_ID}/registry/repositories" \ | jq -r '.[] | select(.name == "buildcache") | .id') - + CURL_STATUS=${PIPESTATUS[0]} + if [ $CURL_STATUS -ne 0 ]; then + echo "Error: Failed to fetch registry repositories from GitLab API" + exit 1 + fi if [ -z "$REPOSITORY_ID" ]; then echo "Warning: Could not find buildcache repository in GitLab registry" exit 0 From 685722df7148ce4282ce9877c8834c57cde834f4 Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Sun, 14 Dec 2025 17:45:32 -0600 Subject: [PATCH 10/12] fix: docs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- docs/build-pipeline.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build-pipeline.md b/docs/build-pipeline.md index 58cf66b5..72964e18 100644 --- a/docs/build-pipeline.md +++ b/docs/build-pipeline.md @@ -165,7 +165,7 @@ Pre-built binaries are stored in OCI registries: | Trigger | Behavior | |---------|----------| -| Pull Request closed | Automatically removes all buildcache tags for the PR from ghcr.io and eicweb.phy.anl.gov | +| Pull Request closed | Automatically removes all buildcache tags associated with the branch slug (typically unique to the PR) from ghcr.io and eicweb.phy.anl.gov | ## Environment Matrix From 52a832eeea313a060920479f630f278af8403fb9 Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Sun, 14 Dec 2025 17:46:33 -0600 Subject: [PATCH 11/12] fix: handle pagination for eicweb Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/cleanup-buildcache.yml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cleanup-buildcache.yml b/.github/workflows/cleanup-buildcache.yml index 4dd24a37..a8a56a8f 100644 --- a/.github/workflows/cleanup-buildcache.yml +++ b/.github/workflows/cleanup-buildcache.yml @@ -122,11 +122,25 @@ jobs: echo "Found buildcache repository ID: ${REPOSITORY_ID}" - # Fetch all tags and filter for this branch - TAGS_TO_DELETE=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ - "${GITLAB_API}/projects/${GITLAB_PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags?per_page=100" \ - | jq -r --arg ref_slug "${REF_SLUG}" '.[] | select(.name | contains("-\($ref_slug)-")) | .name') - + # Fetch all tags and filter for this branch, handling pagination + TAGS_TO_DELETE="" + PAGE=1 + while :; do + RESPONSE=$(curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \ + "${GITLAB_API}/projects/${GITLAB_PROJECT_ID}/registry/repositories/${REPOSITORY_ID}/tags?per_page=100&page=${PAGE}") + TAGS=$(echo "$RESPONSE" | jq -r --arg ref_slug "${REF_SLUG}" '.[] | select(.name | contains("-\($ref_slug)-")) | .name') + if [ -z "$TAGS" ]; then + break + fi + TAGS_TO_DELETE="${TAGS_TO_DELETE} +${TAGS}" + # If fewer than 100 tags returned, this is the last page + COUNT=$(echo "$RESPONSE" | jq 'length') + if [ "$COUNT" -lt 100 ]; then + break + fi + PAGE=$((PAGE+1)) + done if [ -z "$TAGS_TO_DELETE" ]; then echo "No buildcache tags found for branch slug '${REF_SLUG}' in eicweb.phy.anl.gov" else From d7f1468c718336c8402502bf14c2769d766e6ff1 Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Sun, 14 Dec 2025 18:29:06 -0600 Subject: [PATCH 12/12] fix: add manual dispatch to docs --- docs/build-pipeline.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/build-pipeline.md b/docs/build-pipeline.md index 72964e18..c5f5e61d 100644 --- a/docs/build-pipeline.md +++ b/docs/build-pipeline.md @@ -166,6 +166,7 @@ Pre-built binaries are stored in OCI registries: | Trigger | Behavior | |---------|----------| | Pull Request closed | Automatically removes all buildcache tags associated with the branch slug (typically unique to the PR) from ghcr.io and eicweb.phy.anl.gov | +| Manual Dispatch | Allows manual cleanup of buildcache tags for a specific branch or PR by specifying a custom `ref_slug` parameter | ## Environment Matrix