Skip to content
Closed
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
6 changes: 4 additions & 2 deletions .github/scripts/install-oras.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
set -euxo pipefail
: "${ORAS_VERSION:?ORAS_VERSION must be set}"
ORAS_ARCH="$(dpkg --print-architecture)"
curl -fsSL -o oras.tar.gz "https://github.com/oras-project/oras/releases/download/v${ORAS_VERSION}/oras_${ORAS_VERSION}_linux_${ORAS_ARCH}.tar.gz"
curl -fsSL -o oras_checksums.txt "https://github.com/oras-project/oras/releases/download/v${ORAS_VERSION}/oras_${ORAS_VERSION}_checksums.txt"
HERE="$(cd "$(dirname "$0")" && pwd)"
# Retried (with-retry.sh): github.com sometimes answers 503 for a few seconds.
"$HERE/with-retry.sh" curl -fsSL -o oras.tar.gz "https://github.com/oras-project/oras/releases/download/v${ORAS_VERSION}/oras_${ORAS_VERSION}_linux_${ORAS_ARCH}.tar.gz"
"$HERE/with-retry.sh" curl -fsSL -o oras_checksums.txt "https://github.com/oras-project/oras/releases/download/v${ORAS_VERSION}/oras_${ORAS_VERSION}_checksums.txt"
# Match the filename exactly ($2 == f): a substring match can also hit
# a sibling entry like *.tar.gz.sbom.json and return two hashes.
EXPECTED_SHA=$(awk -v f="oras_${ORAS_VERSION}_linux_${ORAS_ARCH}.tar.gz" '$2 == f {print $1}' oras_checksums.txt)
Expand Down
16 changes: 16 additions & 0 deletions .github/scripts/tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,22 @@ CF="$cf3" RETRY_DELAY=0 RETRY_MAX=2 "$WR" bash -c 'echo $(( $(cat "$CF") + 1 ))
"$WR" >/dev/null 2>&1; rc=$?
[ "$rc" = 2 ] && echo " ok: no-args -> exit 2 (usage)" || { echo " FAIL: no-args rc $rc (want 2)"; fail=1; }

echo "== install-oras.sh =="
# REGRESSION: a release download that fails once (github.com answering 503) is retried;
# the checksum is still verified and oras installed. curl and sudo are stubs.
wO="$(mktemp -d)"; tmpdirs+=("$wO")
( cd "$wO" && ORAS_VERSION=1.2.0 STUB_CURL=flaky STUB_FLAKY_MARK="$wO/failed-once" RETRY_DELAY=0 STUB_LOG="$wO/stub.log" "${ROOT}/.github/scripts/install-oras.sh" ) >/dev/null 2>&1; rcO=$?
assert_eq "$rcO" "0" "O transient download failure is retried -> exit 0"
assert_eq "$(grep -c '^curl ' "$wO/stub.log")" "3" "O three curl calls (1 failure + 1 retry + checksums)"
assert_contains "$(cat "$wO/stub.log")" "sudo mv oras /usr/local/bin/oras" "O oras installed after the retry"

# a download that keeps failing still fails the script, after RETRY_MAX attempts
wOf="$(mktemp -d)"; tmpdirs+=("$wOf")
( cd "$wOf" && ORAS_VERSION=1.2.0 STUB_CURL=fail RETRY_DELAY=0 STUB_LOG="$wOf/stub.log" "${ROOT}/.github/scripts/install-oras.sh" ) >/dev/null 2>&1; rcOf=$?
assert_eq "$rcOf" "22" "Of permanent download failure -> curl's exit code (22)"
assert_eq "$(grep -c '^curl ' "$wOf/stub.log")" "3" "Of download attempted RETRY_MAX (default 3) times before giving up"
assert_not_contains "$(cat "$wOf/stub.log")" "sudo mv" "Of nothing installed"

echo "== cve-aggregate.sh =="
CVE_FIX="${ROOT}/.github/scripts/tests/fixtures/cve"
AGG="$(mktemp)"; tmpdirs+=("$AGG")
Expand Down
32 changes: 32 additions & 0 deletions .github/scripts/tests/stubs/curl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Stub curl for install-oras.sh: writes a tiny oras tarball, or a checksums file
# matching it, to the -o target. Failure knobs: STUB_CURL=fail (every call), or
# STUB_CURL=flaky (first call only, like github.com answering 503 once; the marker
# file STUB_FLAKY_MARK records that the one failure already happened). Both exit
# 22, which is what `curl -f` returns for an HTTP error.
echo "curl $*" >> "${STUB_LOG:-/dev/null}"
out=""; url=""
while [ "$#" -gt 0 ]; do
case "$1" in
-o) out="$2"; shift ;;
http*) url="$1" ;;
esac
shift
done
fail503() { echo "curl: (22) The requested URL returned error: 503" >&2; exit 22; }
[ "${STUB_CURL:-ok}" = "fail" ] && fail503
if [ "${STUB_CURL:-ok}" = "flaky" ] && [ ! -e "${STUB_FLAKY_MARK:?}" ]; then
: > "$STUB_FLAKY_MARK"
fail503
fi
case "$url" in
*checksums.txt)
sha="$(sha256sum oras.tar.gz | cut -d' ' -f1)"
for arch in amd64 arm64; do
echo "${sha} oras_${ORAS_VERSION}_linux_${arch}.tar.gz"
done > "$out" ;;
*)
tmp="$(mktemp -d)"; echo "stub oras binary" > "${tmp}/oras"
tar -czf "$out" -C "$tmp" oras; rm -rf "$tmp" ;;
esac
exit 0
4 changes: 4 additions & 0 deletions .github/scripts/tests/stubs/sudo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Stub sudo: records the call and runs nothing, so the tests never touch the system.
echo "sudo $*" >> "${STUB_LOG:-/dev/null}"
exit 0
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ jobs:
run: |
set -eux
COPA_ARCH="$(dpkg --print-architecture)"
curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_${COPA_ARCH}.tar.gz"
curl -fsSL -o copacetic_checksums.txt "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copacetic_checksums.txt"
_ci/.github/scripts/with-retry.sh curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_${COPA_ARCH}.tar.gz"
_ci/.github/scripts/with-retry.sh curl -fsSL -o copacetic_checksums.txt "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copacetic_checksums.txt"
# Verify checksum before extracting. Match the filename exactly ($2 == f):
# a substring match also hits copa_..._linux_..._tar.gz.sbom.json (two hashes).
EXPECTED_SHA=$(awk -v f="copa_${COPA_VERSION}_linux_${COPA_ARCH}.tar.gz" '$2 == f {print $1}' copacetic_checksums.txt)
Expand Down
Loading