- Create check_package_version.yml reusable workflow - Add workspacePath input for flexible package.json location - Fix path concatenation to handle root directory cleanly - Expose version_changed and version outputs - Create check_image_version.yml reusable workflow - Add workspacePath, imageName, registryUrl, registryUsername, and registryNamespace inputs - Make fully generic and portable across different registries - Fix path handling for clean path generation - Rename secret to registryToken for clarity - Update build.yml to use reusable workflows - Replace inline jobs with workflow_call references - Pass all required parameters explicitly - Maintain existing conditional logic in build job Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
92 lines
3.0 KiB
YAML
92 lines
3.0 KiB
YAML
name: Check Image Version
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
workspacePath:
|
|
description: 'Path relative to repo root where package.json is located'
|
|
required: false
|
|
type: string
|
|
default: '.'
|
|
imageName:
|
|
description: 'Docker image name without registry FQDN or username'
|
|
required: true
|
|
type: string
|
|
registryUrl:
|
|
description: 'Docker registry URL (e.g., registry.budakova.org)'
|
|
required: false
|
|
type: string
|
|
default: 'registry.budakova.org'
|
|
registryUsername:
|
|
description: 'Docker registry username'
|
|
required: true
|
|
type: string
|
|
registryNamespace:
|
|
description: 'Docker registry namespace/organization (e.g., knee-cola)'
|
|
required: true
|
|
type: string
|
|
secrets:
|
|
registryToken:
|
|
description: 'Registry access token'
|
|
required: true
|
|
outputs:
|
|
image_exists:
|
|
description: 'Whether the image exists in the registry'
|
|
value: ${{ jobs.check_image.outputs.image_exists }}
|
|
version:
|
|
description: 'Current version from package.json'
|
|
value: ${{ jobs.check_image.outputs.version }}
|
|
|
|
jobs:
|
|
check_image:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
image_exists: ${{ steps.manifest-check.outputs.image_exists }}
|
|
version: ${{ steps.version-read.outputs.version }}
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Read version from package.json
|
|
id: version-read
|
|
run: |
|
|
WORKSPACE_PATH="${{ inputs.workspacePath }}"
|
|
# Clean up path - remove trailing slash if present
|
|
WORKSPACE_PATH="${WORKSPACE_PATH%/}"
|
|
# Handle root directory case
|
|
if [ "$WORKSPACE_PATH" = "." ]; then
|
|
PACKAGE_JSON_PATH="package.json"
|
|
else
|
|
PACKAGE_JSON_PATH="${WORKSPACE_PATH}/package.json"
|
|
fi
|
|
|
|
VERSION=$(node -p "require('./${PACKAGE_JSON_PATH}').version")
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
echo "Checking for image version: $VERSION"
|
|
|
|
- name: Login to Registry
|
|
run: |
|
|
echo "${{ secrets.registryToken }}" | docker login ${{ inputs.registryUrl }} -u "${{ inputs.registryUsername }}" --password-stdin
|
|
|
|
- name: Check if image exists in registry
|
|
id: manifest-check
|
|
run: |
|
|
VERSION=${{ steps.version-read.outputs.version }}
|
|
IMAGE="${{ inputs.registryUrl }}/${{ inputs.registryNamespace }}/${{ inputs.imageName }}:${VERSION}"
|
|
|
|
echo "Checking manifest for image: $IMAGE"
|
|
|
|
if docker manifest inspect "$IMAGE" &>/dev/null; then
|
|
echo "Image exists in registry"
|
|
echo "image_exists=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "Image does not exist in registry"
|
|
echo "image_exists=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Summary
|
|
run: |
|
|
echo "Version: ${{ steps.version-read.outputs.version }}"
|
|
echo "Image exists: ${{ steps.manifest-check.outputs.image_exists }}"
|