|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -Eeuo pipefail |
| 3 | + |
| 4 | +dir="$(dirname "$BASH_SOURCE")" |
| 5 | + |
| 6 | +tmpJson="$(mktemp)" |
| 7 | +trap 'rm $tmpJson' EXIT |
| 8 | + |
| 9 | +jq -n -c ' |
| 10 | + # input arch and test values |
| 11 | + # output unique buildId string |
| 12 | + def buildId($arch): |
| 13 | + [$arch, .[] | tostring] | join("-") |
| 14 | + ; |
| 15 | + [ |
| 16 | + # add new test cases here |
| 17 | + # each item will be used for each architecture generated |
| 18 | + # [ ".build.resloved", "count", "skips" ] |
| 19 | + [ null, 1, 0 ], # buildable, tried once |
| 20 | + [ null, 23, 0 ], # buildable, tried many but less than skip threshold |
| 21 | + [ null, 24, 0 ], # buildable, tried many, just on skip threshold |
| 22 | + [ null, 25, 23 ], # buildable, final skip |
| 23 | + [ null, 25, 24 ], # buildable, no longer skipped |
| 24 | + [ {}, 3, 0 ], # build "complete" (not queued or skipped) |
| 25 | + empty # trailing comma |
| 26 | + ] as $data |
| 27 | + | [ "amd64", "arm32v7", "windows-amd64" ] |
| 28 | + | to_entries |
| 29 | + | ( |
| 30 | + # making a list of build objects as a "builds.json" |
| 31 | + map( |
| 32 | + (.key | tostring) as $archindex |
| 33 | + | .value as $arch |
| 34 | + | $data | to_entries[] |
| 35 | + | (.value | buildId($arch)) as $buildId |
| 36 | + | .key as $index |
| 37 | + | .value[0] as $resolved |
| 38 | + | { |
| 39 | + ($buildId): { |
| 40 | + $buildId, |
| 41 | + "build": { |
| 42 | + $arch, |
| 43 | + $resolved, |
| 44 | + "resolvedParents": { |
| 45 | + (if $arch | startswith("windows") then |
| 46 | + "windows:ltsc2022" |
| 47 | + else |
| 48 | + "debian:fake" |
| 49 | + end |
| 50 | + ): { |
| 51 | + "manifests": [{ |
| 52 | + "platform": ( |
| 53 | + if $arch | startswith("windows") then |
| 54 | + { |
| 55 | + "architecture": "amd64", |
| 56 | + "os": "windows", |
| 57 | + "os.version": "10.0.20348.12345" |
| 58 | + } |
| 59 | + else |
| 60 | + { |
| 61 | + "architecture": ($arch | rtrimstr("v6")|rtrimstr("v7")|rtrimstr("v8")), |
| 62 | + "os": "linux" |
| 63 | + } |
| 64 | + end |
| 65 | + ) |
| 66 | + }] |
| 67 | + } |
| 68 | + } |
| 69 | + }, |
| 70 | + "source": { |
| 71 | + "arches": { |
| 72 | + ($arch): { |
| 73 | + "tags": [("a","b","c") | . * ($index + 1)] |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + ) |
| 80 | + | add |
| 81 | + ), ( |
| 82 | + # making a list of minimal build records like in "past-jobs.json" |
| 83 | + map( |
| 84 | + (.key | tostring) as $archindex |
| 85 | + | .value as $arch |
| 86 | + | $data | to_entries[] |
| 87 | + | (.value | buildId($arch)) as $buildId |
| 88 | + | .value[1] as $count |
| 89 | + | .value[2] as $skips |
| 90 | + | { |
| 91 | + ($buildId|tostring): { |
| 92 | + $count, |
| 93 | + $skips |
| 94 | + } |
| 95 | + } |
| 96 | + ) |
| 97 | + | add |
| 98 | + ) |
| 99 | +' > "$tmpJson" |
| 100 | + |
| 101 | +head -n1 "$tmpJson" | jq --tab '.' > "$dir/in.json" |
| 102 | +tail -n1 "$tmpJson" | jq --tab '.' > "$dir/past-jobs.json" |
0 commit comments