Docker Image CI #132
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Image CI | |
on: | |
pull_request: | |
branches: | |
- master | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
schedule: | |
- cron: '0 0 * * *' | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.event.repository.name }} | |
PACKAGE_NAME: autogenstudio | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
- name: Get the latest version number of the python package | |
id: get_version | |
run: | | |
VERSION=$(curl -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json | jq -r .info.version) | |
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
- name: Compare PIP version with last created package in the container registry | |
id: check_version | |
run: | | |
echo "Checking if the version exists in the container registry..." | |
echo "Version: ${{ steps.get_version.outputs.VERSION }}" | |
IMAGE=${{ env.REGISTRY }}/$(echo "${{ github.actor }}" | tr '[:upper:]' '[:lower:]')/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }} | |
echo "Image: $IMAGE" | |
echo "PUSH_IMAGE=false" >> $GITHUB_OUTPUT | |
if docker manifest inspect $IMAGE > /dev/null 2>&1; then | |
echo "The version exists in the container registry." | |
echo "VERSION_EXISTS=true" >> $GITHUB_OUTPUT | |
else | |
echo "The version does not exist in the container registry." | |
echo "VERSION_EXISTS=false" >> $GITHUB_OUTPUT | |
if ${{ github.event_name }} != 'pull_request'; then | |
echo "Skipping the push steps." | |
echo "PUSH_IMAGE=true" >> $GITHUB_OUTPUT | |
fi | |
fi | |
- name: Upload the Docker image to the container registry | |
id: container_registry_upload | |
uses: mr-smithers-excellent/docker-build-push@v6 | |
with: | |
image: ${{ env.IMAGE_NAME }} | |
tags: ${{ steps.get_version.outputs.VERSION }}, latest | |
registry: ${{ env.REGISTRY }} | |
pushImage: ${{ steps.check_version.outputs.PUSH_IMAGE }} | |
multiPlatform: true | |
platform: linux/amd64,linux/arm64 | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} |