Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions .github/actions/get-weaviate-branch/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
name: get-weaviate-branch
description: 'Resolves a Weaviate Docker tag to the git ref (commit/branch) from weaviate/weaviate that matches the image code'
inputs:
docker_tag:
description: 'The Docker tag to resolve (e.g. 1.36.6, preview-my-pr-abc1234.amd64, main-abc1234, nightly, latest)'
required: true
gh_token:
description: 'GitHub token for API calls to resolve short commit hashes (avoids rate limits). Optional but recommended.'
required: false
default: ''
outputs:
ref:
description: 'Best git ref for checkout (always a full 40-char commit hash)'
value: ${{ steps.resolve.outputs.ref }}
commit:
description: 'Full 40-char commit hash'
value: ${{ steps.resolve.outputs.commit }}
branch:
description: 'Branch name best-guess (empty if not determinable, e.g. for preview/PR tags)'
value: ${{ steps.resolve.outputs.branch }}
runs:
using: 'composite'
steps:
- name: Resolve Docker tag to git ref
id: resolve
shell: bash
env:
GH_TOKEN: ${{ inputs.gh_token }}
run: |
set -euo pipefail

# weaviate/weaviate is a public repo — git operations (ls-remote, fetch)
# work without authentication. The token is only needed for the GitHub
# API call that resolves short commit hashes (step 6).
WEAVIATE_REPO="https://github.com/weaviate/weaviate.git"
Comment thread
jfrancoa marked this conversation as resolved.
WEAVIATE_API="https://api.github.com/repos/weaviate/weaviate"
tag="${{ inputs.docker_tag }}"
commit=""
branch=""

echo "Resolving Docker tag: ${tag}"

# Step 1: Strip architecture suffix
tag_stripped="${tag}"
tag_stripped="${tag_stripped%.amd64}"
tag_stripped="${tag_stripped%.arm64}"

# Step 2: Handle special Docker-only tags
if [ "${tag_stripped}" = "nightly" ]; then
echo "Tag is 'nightly' — resolving main branch HEAD"
commit=$(git ls-remote "${WEAVIATE_REPO}" refs/heads/main | awk '{print $1}')
branch="main"
elif [ "${tag_stripped}" = "latest" ]; then
echo "Tag is 'latest' — finding highest release tag"
# Find the latest release tag name — capture full output to avoid
# broken pipe from head -1 under pipefail.
all_tags=$(git -c 'versionsort.suffix=-' ls-remote --tags --refs --sort='-v:refname' "${WEAVIATE_REPO}" \
| grep -oE 'refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$' || true)
latest_tag=$(echo "${all_tags}" | head -1 | sed 's|refs/tags/||')
if [ -z "${latest_tag}" ]; then
echo "::error::Failed to find any release tag for 'latest' Docker tag"
exit 1
fi

# Resolve the annotated tag to its underlying commit (use ^{} dereferenced entry)
commit=$(git ls-remote --tags "${WEAVIATE_REPO}" "refs/tags/${latest_tag}" "refs/tags/${latest_tag}^{}" \
| tail -1 | awk '{print $1}')
if [ -z "${commit}" ]; then
echo "::error::Failed to resolve commit for tag '${latest_tag}'"
exit 1
fi

# Extract major.minor for branch
version="${latest_tag#v}"
major_minor=$(echo "${version}" | grep -oE '^[0-9]+\.[0-9]+')
branch="stable/v${major_minor}"
echo "Resolved 'latest' to tag ${latest_tag} (commit ${commit})"
Comment thread
jfrancoa marked this conversation as resolved.
else
# Step 3: Try to extract 7-char hex hash from end (after last '-')
suffix="${tag_stripped##*-}"
if [[ "${suffix}" =~ ^[0-9a-f]{7}$ ]]; then
commit="${suffix}"
prefix="${tag_stripped%-*}"

