Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
96 changes: 96 additions & 0 deletions .github/workflows/publish-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Build and Push Docker Image

on:
schedule:
- cron: '0 0 * * 0' # Runs on every Sunday at midnight UTC
workflow_dispatch:

env:
# Default to GitHub repo name, but allows to set a separate docker repo name
# using GitHub repo secrets.
DOCKER_REPO: ${{ secrets.DOCKER_REPO || github.repository }}

jobs:
build:
runs-on: ubuntu-latest

steps:
# Checkout the repository
- name: Checkout repository
uses: actions/checkout@v4

# Log in to DockerHub using stored credentials
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Add Jottacloud repo in order to get the newest jotta-cli version
- name: Add Jottacloud repo
run: |
set -e
sudo apt-get update
sudo curl -fsSL https://repo.jotta.cloud/public.asc -o /usr/share/keyrings/jotta.gpg
echo "deb [signed-by=/usr/share/keyrings/jotta.gpg] https://repo.jotta.cloud/debian debian main" | sudo tee /etc/apt/sources.list.d/jotta-cli.list
sudo apt-get update

# Get the latest available jotta-cli version from APT
- name: Get latest jotta-cli version
run: |
VERSION=$(apt-cache madison jotta-cli | awk '{print $3}' | sort -V | tail -n1)
if [ -z "$VERSION" ]; then
echo "Error: Unable to fetch jotta-cli version."
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV

# Get the latest pushed Docker image version from Docker Hub
# This uses the tag names, and excludes the "latest" tag
- name: Get latest published Docker image version
run: |
DOCKER_VERSION=$(curl -s "https://registry.hub.docker.com/v2/repositories/${{ env.DOCKER_REPO }}/tags" | \
jq -r '.results[].name' | grep -v '^latest$' | awk -F '-' '{print $1}' | sort -V | tail -n1)
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pipeline parsing logic assumes tag format with '-' delimiter but doesn't handle cases where tags might not contain '-'. This could cause awk -F '-' '{print $1}' to fail or return unexpected results for tags without dashes.

Suggested change
jq -r '.results[].name' | grep -v '^latest$' | awk -F '-' '{print $1}' | sort -V | tail -n1)
jq -r '.results[].name' | grep -v '^latest$' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n1)

Copilot uses AI. Check for mistakes.
echo "DOCKER_VERSION=$DOCKER_VERSION" >> $GITHUB_ENV

# Compare versions; exit early if no update is needed
- name: Compare versions and decide whether to build
run: |
if [ "${{ env.VERSION }}" == "${{ env.DOCKER_VERSION }}" ]; then
echo "No update needed. Exiting."
exit 0
else
echo "New version detected: ${{ env.VERSION }} (Latest Docker version: ${{ env.DOCKER_VERSION }})"
fi

# Enable QEMU for multi-platform builds
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

# Enable Buildx for advanced Docker builds
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Set date variable for image tags
- name: Set the date variable
run: |
DATE=$(date +%Y%m%d) # Get the current date in yyyyMMdd format
echo "DATE=$DATE" >> $GITHUB_ENV

# Build and push the Docker image for multiple platforms
- name: Build and push Docker image
run: |
IMAGE_TAG="${{ env.VERSION }}-${{ env.DATE }}"
docker buildx build --platform linux/amd64,linux/arm64/v8 \
-t ${{ env.DOCKER_REPO }}:latest \
-t ${{ env.DOCKER_REPO }}:${IMAGE_TAG} \
--push .

# Tag the Git repository with the new version and push the tag
- name: Tag and push Git version
run: |
IMAGE_TAG="${{ env.VERSION }}-${{ env.DATE }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
git tag "${IMAGE_TAG}" -a -m "jotta-cli ${{ env.VERSION }}"
git push --tags
20 changes: 20 additions & 0 deletions .github/workflows/update-dockerhub-readme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Update README on Docker Hub
on:
push:
branches:
- main
paths:
- 'README.md'

jobs:
update_readme:
runs-on: ubuntu-latest
steps:
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ github.repository }}
readme-filepath: ./README.md
short-description: ${{ github.event.repository.description }}