mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-20 06:56:17 -05:00
ci: reconcile snapshot assets individually
This commit is contained in:
1 file changed
+60
-6
+60
-6
@@ -35,24 +35,31 @@ retry_gh() {
|
|||||||
|
|
||||||
upload_files() {
|
upload_files() {
|
||||||
local files=("$@")
|
local files=("$@")
|
||||||
|
local file
|
||||||
|
|
||||||
if [ ${#files[@]} -eq 0 ]; then
|
if [ ${#files[@]} -eq 0 ]; then
|
||||||
echo "No release assets found to upload"
|
echo "No release assets found to upload"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
retry_gh gh -R "$REPO" release upload "$TAG" --clobber "${files[@]}"
|
for file in "${files[@]}"; do
|
||||||
|
upload_file "$file"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
release_assets() {
|
release_assets() {
|
||||||
"$SCRIPT_DIR/release-assets.sh" "$TAG"
|
"$SCRIPT_DIR/release-assets.sh" "$TAG"
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot_asset_names() {
|
release_assets_json() {
|
||||||
|
retry_gh gh -R "$REPO" release view "$TAG" --json assets
|
||||||
|
}
|
||||||
|
|
||||||
|
release_asset_names() {
|
||||||
retry_gh gh -R "$REPO" release view "$TAG" --json assets --jq '.assets[].name'
|
retry_gh gh -R "$REPO" release view "$TAG" --json assets --jq '.assets[].name'
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_snapshot_asset() {
|
delete_release_asset() {
|
||||||
local asset=$1
|
local asset=$1
|
||||||
local assets
|
local assets
|
||||||
local attempt=1
|
local attempt=1
|
||||||
@@ -62,7 +69,7 @@ delete_snapshot_asset() {
|
|||||||
if gh -R "$REPO" release delete-asset "$TAG" "$asset" --yes; then
|
if gh -R "$REPO" release delete-asset "$TAG" "$asset" --yes; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
if assets="$(snapshot_asset_names)" && ! grep -Fqx -- "$asset" <<<"$assets"; then
|
if assets="$(release_asset_names)" && ! grep -Fqx -- "$asset" <<<"$assets"; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
if (( attempt >= GH_DELETE_MAX_ATTEMPTS )); then
|
if (( attempt >= GH_DELETE_MAX_ATTEMPTS )); then
|
||||||
@@ -76,6 +83,53 @@ delete_snapshot_asset() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upload_file() {
|
||||||
|
local file=$1
|
||||||
|
local asset
|
||||||
|
local assets_json
|
||||||
|
local local_digest
|
||||||
|
local remote_digest
|
||||||
|
local remote_exists
|
||||||
|
local attempt=1
|
||||||
|
local delay
|
||||||
|
|
||||||
|
asset="$(basename "$file")"
|
||||||
|
local_digest="sha256:$(sha256sum "$file" | cut -d ' ' -f 1)"
|
||||||
|
echo "Uploading $asset..."
|
||||||
|
|
||||||
|
while (( attempt <= GH_MAX_ATTEMPTS )); do
|
||||||
|
if gh -R "$REPO" release upload "$TAG" "$file"; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if assets_json="$(release_assets_json)"; then
|
||||||
|
remote_digest="$(jq -r --arg name "$asset" \
|
||||||
|
'.assets[] | select(.name == $name) | .digest // empty' <<<"$assets_json")"
|
||||||
|
if [[ "$remote_digest" == "$local_digest" ]]; then
|
||||||
|
echo "$asset is already uploaded with the expected digest"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
remote_exists="$(jq -r --arg name "$asset" \
|
||||||
|
'[.assets[] | select(.name == $name)] | length' <<<"$assets_json")"
|
||||||
|
if [[ "$remote_exists" != "0" ]]; then
|
||||||
|
if ! delete_release_asset "$asset"; then
|
||||||
|
echo "Could not replace release asset yet: $asset" >&2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( attempt >= GH_MAX_ATTEMPTS )); then
|
||||||
|
echo "Failed to upload release asset after $attempt attempts: $asset" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
delay=$((attempt * 3))
|
||||||
|
echo "Failed to upload $asset; retrying in ${delay}s" >&2
|
||||||
|
sleep "$delay"
|
||||||
|
((attempt += 1))
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Update the existing snapshot release in place to avoid notification spam.
|
# Update the existing snapshot release in place to avoid notification spam.
|
||||||
# Preserve its macOS update assets when the current run does not replace them.
|
# Preserve its macOS update assets when the current run does not replace them.
|
||||||
release_snapshot() {
|
release_snapshot() {
|
||||||
@@ -97,7 +151,7 @@ release_snapshot() {
|
|||||||
# release without the current artifacts.
|
# release without the current artifacts.
|
||||||
upload_files "${files[@]}"
|
upload_files "${files[@]}"
|
||||||
|
|
||||||
if ! existing_assets="$(snapshot_asset_names)"; then
|
if ! existing_assets="$(release_asset_names)"; then
|
||||||
echo "::warning::Could not list stale snapshot assets for cleanup" >&2
|
echo "::warning::Could not list stale snapshot assets for cleanup" >&2
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -121,7 +175,7 @@ release_snapshot() {
|
|||||||
"$asset" == GP-Connect-*-arm64.* ]]; then
|
"$asset" == GP-Connect-*-arm64.* ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
if ! delete_snapshot_asset "$asset"; then
|
if ! delete_release_asset "$asset"; then
|
||||||
echo "::warning::Could not remove stale snapshot asset: $asset" >&2
|
echo "::warning::Could not remove stale snapshot asset: $asset" >&2
|
||||||
fi
|
fi
|
||||||
done <<<"$existing_assets"
|
done <<<"$existing_assets"
|
||||||
|
|||||||
Reference in new issue
Block a user