3 Commits
v1.4 ... main

2 changed files with 79 additions and 1 deletions

View File

@@ -58,6 +58,13 @@ on:
type: string
default: ""
skip_if_tag_exists:
description: >
If true, skip build when all images already have sha-<commit> tags.
required: false
type: string
default: "false"
env:
description: >
Multiline env vars, one per line: KEY=VALUE
@@ -147,6 +154,9 @@ jobs:
IMAGES: ${{ inputs.images }}
BUILD_ARGS: ${{ inputs.build_args }}
EXTRA_TAGS_INPUT: ${{ inputs.extra_tags }}
CHECKOUT_REPO: ${{ inputs.checkout_repo }}
CHECKOUT_PATH: ${{ inputs.checkout_path }}
SKIP_IF_TAG_EXISTS: ${{ inputs.skip_if_tag_exists }}
CI_TOKEN: ${{ secrets.ci_token }}
TRIVY_SEVERITY: ${{ inputs.trivy_severity }}
run: |
@@ -176,8 +186,38 @@ jobs:
RAW_REF="${{ github.ref }}"
SHA_FULL="${{ github.sha }}"
SOURCE_SHA_FULL="$SHA_FULL"
if [ -n "$CHECKOUT_REPO" ] && [ -d "$CHECKOUT_PATH/.git" ]; then
SOURCE_SHA_FULL=$(git -C "$CHECKOUT_PATH" rev-parse HEAD)
fi
SHA_FULL="$SOURCE_SHA_FULL"
SHA_SHORT="${SHA_FULL:0:12}"
truthy() {
case "${1,,}" in
1|true|yes|y|on) return 0;;
*) return 1;;
esac
}
if truthy "$SKIP_IF_TAG_EXISTS"; then
missing=0
while read -r img; do
IMAGE_NAME=$(echo "$img" | jq -r '.name')
FULL_IMAGE="${{ inputs.registry_host }}/$IMAGE_NAME"
if docker manifest inspect "$FULL_IMAGE:sha-$SHA_SHORT" >/dev/null 2>&1; then
echo "==== Found existing tag $FULL_IMAGE:sha-$SHA_SHORT ===="
else
echo "==== Missing tag $FULL_IMAGE:sha-$SHA_SHORT (will build) ===="
missing=1
fi
done < <(echo "$IMAGES" | jq -c '.[]')
if [ "$missing" -eq 0 ]; then
echo "All images already have sha-$SHA_SHORT tag. Skipping build."
exit 0
fi
fi
VERSION_TAGS=()
if [[ "$RAW_REF" =~ ^refs/tags/v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
VERSION_TAGS+=("v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}")

View File

@@ -101,7 +101,7 @@ jobs:
POSTGRES_PASSWORD: ${{ inputs.postgres_password }}
POSTGRES_DB: ${{ inputs.postgres_db }}
ports:
- 5432:5432
- 5432
options: >-
--health-cmd="${{ inputs.postgres_health_cmd }}"
--health-interval=${{ inputs.postgres_health_interval }}
@@ -123,6 +123,22 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Configure DB env
run: |
if [ "${ACT:-}" = "true" ] || [ "${GITEA_ACTIONS:-}" = "true" ]; then
host="postgres"
port="5432"
else
host="127.0.0.1"
port="${{ job.services.postgres.ports['5432'] }}"
fi
echo "POSTGRES_HOST=$host" >> "$GITHUB_ENV"
echo "POSTGRES_PORT=$port" >> "$GITHUB_ENV"
echo "POSTGRES_USER=${{ inputs.postgres_user }}" >> "$GITHUB_ENV"
echo "POSTGRES_PASSWORD=${{ inputs.postgres_password }}" >> "$GITHUB_ENV"
echo "POSTGRES_DB=${{ inputs.postgres_db }}" >> "$GITHUB_ENV"
echo "DATABASE_URL=postgres://${{ inputs.postgres_user }}:${{ inputs.postgres_password }}@$host:$port/${{ inputs.postgres_db }}" >> "$GITHUB_ENV"
- name: Load env vars
if: ${{ inputs.env != '' }}
run: |
@@ -189,6 +205,28 @@ jobs:
echo "$line" >> "$GITHUB_ENV"
done <<< "${{ inputs.test_env }}"
- name: Wait for postgres
run: |
python - <<'PY'
import os
import socket
import time
host = os.getenv("POSTGRES_HOST", "127.0.0.1")
port = int(os.getenv("POSTGRES_PORT", "5432"))
deadline = time.time() + 60
while True:
try:
with socket.create_connection((host, port), timeout=2):
print(f"Postgres reachable at {host}:{port}")
break
except OSError:
if time.time() > deadline:
raise
time.sleep(1)
PY
- name: Run format check
if: ${{ inputs.format_command != '' }}
run: ${{ inputs.format_command }}