Skip to content

Building and pushing UI frontend and backend images #25

Building and pushing UI frontend and backend images

Building and pushing UI frontend and backend images #25

name: Building and pushing UI frontend and backend images
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
check_and_build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Check latest version of sf-hamilton-ui
id: check_version
run: |
response=$(curl -s https://pypi.org/pypi/sf-hamilton-ui/json)
version=$(echo "$response" | jq -r '.info.version')
echo "latest_version=$version" >> $GITHUB_ENV
- name: Fetch highest version from Docker Hub
id: fetch_tags
run: |
# get the list of tags for the frontend image
tags=$(curl -s https://registry.hub.docker.com/v2/repositories/dagworks/ui-frontend/tags?page_size=100 | jq -r '.results[].name')
# find the highest version tag
highest_version="none"
for tag in $tags; do
if [[ "$tag" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [ "$highest_version" == "none" ] || [ "$(printf '%s\n' "$tag" "$highest_version" | sort -V | tail -n1)" == "$tag" ]; then
highest_version="$tag"
fi
fi
done
echo "Highest version on Docker Hub: $highest_version"
echo "highest_version=$highest_version" >> $GITHUB_OUTPUT
- name: Compare versions
id: compare_versions
run: |
echo "Current version: $latest_version"
highest_version=${{ steps.fetch_tags.outputs.highest_version }}
echo "Highest version found: $highest_version"
if [[ "$latest_version" == "$highest_version" ]]; then
echo "No new version found. Exiting."
echo "skip_build=true" >> $GITHUB_ENV
else
echo "New version detected: $latest_version"
echo "skip_build=false" >> $GITHUB_ENV
fi
- name: Run build and push script
if: env.skip_build != 'true'
run: |
chmod +x ./ui/buildx_and_push.sh
./ui/buildx_and_push.sh $latest_version
- name: Save the latest version to a file
if: env.skip_build != 'true'
run: |
mkdir -p version_cache
echo "$latest_version" > version_cache/previous_version.txt
- name: Cache the latest version
if: env.skip_build != 'true'
uses: actions/cache@v4
with:
path: ./version_cache
key: hamilton-ui-version-cache