Skip to content

Commit b909a6c

Browse files
committed
update github actions
1 parent 4bc106a commit b909a6c

8 files changed

Lines changed: 699 additions & 1 deletion

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
echo "🔄 Updating metadata.json with correct versions"
6+
7+
# Define components and their services
8+
COMPONENTS=("miner" "validator")
9+
declare -A SERVICES
10+
SERVICES["miner"]="neuron"
11+
SERVICES["validator"]="neuron redis"
12+
13+
# Function to extract version from a directory
14+
get_version() {
15+
dir="$1"
16+
if [ -f "$dir/version.py" ]; then
17+
grep -oE '__version__ *= *["'\'']([^"\'']+)["'\'']' "$dir/version.py" | sed -E 's/__version__ *= *["'\'']([^"\'']+)["'\'']/\1/'
18+
elif [ -f "$dir/pyproject.toml" ]; then
19+
grep -E '^version\s*=\s*"([^"]+)"' "$dir/pyproject.toml" | awk -F '"' '{print $2}'
20+
elif [ -f "$dir/VERSION" ]; then
21+
tr -d '\n' < "$dir/VERSION"
22+
else
23+
echo "VERSION_NOT_FOUND"
24+
fi
25+
}
26+
27+
# Ensure jq is installed
28+
if ! command -v jq &> /dev/null; then
29+
echo "❌ Error: jq is not installed. Please install jq to run this script."
30+
exit 1
31+
fi
32+
33+
# Extract root project version (./version.py)
34+
echo "📦 Extracting root project version..."
35+
ROOT_VERSION=$(get_version ".")
36+
if [[ "$ROOT_VERSION" == "VERSION_NOT_FOUND" ]]; then
37+
echo "❌ Could not find root project version."
38+
exit 1
39+
fi
40+
41+
# Iterate over all components
42+
for COMPONENT in "${COMPONENTS[@]}"; do
43+
echo "📦 Processing component: $COMPONENT"
44+
45+
# Get component version (from subvortex/component/version.py)
46+
COMPONENT_VERSION=$(get_version "subvortex/$COMPONENT")
47+
if [[ "$COMPONENT_VERSION" == "VERSION_NOT_FOUND" ]]; then
48+
echo "⚠️ No component version found for $COMPONENT"
49+
continue
50+
fi
51+
52+
# Update each service
53+
for SERVICE in ${SERVICES[$COMPONENT]}; do
54+
echo "🔍 Processing service: $COMPONENT/$SERVICE"
55+
56+
SERVICE_PATH="subvortex/$COMPONENT/$SERVICE"
57+
if [[ ! -d "$SERVICE_PATH" ]]; then
58+
echo "🚫 Directory not found: $SERVICE_PATH"
59+
continue
60+
fi
61+
62+
# Get service version (subvortex/component/service)
63+
SERVICE_VERSION=$(get_version "$SERVICE_PATH")
64+
if [[ "$SERVICE_VERSION" == "VERSION_NOT_FOUND" ]]; then
65+
echo "⚠️ No service version found for $COMPONENT/$SERVICE"
66+
continue
67+
fi
68+
69+
# Metadata file
70+
metadata_path="$SERVICE_PATH/metadata.json"
71+
tmpfile=$(mktemp)
72+
73+
# Build/update JSON
74+
if [ -f "$metadata_path" ]; then
75+
jq --arg root_version "$ROOT_VERSION" \
76+
--arg comp_version "$COMPONENT_VERSION" \
77+
--arg svc_version "$SERVICE_VERSION" \
78+
'.version = $root_version
79+
| ."'"$COMPONENT"'.version" = $comp_version
80+
| ."'"$COMPONENT"'.'"$SERVICE"'.version" = $svc_version' \
81+
"$metadata_path" > "$tmpfile" && mv "$tmpfile" "$metadata_path"
82+
else
83+
echo "{
84+
\"version\": \"$ROOT_VERSION\",
85+
\"$COMPONENT.version\": \"$COMPONENT_VERSION\",
86+
\"$COMPONENT.$SERVICE.version\": \"$SERVICE_VERSION\"
87+
}" > "$metadata_path"
88+
fi
89+
90+
echo "🏷️ Updated $metadata_path with:"
91+
echo " ➡️ version=$ROOT_VERSION"
92+
echo " ➡️ $COMPONENT.version=$COMPONENT_VERSION"
93+
echo " ➡️ $COMPONENT.$SERVICE.version=$SERVICE_VERSION"
94+
done
95+
done
96+
97+
echo "✅ Done."

