Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 16 additions & 7 deletions .scripts/actions/retry.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#!/usr/bin/env bash

# Retries any command passed to this script a maximum number of $CMD_RETRIES and
# wait $CMD_TIMEOUT between each try. If the command failed $CMD_RETRIES, this
# Initially, the retry args are empty. If the command fails, the retry args are
# set to what the user provided via the RETRY_ARGS env var.
retry_args=""

# Retries any command passed to this script a maximum number of $RETRY_COUNT and
# wait $RETRY_TIMEOUT between each try. If the command failed $RETRY_COUNT, this
# script will return with exit code 1.
for TRY in $(seq 1 "$CMD_RETRIES"); do
"$@"
for TRY in $(seq 1 "$RETRY_COUNT"); do
if [ -z "$retry_args" ]; then
"$@"
else
"$@" "$retry_args"
fi

EXIT_CODE=$?
# If command ran successfully, exit the loop
Expand All @@ -15,11 +23,12 @@ for TRY in $(seq 1 "$CMD_RETRIES"); do
echo "Command failed $TRY time(s)"

# Exit if we reached the number if retries and the command didn't run successfully
if [ "$TRY" == "$CMD_RETRIES" ]; then
if [ "$TRY" == "$RETRY_COUNT" ]; then
echo "Exiting"
exit 1
fi

echo "Waiting for $CMD_TIMEOUT to try again"
sleep "$CMD_TIMEOUT"
retry_args="${RETRY_ARGS:-}"
echo "Waiting for $RETRY_TIMEOUT to try again"
sleep "$RETRY_TIMEOUT"
done
12 changes: 12 additions & 0 deletions publish-helm-chart/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ inputs:
app-version:
description: The app version to set in the Helm Chart
required: true
cosign-retries:
description: The number of times cosign operations should be retried
default: "3"
cosign-retry-timeout:
description: |
Duration to wait before a new cosign operation is retried, format: `NUMBER[SUFFIX]`.
SUFFIX may be 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days.
See `sleep --help` for the full details.
default: "30s"
runs:
using: composite
steps:
Expand Down Expand Up @@ -120,6 +129,9 @@ runs:

- name: Sign Helm Chart
env:
RETRY_TIMEOUT: ${{ inputs.cosign-retry-timeout }}
RETRY_COUNT: ${{ inputs.cosign-retries }}
RETRY_ARGS: --verbose
CHART_REGISTRY_URI: ${{ inputs.chart-registry-uri }}
CHART_REPOSITORY: ${{ inputs.chart-repository }}
GITHUB_DEBUG: ${{ runner.debug }}
Expand Down
5 changes: 3 additions & 2 deletions publish-image-index-manifest/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ runs:
- name: Sign Image Index Manifest
shell: bash
env:
CMD_TIMEOUT: ${{ inputs.cosign-retry-timeout }}
CMD_RETRIES: ${{ inputs.cosign-retries }}
RETRY_TIMEOUT: ${{ inputs.cosign-retry-timeout }}
RETRY_COUNT: ${{ inputs.cosign-retries }}
RETRY_ARGS: --verbose
IMAGE_REPOSITORY: ${{ inputs.image-repository }}
REGISTRY_URI: ${{ inputs.image-registry-uri }}
run: |
Expand Down
10 changes: 6 additions & 4 deletions publish-image/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ runs:
- name: Sign the container image (${{ env.IMAGE_REPO_DIGEST }})
shell: bash
env:
CMD_TIMEOUT: ${{ inputs.cosign-retry-timeout }}
CMD_RETRIES: ${{ inputs.cosign-retries }}
RETRY_TIMEOUT: ${{ inputs.cosign-retry-timeout }}
RETRY_COUNT: ${{ inputs.cosign-retries }}
RETRY_ARGS: --verbose
run: |
set -euo pipefail

Expand All @@ -113,8 +114,9 @@ runs:
- name: Generate SBOM for the container image (${{ env.IMAGE_REPO_DIGEST }})
shell: bash
env:
CMD_TIMEOUT: ${{ inputs.cosign-retry-timeout }}
CMD_RETRIES: ${{ inputs.cosign-retries }}
RETRY_TIMEOUT: ${{ inputs.cosign-retry-timeout }}
RETRY_COUNT: ${{ inputs.cosign-retries }}
RETRY_ARGS: --verbose
IMAGE_MANIFEST_TAG: ${{ inputs.image-manifest-tag }}
IMAGE_REPOSITORY: ${{ inputs.image-repository }}
REGISTRY_URI: ${{ inputs.image-registry-uri }}
Expand Down