Skip to content

Commit 14c02f6

Browse files
committed
Scope publish workflow to one cli version per run.
1 parent 144e38f commit 14c02f6

2 files changed

Lines changed: 76 additions & 39 deletions

File tree

.github/workflows/publish.yml

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: publish
33

44
on:
55
workflow_dispatch:
6+
inputs:
7+
stellar_cli_version:
8+
description: stellar-cli version to publish (must be declared in builds.json, e.g. 26.0.0)
9+
required: true
10+
type: string
611
push:
712
tags:
813
- v*
@@ -19,16 +24,30 @@ jobs:
1924
runs-on: ubuntu-24.04
2025
outputs:
2126
matrix: ${{ steps.resolve.outputs.matrix }}
27+
stellar_cli_version: ${{ steps.scope.outputs.version }}
2228
steps:
2329
- name: checkout
2430
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2531
- name: install check-jsonschema
2632
run: pipx install check-jsonschema
2733
- name: validate builds.json
2834
run: ./scripts/validate-json.sh
35+
- name: scope to one cli version
36+
id: scope
37+
run: |
38+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
39+
version="${{ inputs.stellar_cli_version }}"
40+
else
41+
tag="${GITHUB_REF#refs/tags/}"
42+
version="${tag#v}"
43+
fi
44+
echo "version=$version" >> "$GITHUB_OUTPUT"
2945
- name: resolve matrix
3046
id: resolve
31-
run: echo "matrix=$(./scripts/resolve-matrix.sh)" >> "$GITHUB_OUTPUT"
47+
run: |
48+
matrix="$(./scripts/resolve-matrix.sh \
49+
--stellar-cli-version "${{ steps.scope.outputs.version }}")"
50+
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
3251
3352
build:
3453
name: ${{ matrix.stellar_cli_version }} rust${{ matrix.rust_version }} ${{ matrix.arch }}
@@ -93,8 +112,10 @@ jobs:
93112
94113
manifest:
95114
name: assemble manifest lists
96-
needs: build
115+
needs: [matrix, build]
97116
runs-on: ubuntu-24.04
117+
env:
118+
STELLAR_CLI_VERSION: ${{ needs.matrix.outputs.stellar_cli_version }}
98119
steps:
99120
- name: checkout
100121
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -107,16 +128,14 @@ jobs:
107128
password: ${{ secrets.DOCKERHUB_TOKEN }}
108129
- name: create manifest list per (cli, rust) pair
109130
run: |
110-
while IFS= read -r row; do
111-
cli="$(jq -r '.cli' <<<"$row")"
112-
rust="$(jq -r '.rust' <<<"$row")"
131+
while IFS= read -r rust; do
113132
list_tag="$(./scripts/tag-names.sh \
114-
--stellar-cli-version "$cli" --rust-version "$rust")"
133+
--stellar-cli-version "$STELLAR_CLI_VERSION" --rust-version "$rust")"
115134
amd64_tag="$(./scripts/tag-names.sh \
116-
--stellar-cli-version "$cli" --rust-version "$rust" \
135+
--stellar-cli-version "$STELLAR_CLI_VERSION" --rust-version "$rust" \
117136
--platform linux/amd64)"
118137
arm64_tag="$(./scripts/tag-names.sh \
119-
--stellar-cli-version "$cli" --rust-version "$rust" \
138+
--stellar-cli-version "$STELLAR_CLI_VERSION" --rust-version "$rust" \
120139
--platform linux/arm64)"
121140
if docker buildx imagetools inspect "$REGISTRY:$list_tag" >/dev/null 2>&1; then
122141
echo "::error::tag $REGISTRY:$list_tag already exists; manifest lists are immutable and never overwritten"
@@ -128,17 +147,18 @@ jobs:
128147
"$REGISTRY:$amd64_tag" \
129148
"$REGISTRY:$arm64_tag"
130149
echo "::endgroup::"
131-
done < <(jq -c '
150+
done < <(jq -r --arg v "$STELLAR_CLI_VERSION" '
132151
.stellar_cli_versions[]
133-
| .version as $v
152+
| select(.version == $v)
134153
| .rust_versions[]
135-
| {cli: $v, rust: .}
136154
' builds.json)
137155
138156
aliases:
139157
name: publish moving aliases
140-
needs: manifest
158+
needs: [matrix, manifest]
141159
runs-on: ubuntu-24.04
160+
env:
161+
STELLAR_CLI_VERSION: ${{ needs.matrix.outputs.stellar_cli_version }}
142162
steps:
143163
- name: checkout
144164
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -151,25 +171,26 @@ jobs:
151171
password: ${{ secrets.DOCKERHUB_TOKEN }}
152172
- name: publish :<cli> and :latest aliases
153173
run: |
174+
default_rust="$(jq -r --arg v "$STELLAR_CLI_VERSION" \
175+
'.stellar_cli_versions[] | select(.version == $v) | .default_rust' \
176+
builds.json | head -n1)"
177+
target_tag="$(./scripts/tag-names.sh \
178+
--stellar-cli-version "$STELLAR_CLI_VERSION" \
179+
--rust-version "$default_rust")"
180+
target="$REGISTRY:$target_tag"
181+
182+
echo "::group::alias $REGISTRY:$STELLAR_CLI_VERSION -> $target"
183+
docker buildx imagetools create --tag "$REGISTRY:$STELLAR_CLI_VERSION" "$target"
184+
echo "::endgroup::"
185+
154186
newest_cli="$(./scripts/newest-pair.sh --stellar-cli-version)"
155-
while IFS= read -r cli; do
156-
default_rust="$(jq -r --arg cli "$cli" \
157-
'.stellar_cli_versions[] | select(.version == $cli) | .default_rust' \
158-
builds.json | head -n1)"
159-
target_tag="$(./scripts/tag-names.sh \
160-
--stellar-cli-version "$cli" --rust-version "$default_rust")"
161-
target="$REGISTRY:$target_tag"
162-
163-
echo "::group::alias $REGISTRY:$cli -> $target"
164-
docker buildx imagetools create --tag "$REGISTRY:$cli" "$target"
187+
if [ "$STELLAR_CLI_VERSION" = "$newest_cli" ]; then
188+
echo "::group::alias $REGISTRY:latest -> $target"
189+
docker buildx imagetools create --tag "$REGISTRY:latest" "$target"
165190
echo "::endgroup::"
166-
167-
if [ "$cli" = "$newest_cli" ]; then
168-
echo "::group::alias $REGISTRY:latest -> $target"
169-
docker buildx imagetools create --tag "$REGISTRY:latest" "$target"
170-
echo "::endgroup::"
171-
fi
172-
done < <(jq -r '.stellar_cli_versions[].version' builds.json)
191+
else
192+
echo "cli $STELLAR_CLI_VERSION is not the newest ($newest_cli); skipping :latest"
193+
fi
173194
174195
complete:
175196
if: always()