.github/scripts/install_skopeo.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
echo "📦 Checking if skopeo is installed..."
5+
6+
if command -v skopeo >/dev/null 2>&1; then
7+
echo "✅ skopeo already installed."
8+
exit 0
9+
fi
10+
11+
echo "🔍 skopeo not found — installing..."
12+
13+
# Detect OS
14+
OS="$(uname -s)"
15+
16+
if [[ "$OS" == "Darwin" ]]; then
17+
# macOS
18+
if ! command -v brew >/dev/null 2>&1; then
19+
echo "❌ Homebrew is not installed. Install it from https://brew.sh/"
20+
exit 1
21+
fi
22+
brew install skopeo
23+
elif [[ "$OS" == "Linux" ]]; then
24+
# Linux
25+
if command -v apt-get >/dev/null 2>&1; then
26+
# Debian/Ubuntu
27+
sudo apt-get update
28+
sudo apt-get install -y skopeo
29+
elif command -v dnf >/dev/null 2>&1; then
30+
# Fedora
31+
sudo dnf install -y skopeo
32+
elif command -v yum >/dev/null 2>&1; then
33+
# RHEL/CentOS 7
34+
sudo yum install -y skopeo
35+
else
36+
echo "❌ Unsupported Linux distribution. Please install skopeo manually."
37+
exit 1
38+
fi
39+
else
40+
echo "❌ Unsupported OS: $OS"
41+
exit 1
42+
fi
43+
44+
echo "✅ skopeo installed successfully."
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
COMPONENT="$1"
5+
SERVICE="$2"
6+
TAG="$3"
7+
VERSION="${TAG#v}"
8+
REPO_OWNER="${GITHUB_REPOSITORY_OWNER:-eclipsevortex}"
9+
REPO_NAME="subvortex-$COMPONENT-${SERVICE//_/-}"
10+
IMAGE="ghcr.io/$REPO_OWNER/$REPO_NAME"
11+
12+
GHCR_USERNAME="${GHCR_USERNAME:-}"
13+
GHCR_TOKEN="${GHCR_TOKEN:-}"
14+
15+
# Always resolve the absolute path to the 'scripts' folder
16+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17+
18+
# Run the install_skopeo.sh script
19+
bash "$SCRIPT_DIR/install_skopeo.sh"
20+
21+
if [[ -z "$GHCR_USERNAME" || -z "$GHCR_TOKEN" ]]; then
22+
echo "❌ Missing GHCR credentials (GHCR_USERNAME / GHCR_TOKEN)"
23+
exit 1
24+
fi
25+
26+
echo "🧹 Cleaning up release: $TAG"
27+
echo "📦 Target image: $IMAGE"
28+
29+
# Fetch all GitHub releases
30+
REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
31+
ALL_RELEASES=$(gh api "/repos/$REPO/releases" --paginate | jq -rc '[.[] | select(.draft == false)] | sort_by(.created_at) | reverse')
32+
33+
# Helper to safely extract tags or return empty
34+
jq_extract_or_empty() {
35+
echo "$ALL_RELEASES" | jq -r "$1" | grep -v '^null$' || echo ""
36+
}
37+
38+
# Determine floating tag targets
39+
DEV_TAG=$(jq_extract_or_empty '.[0].tag_name')
40+
STABLE_TAG=$(jq_extract_or_empty 'map(select(.tag_name | test("-alpha") | not)) | .[0].tag_name')
41+
LATEST_TAG=$(jq_extract_or_empty 'map(select(.prerelease == false)) | .[0].tag_name')
42+
43+
echo "🔁 Floating tag targets:"
44+
printf " dev → %s\n" "${DEV_TAG:-<none>}"
45+
printf " stable → %s\n" "${STABLE_TAG:-<none>}"
46+
printf " latest → %s\n" "${LATEST_TAG:-<none>}"
47+
48+
# Function to delete a tag via Docker Hub API
49+
delete_docker_tag() {
50+
local tag="$1"
51+
52+
echo "🗑️ Attempting to delete $IMAGE:$tag from GHCR..."
53+
54+
# Find version ID
55+
VERSION_ID=$(gh api "user/packages/container/${REPO_NAME}/versions" \
56+
-H "Authorization: Bearer $GHCR_TOKEN" \
57+
| jq -r ".[] | select(.metadata.container.tags[]? == \"$tag\") | .id")
58+
59+
if [[ -z "$VERSION_ID" ]]; then
60+
echo "⚠️ No version ID found for tag $tag — skipping delete."
61+
return
62+
fi
63+
64+
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
65+
-H "Authorization: Bearer $GHCR_TOKEN" \
66+
-H "Accept: application/vnd.github.v3+json" \
67+
"https://api.github.com/user/packages/container/${REPO_NAME}/versions/${VERSION_ID}")
68+
69+
case "$RESPONSE" in
70+
204) echo "✅ Deleted $IMAGE:$tag" ;;
71+
404) echo "⚠️ Tag $IMAGE:$tag not found on GHCR" ;;
72+
*) echo "❌ Failed to delete $IMAGE:$tag (HTTP $RESPONSE)" ;;
73+
esac
74+
}
75+
76+
# Apply floating tags or delete if no valid target
77+
for FTAG in dev stable latest; do
78+
case "$FTAG" in
79+
dev) TARGET="$DEV_TAG" ;;
80+
stable) TARGET="$STABLE_TAG" ;;
81+
latest) TARGET="$LATEST_TAG" ;;
82+
esac
83+
84+
if [[ -z "$TARGET" ]]; then
85+
echo "⚠️ No tag found for $FTAG — skipping"
86+
continue
87+
fi
88+
89+
TARGET="${TARGET#v}"
90+
91+
if [[ -n "$TARGET" ]]; then
92+
echo "🔍 Checking if $IMAGE:$TARGET exists..."
93+
94+
if skopeo inspect --raw --creds "${GHCR_USERNAME}:${GHCR_TOKEN}" docker://$IMAGE:$TARGET &>/dev/null; then
95+
echo "🏷️ Re-tagging $IMAGE:$FTAG$IMAGE:$TARGET using skopeo"
96+
skopeo copy --all --dest-creds="${GHCR_USERNAME}:${GHCR_TOKEN}" \
97+
docker://$IMAGE:$TARGET \
98+
docker://$IMAGE:$FTAG
99+
echo "✅ Floating tag '$FTAG' now points to '$TARGET'"
100+
else
101+
echo "⚠️ Image $IMAGE:$TARGET does not exist — skipping $FTAG re-tag"
102+
delete_docker_tag "$FTAG"
103+
fi
104+
else
105+
echo "⚠️ No valid candidate for $FTAG — skipping"
106+
fi
107+
done
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
COMPONENT="$1"
5+
SERVICE="$2"
6+
RAW_VERSION_TAG="$3"
7+
IS_PRERELEASE="$4"
8+
IS_DRAFT="$5"
9+
10+
VERSION="${RAW_VERSION_TAG#v}"
11+
REPO_OWNER="${GITHUB_REPOSITORY_OWNER:-eclipsevortex}"
12+
REPO_NAME="subvortex-$COMPONENT-${SERVICE//_/-}"
13+
IMAGE="ghcr.io/$REPO_OWNER/$REPO_NAME"
14+
15+
if [[ "$IS_DRAFT" == "true" ]]; then
16+
echo "⏭️ Skipping draft release"
17+
exit 0
18+
fi
19+
20+
echo "📦 Current release: $RAW_VERSION_TAG (prerelease=$IS_PRERELEASE)"
21+
echo "🔍 Getting manifest for $IMAGE:$VERSION"
22+
docker buildx imagetools inspect "$IMAGE:$VERSION"
23+
24+
# Floating tags
25+
DEV_TAG="$RAW_VERSION_TAG"
26+
STABLE_TAG=""
27+
LATEST_TAG=""
28+
29+
if [[ "$RAW_VERSION_TAG" =~ -alpha\. || "$RAW_VERSION_TAG" =~ -beta\. ]]; then
30+
# Alpha or beta → only dev
31+
:
32+
elif [[ "$RAW_VERSION_TAG" =~ -rc\. ]]; then
33+
# Release candidate → dev + stable
34+
STABLE_TAG="$RAW_VERSION_TAG"
35+
else
36+
# No suffix = final release → dev + stable + latest
37+
STABLE_TAG="$RAW_VERSION_TAG"
38+
LATEST_TAG="$RAW_VERSION_TAG"
39+
fi
40+
41+
echo "🔁 Will update Docker floating tags:"
42+
printf " dev → %s\n" "${DEV_TAG:-<none>}"
43+
printf " stable → %s\n" "${STABLE_TAG:-<none>}"
44+
printf " latest → %s\n" "${LATEST_TAG:-<none>}"
45+
46+
# Retag floating tags
47+
for FLOAT_TAG in dev stable latest; do
48+
case "$FLOAT_TAG" in
49+
dev) TARGET_TAG="$DEV_TAG" ;;
50+
stable) TARGET_TAG="$STABLE_TAG" ;;
51+
latest) TARGET_TAG="$LATEST_TAG" ;;
52+
esac
53+
54+
if [[ -z "$TARGET_TAG" ]]; then
55+
echo "⚠️ No tag found for $FLOAT_TAG — skipping"
56+
continue
57+
fi
58+
59+
if [[ "$IS_PRERELEASE" == "true" && "$FLOAT_TAG" == "latest" ]]; then
60+
echo "⏭️ Skipping 'latest' for prerelease"
61+
continue
62+
fi
63+
64+
TARGET_VERSION="${TARGET_TAG#v}"
65+
66+
# 🔥 Check if the source image exists
67+
if ! docker buildx imagetools inspect "$IMAGE:$TARGET_VERSION" &>/dev/null; then
68+
echo "⚠️ Source image $IMAGE:$TARGET_VERSION does not exist — skipping $FLOAT_TAG"
69+
continue
70+
fi
71+
72+
# -- Optimization: check if FLOAT_TAG already points to the correct image
73+
echo "🔍 Checking if $IMAGE:$FLOAT_TAG already matches $IMAGE:$TARGET_VERSION..."
74+
75+
TARGET_DIGEST=$(docker buildx imagetools inspect "$IMAGE:$TARGET_VERSION" --format '{{.Manifest.Digest}}' 2>/dev/null || echo "")
76+
FLOAT_DIGEST=$(docker buildx imagetools inspect "$IMAGE:$FLOAT_TAG" --format '{{.Manifest.Digest}}' 2>/dev/null || echo "")
77+
78+
if [[ "$TARGET_DIGEST" == "$FLOAT_DIGEST" && -n "$TARGET_DIGEST" ]]; then
79+
echo "$IMAGE:$FLOAT_TAG already up to date. Skipping."
80+
continue
81+
fi
82+
83+
echo "🔁 Retagging $IMAGE:$TARGET_VERSION as $IMAGE:$FLOAT_TAG"
84+
docker buildx imagetools create \
85+
--tag "$IMAGE:$FLOAT_TAG" \
86+
"$IMAGE:$TARGET_VERSION"
87+
done

0 commit comments

Comments
 (0)