-
Notifications
You must be signed in to change notification settings - Fork 6
chore(ci): clean up custom release tags in dev registry #2461
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
Open
universal-itengineer
wants to merge
3
commits into
main
Choose a base branch
from
chore/ci/improve-cleanup-dev-registry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Copyright 2026 Flant JSC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -Eeuo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| # shellcheck source=.github/scripts/bash/e2e/common.sh | ||
| source "${SCRIPT_DIR}/e2e/common.sh" | ||
|
|
||
| require_env MODULES_MODULE_SOURCE | ||
| require_env MODULES_MODULE_NAME | ||
|
|
||
| readonly PR_TAG_TTL_DAYS="${REGISTRY_CLEANUP_PR_TAG_TTL_DAYS:-14}" | ||
| readonly RC_TAG_TTL_DAYS="${REGISTRY_CLEANUP_RC_TAG_TTL_DAYS:-60}" | ||
| readonly DRY_RUN="${REGISTRY_CLEANUP_DRY_RUN:-false}" | ||
| # MODULES_MODULE_SOURCE and MODULES_MODULE_NAME come from the workflow env block | ||
| # and are validated by require_env above. | ||
| # shellcheck disable=SC2154 | ||
| readonly RELEASE_REPO="${MODULES_MODULE_SOURCE}/${MODULES_MODULE_NAME}/release" | ||
| readonly SECONDS_PER_DAY=$((24 * 60 * 60)) | ||
|
|
||
| now_epoch="$(date +%s)" | ||
| readonly pr_threshold_epoch=$((now_epoch - PR_TAG_TTL_DAYS * SECONDS_PER_DAY)) | ||
| readonly rc_threshold_epoch=$((now_epoch - RC_TAG_TTL_DAYS * SECONDS_PER_DAY)) | ||
|
|
||
| log() { | ||
| echo "[INFO] $*" | ||
| } | ||
|
|
||
| tag_created_epoch() { | ||
| local tag="$1" | ||
|
|
||
| crane config "${RELEASE_REPO}:${tag}" \ | ||
| | jq -r '.created | sub("\\.[0-9]+";"") | sub("Z?$";"Z") | fromdateiso8601' | ||
| } | ||
|
|
||
| # Returns 0 if the tag is expired and should be deleted. | ||
| # Protected tags (release channels, stable vX.Y.Z, main) never match. | ||
| is_expired_tag() { | ||
| local tag="$1" | ||
| local created_epoch="$2" | ||
|
|
||
| if [[ "${tag}" =~ ^pr[0-9]+$ || "${tag}" =~ ^release-[0-9]+\.[0-9]+ ]]; then | ||
| [ "${created_epoch}" -lt "${pr_threshold_epoch}" ] | ||
| elif [[ "${tag}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+$ ]]; then | ||
| [ "${created_epoch}" -lt "${rc_threshold_epoch}" ] | ||
| else | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| # crane delete removes the manifest by the digest the tag points to. Tags that | ||
| # share a digest with the deleted one are untagged too, so only expired and | ||
| # unprotected tags reach this function. | ||
| delete_tag() { | ||
| local tag="$1" | ||
|
|
||
| if [ "${DRY_RUN}" = "true" ]; then | ||
| log "[dry-run] would delete ${RELEASE_REPO}:${tag}" | ||
| return | ||
| fi | ||
|
|
||
| log "deleting ${RELEASE_REPO}:${tag}" | ||
| crane delete "${RELEASE_REPO}:${tag}" | ||
| } | ||
|
|
||
| cleanup_repo() { | ||
| local tag created_epoch | ||
| local deleted=0 kept=0 failed=0 | ||
|
|
||
| while read -r tag; do | ||
| [ -z "${tag}" ] && continue | ||
|
|
||
| created_epoch="$(tag_created_epoch "${tag}" 2>/dev/null)" || created_epoch="" | ||
| if [ -z "${created_epoch}" ]; then | ||
| log "skip ${tag}: cannot resolve creation time" | ||
| kept=$((kept + 1)) | ||
| continue | ||
| fi | ||
|
|
||
| if is_expired_tag "${tag}" "${created_epoch}"; then | ||
| if delete_tag "${tag}"; then | ||
| deleted=$((deleted + 1)) | ||
| else | ||
| log "WARN: failed to delete ${RELEASE_REPO}:${tag}" | ||
| failed=$((failed + 1)) | ||
| fi | ||
| else | ||
| kept=$((kept + 1)) | ||
| fi | ||
| done < <(crane ls "${RELEASE_REPO}") | ||
|
|
||
| log "done: ${deleted} deleted, ${kept} kept, ${failed} failed" | ||
|
|
||
| if [ "${failed}" -gt 0 ]; then | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| log "cleaning custom release tags in ${RELEASE_REPO}" | ||
| log "dry run: ${DRY_RUN}" | ||
| log "pr/release branch tag TTL: ${PR_TAG_TTL_DAYS} days" | ||
| log "release candidate tag TTL: ${RC_TAG_TTL_DAYS} days" | ||
|
|
||
| cleanup_repo | ||
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.
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.