Repository navigation
Expand file tree
/
Copy pathscanner-updater-matrix.sh
More file actions
executable file
·72 lines (66 loc) · 2.47 KB
/
Copy pathscanner-updater-matrix.sh
File metadata and controls
executable file
·72 lines (66 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
#
# Build a GitHub Actions matrix of updater/stream pairs that are due
# for a refresh.
#
# Expands stream/ref pairs (from scanner-get-released-tags.sh) against
# per-stream updater lists (from source-config.yaml), then calls
# scanner-updater-check-freshness.sh for each pair. Only due pairs
# are emitted.
#
# Inputs (environment):
# SOURCE_CONFIG — path to source-config.yaml
#
# Outputs (stdout):
# JSON object with "has_due", "has_errors", "errors", and "matrix"
# for GitHub Actions.
#
# Requires: yq, jq, and scanner-get-released-tags.sh and
# scanner-updater-check-freshness.sh in the same repo checkout.
set -euo pipefail
config="${SOURCE_CONFIG:?SOURCE_CONFIG is required}"
for cmd in yq jq; do
if ! command -v "$cmd" &>/dev/null; then
echo "::error::$cmd is required but not found"
exit 1
fi
done
# Read storage location from config.
bucket=$(yq '.storage.bucket' "$config")
prefix=$(yq '.storage.prefix' "$config")
# Expand stream/ref/updater triples, check freshness, emit due pairs.
./.github/workflows/scripts/scanner-get-released-tags.sh \
| jq -r '.[] | "\(.version) \(.ref)"' \
| while read -r stream ref; do
yq ".bundles.\"$stream\" | .[]" "$config" \
| while read -r updater; do
echo "$stream $ref $updater"
done
done \
| while read -r stream ref updater; do
object="gs://${bucket}/${prefix}/${stream}/sources/${updater}.json.zst"
# check-freshness.sh exit codes: 0=fresh, 1=stale/missing, 2=error.
if GCS_OBJECT="$object" \
UPDATER_SOURCE="$updater" \
SOURCE_CONFIG="$config" \
./.github/workflows/scripts/scanner-updater-check-freshness.sh
then
continue
elif [[ $? -eq 1 ]]; then
jq -n \
--arg source "$updater" \
--arg ref "$ref" \
--arg object "$object" \
'{source: $source, ref: $ref, object: $object}'
else
echo "::error::${object}: freshness check failed"
jq -n --arg msg "${object}: freshness check failed" '{error: $msg}'
continue
fi
done \
| jq -s '{
has_due: (map(select(.source)) | length > 0 | tostring),
has_errors: (map(select(.error)) | length > 0 | tostring),
errors: [.[] | .error // empty],
matrix: {include: [.[] | select(.source)]}
}'