Skip to content

Commit

Permalink
Add weaviate-version-in-image composite action.
Browse files Browse the repository at this point in the history
This new composite action returns in an output.weaviate_version
variable the underlaying version from a given image.
  • Loading branch information
jfrancoa committed Oct 23, 2024
1 parent 9affc1e commit 11dcc55
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/actions/weaviate-version-in-image/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: weaviate-version-in-image
description: 'Retrieves the Weaviate version from a given Weaviate Docker image.'
inputs:
image_tag:
description: 'The Weaviate Docker image to retrieve the version from.'
required: true
default: 'latest'
registry:
description: 'The Docker registry and namespace to pull the image from.'
required: false
default: 'docker.io/semitechnologies/weaviate'
runs:
using: 'composite'
steps:
- name: Set globals
id: globals
shell: bash
run: |
echo "action_timeout=300" >> "${GITHUB_OUTPUT}"
echo "action_port=8080" >> "${GITHUB_OUTPUT}"
- name: Start Weaviate service
shell: bash
id: start-docker-container
run: |
CONTAINER_ID=$(docker run -d --rm \
--name weaviate_service \
-p ${{ steps.globals.outputs.action_port}}:8080 \
${{ inputs.registry }}:${{ inputs.image_tag }} \
--host 0.0.0.0 \
--port 8080 \
--scheme http \
--write-timeout 600s)
echo "Container ID: $CONTAINER_ID"
echo "container_id=$CONTAINER_ID" >> "${GITHUB_OUTPUT}"
- name: Wait for .well-known/ready API to be ready
shell: bash
id: wait-for-ready
run: |
start_time=$(date +%s)
timeout=${{ steps.globals.outputs.action_timeout }}
until [ "$(curl -w '%{http_code}' -s -o /dev/null http://localhost:${{ steps.globals.outputs.action_port}}/v1/.well-known/ready)" -eq 200 ]; do
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -ge "$timeout" ]; then
echo "Timeout of $timeout seconds reached. Exiting..."
exit 1
fi
echo "Waiting for Weaviate service to be ready..."
sleep 5
done
- name: Set the Weaviate version as an output
shell: bash
run: |
WEAVIATE_VERSION=$(curl http://localhost:${{ steps.globals.outputs.action_port}}/v1/meta | jq -r '.version')
echo "Found weaviate version: $WEAVIATE_VERSION"
echo "weaviate_version=$WEAVIATE_VERSION" >> "${GITHUB_OUTPUT}"
91 changes: 91 additions & 0 deletions .github/workflows/version-in-image-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Test Weaviate Version in Image Action

on:
push:

jobs:
basic-image:
runs-on: ubuntu-latest
env:
IMAGE_TAG: "1.27.0"
EXPECTED: "1.27.0"
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Test weaviate-version-in-image action
id: weaviate-version-in-image
uses: ./.github/actions/weaviate-version-in-image
with:
image_tag: ${{ env.IMAGE_TAG }}
- name: Verify that the retrieved version matches the expected one
run: |
echo "Expected: ${{ env.EXPECTED }}"
echo "Actual: ${{ steps.weaviate-version-in-image.outputs.weaviate_version }}"
if [ "${{ env.EXPECTED }}" != "${{ steps.weaviate-version-in-image.outputs.weaviate_version }}" ]; then
echo "The retrieved version does not match the expected one."
exit 1
fi
stable-image:
runs-on: ubuntu-latest
env:
IMAGE_TAG: "stable-v1.25-b3bc753"
EXPECTED: "1.25.0"
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Test weaviate-version-in-image action
id: weaviate-version-in-image
uses: ./.github/actions/weaviate-version-in-image
with:
image_tag: ${{ env.IMAGE_TAG }}
- name: Verify that the retrieved version matches the expected one
run: |
echo "Expected: ${{ env.EXPECTED }}"
echo "Actual: ${{ steps.weaviate-version-in-image.outputs.weaviate_version }}"
if [ "${{ env.EXPECTED }}" != "${{ steps.weaviate-version-in-image.outputs.weaviate_version }}" ]; then
echo "The retrieved version does not match the expected one."
exit 1
fi
main-image:
runs-on: ubuntu-latest
env:
IMAGE_TAG: "main-f759849"
EXPECTED: "1.27.0"
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Test weaviate-version-in-image action
id: weaviate-version-in-image
uses: ./.github/actions/weaviate-version-in-image
with:
image_tag: ${{ env.IMAGE_TAG }}
- name: Verify that the retrieved version matches the expected one
run: |
echo "Expected: ${{ env.EXPECTED }}"
echo "Actual: ${{ steps.weaviate-version-in-image.outputs.weaviate_version }}"
if [ "${{ env.EXPECTED }}" != "${{ steps.weaviate-version-in-image.outputs.weaviate_version }}" ]; then
echo "The retrieved version does not match the expected one."
exit 1
fi
preview-image:
runs-on: ubuntu-latest
env:
IMAGE_TAG: "preview--hnsw-pq-bq-prefill-compressed-vector-cache-in-parallel-d351d51"
EXPECTED: "1.27.0"
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Test weaviate-version-in-image action
id: weaviate-version-in-image
uses: ./.github/actions/weaviate-version-in-image
with:
image_tag: ${{ env.IMAGE_TAG }}
- name: Verify that the retrieved version matches the expected one
run: |
echo "Expected: ${{ env.EXPECTED }}"
echo "Actual: ${{ steps.weaviate-version-in-image.outputs.weaviate_version }}"
if [ "${{ env.EXPECTED }}" != "${{ steps.weaviate-version-in-image.outputs.weaviate_version }}" ]; then
echo "The retrieved version does not match the expected one."
exit 1
fi
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# github-common-actions
Reusable composite actions used from other Weaviate workflows to avoid code duplication

## weaviate-version-in-image

### Description
Retrieves the Weaviate version from a given Weaviate Docker image.

### Inputs
- `image_tag` (required): The Weaviate Docker image to retrieve the version from. Default: `latest`.
- `registry` (optional): The Docker registry and namespace to pull the image from. Default: `docker.io/semitechnologies/weaviate`.

### Usage
```yaml
name: Retrieve Weaviate Version
on: [push]

jobs:
retrieve-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Retrieve Weaviate Version
uses: ./.github/actions/weaviate-version-in-image
id: weaviate-version
with:
image_tag: 'latest'
registry: 'docker.io/semitechnologies/weaviate'

- name: Output Weaviate Version
run: echo "Weaviate Version: ${{ steps.weaviate-version.outputs.weaviate_version }}"
```
### Runs
This action runs using `composite` with the following steps:
1. **Set globals**: Sets global variables for action timeout and port.
2. **Start Weaviate service**: Starts the Weaviate Docker container.
3. **Wait for .well-known/ready API to be ready**: Waits until the Weaviate service is ready.
4. **Set the Weaviate version as an output**: Retrieves and sets the Weaviate version as an output.

0 comments on commit 11dcc55

Please sign in to comment.