scripts/resolve-matrix.sh

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ source "$script_dir/lib/common.sh"
1515

1616
usage() {
1717
cat <<'EOF'
18-
Usage: scripts/resolve-matrix.sh [--compact|--pretty] [--help]
18+
Usage: scripts/resolve-matrix.sh [--stellar-cli-version <v>] [--compact|--pretty] [--help]
1919
2020
Prints {"include": [...]} on stdout. Each include entry has:
2121
arch amd64 | arm64
@@ -26,32 +26,47 @@ Prints {"include": [...]} on stdout. Each include entry has:
2626
stellar_cli_version e.g. 26.0.0
2727
2828
Options:
29-
--compact One-line JSON (default; matches what fromJson() consumes).
30-
--pretty Pretty-printed JSON, for human inspection.
31-
--help Show this message.
29+
--stellar-cli-version <v> Limit output to one cli version (must be a
30+
declared entry in builds.json). Used by the
31+
publish workflow which scopes each run to a
32+
single release. Without this flag, every
33+
declared cli is included.
34+
--compact One-line JSON (default; matches what fromJson()
35+
consumes).
36+
--pretty Pretty-printed JSON, for human inspection.
37+
--help Show this message.
3238
EOF
3339
}
3440

3541
main() {
36-
local mode="compact"
42+
local mode="compact" only_cli=""
3743

3844
while [ $# -gt 0 ]; do
3945
case "$1" in
40-
--compact) mode="compact"; shift;;
41-
--pretty) mode="pretty"; shift;;
42-
-h|--help) usage; exit 0;;
43-
*) err "unknown argument: $1"; usage; exit 1;;
46+
--stellar-cli-version) only_cli="$2"; shift 2;;
47+
--compact) mode="compact"; shift;;
48+
--pretty) mode="pretty"; shift;;
49+
-h|--help) usage; exit 0;;
50+
*) err "unknown argument: $1"; usage; exit 1;;
4451
esac
4552
done
4653

4754
preflight_checks jq
4855

56+
if [ -n "$only_cli" ]; then
57+
local found
58+
found="$(builds_json --arg v "$only_cli" \
59+
'.stellar_cli_versions[] | select(.version == $v) | .version' | head -n1)"
60+
test -n "$found" \
61+
|| die "stellar-cli $only_cli is not declared in builds.json"
62+
fi
63+
4964
local jq_flags=(-c)
5065
if [ "$mode" = "pretty" ]; then
5166
jq_flags=()
5267
fi
5368

54-
builds_json "${jq_flags[@]}" '
69+
builds_json "${jq_flags[@]}" --arg only "$only_cli" '
5570
. as $b
5671
| def archs: ["amd64", "arm64"];
5772
def digest_for(rust):
@@ -70,6 +85,7 @@ main() {
7085
{
7186
include:
7287
[ .stellar_cli_versions[]
88+
| select($only == "" or .version == $only)
7389
| . as $e
7490
| $e.rust_versions[] as $rust
7591
| archs[] as $arch

0 commit comments

Comments
 (0)