# Step 4: Determine branch from prefix
if [[ "${prefix}" =~ ^preview- ]]; then
# Preview/PR build — branch is not recoverable from tag
branch=""
echo "Preview tag detected, short commit: ${commit}"
elif [[ "${prefix}" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
# Semver prefix (e.g. 1.37.0-dev, 1.36.6) — branch not directly in tag
branch=""
echo "Semver+hash tag detected, short commit: ${commit}"
else
# Branch name prefix (e.g. main, stable-v1.34)
# In push_docker.sh, '/' in branch names is replaced with '-'
# Try common patterns to restore the original branch name
if [[ "${prefix}" =~ ^stable-v[0-9]+\.[0-9]+$ ]]; then
branch="${prefix/stable-/stable/}"
else
# For simple branch names (main, feature-x), keep as-is
# Cannot reliably restore '/' for arbitrary branches
branch="${prefix}"
fi
echo "Branch tag detected, branch: ${branch}, short commit: ${commit}"
fi
else
# Step 5: No hash found — must be a release version tag (X.Y.Z or X.Y.Z-rc.N)
version="${tag_stripped}"
git_tag="v${version}"
echo "Release tag detected: ${git_tag} — resolving commit from git"

# Resolve the annotated tag to its commit (use ^{} dereferenced entry if present)
tag_commit=$(git ls-remote --tags "${WEAVIATE_REPO}" "refs/tags/${git_tag}" "refs/tags/${git_tag}^{}" \
| tail -1 | awk '{print $1}')

if [ -z "${tag_commit}" ]; then
echo "::error::Could not find git tag ${git_tag} in weaviate/weaviate"
exit 1
fi

commit="${tag_commit}"
# Extract major.minor for stable branch (grep handles RC versions like 1.36.0-rc.0 → 1.36)
major_minor=$(echo "${version}" | grep -oE '^[0-9]+\.[0-9]+')
branch="stable/v${major_minor}"
echo "Resolved ${git_tag} to commit ${commit}"
fi
fi

# Step 6: Resolve short hashes (7-char) to full 40-char SHA via GitHub API
if [ -z "${commit}" ]; then
echo "::error::No commit hash could be extracted from Docker tag '${tag}'"
exit 1
fi
if [ "${#commit}" -lt 40 ]; then
echo "Resolving short hash ${commit} to full SHA..."
curl_args=(-sf -H "Accept: application/vnd.github.v3+json")
if [ -n "${GH_TOKEN}" ]; then
curl_args+=(-H "Authorization: Bearer ${GH_TOKEN}")
fi
if ! response=$(curl "${curl_args[@]}" "${WEAVIATE_API}/commits/${commit}"); then
echo "::error::GitHub API call failed when resolving short hash '${commit}'"
exit 1
fi
full_sha=$(printf '%s\n' "${response}" | jq -r '.sha // empty')

if [ -z "${full_sha}" ]; then
echo "::error::Could not resolve short hash ${commit} to a full SHA"
exit 1
fi
Comment thread
jfrancoa marked this conversation as resolved.
echo "Resolved ${commit} -> ${full_sha}"
commit="${full_sha}"
fi

ref="${commit}"

echo "ref=${ref}" >> "${GITHUB_OUTPUT}"
echo "commit=${commit}" >> "${GITHUB_OUTPUT}"
echo "branch=${branch}" >> "${GITHUB_OUTPUT}"

echo "--- Results ---"
echo "ref: ${ref}"
echo "commit: ${commit}"
echo "branch: ${branch}"
68 changes: 68 additions & 0 deletions .github/actions/pull-weaviate-code/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: pull-weaviate-code
description: 'Clones the weaviate/weaviate repository at the commit matching a given Docker tag'
inputs:
docker_tag:
description: 'Weaviate Docker tag to resolve (e.g. 1.36.6, preview-my-pr-abc1234.amd64, main-abc1234, nightly, latest)'
required: true
directory:
description: 'Directory in which to clone the weaviate repository (a "weaviate" folder will be created inside it)'
required: false
default: '.'
gh_token:
description: 'GitHub token passed to get-weaviate-branch for API calls (avoids rate limits). Optional but recommended.'
required: false
default: ''
outputs:
ref:
description: 'The git ref that was checked out (full 40-char commit hash)'
value: ${{ steps.resolve-tag.outputs.ref }}
commit:
description: 'Full 40-char commit hash that was checked out'
value: ${{ steps.resolve-tag.outputs.commit }}
branch:
description: 'The branch name (if determinable)'
value: ${{ steps.resolve-tag.outputs.branch }}
weaviate_path:
description: 'Full path to the cloned weaviate directory'
value: ${{ steps.clone.outputs.weaviate_path }}
runs:
using: 'composite'
steps:
- name: Resolve Docker tag to git ref
id: resolve-tag
uses: ./.github/actions/get-weaviate-branch
with:
docker_tag: ${{ inputs.docker_tag }}
gh_token: ${{ inputs.gh_token }}

- name: Clone weaviate at resolved ref
id: clone
shell: bash
run: |
set -euo pipefail

# weaviate/weaviate is a public repo — no auth needed for git fetch.
WEAVIATE_REPO="https://github.com/weaviate/weaviate.git"
TARGET_DIR="${{ inputs.directory }}"
WEAVIATE_DIR="${TARGET_DIR}/weaviate"
COMMIT="${{ steps.resolve-tag.outputs.commit }}"

# Check that the weaviate path doesn't already exist (file, directory, or symlink)
if [ -e "${WEAVIATE_DIR}" ]; then
echo "::error::Path '${WEAVIATE_DIR}' already exists. Remove it before running this action to avoid conflicts."
exit 1
fi

# Ensure parent directory exists
mkdir -p "${TARGET_DIR}"

echo "Cloning weaviate at commit ${COMMIT} into ${WEAVIATE_DIR}..."
git init "${WEAVIATE_DIR}"
cd "${WEAVIATE_DIR}"
git remote add origin "${WEAVIATE_REPO}"
git fetch --depth=1 origin "${COMMIT}"
git checkout FETCH_HEAD

FULL_PATH="$(pwd)"
echo "weaviate_path=${FULL_PATH}" >> "${GITHUB_OUTPUT}"
echo "Successfully cloned weaviate at ${COMMIT} to ${FULL_PATH}"
Loading
Loading