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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#!/usr/bin/env bash
# Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE
#
# local-ci-04-upload.sh — the packages of release/<TAG>/ onto the draft.
#
# Rickub only accepts uploads from the token of a CI job. So this pushes a
# temporary orphan branch holding the packages and a one-job workflow, waits for
# the job, and deletes the branch, whatever happened. The local checkout is
# never touched.
source "$(dirname "$0")/local-ci-00-common.sh"
load_token
branch="local-ci-publish-${TAG}"
run_timeout_seconds=900
branch_pushed=""
remove_branch() {
if [ -n "${branch_pushed}" ]; then
echo "==> deleting the branch ${branch}"
git -C "${work}/branch" push -q "${git_url}" --delete "${branch}" \
|| echo "⚠️ could not delete ${branch}: delete it by hand"
fi
cleanup_work
}
trap remove_branch EXIT
[ -f "${assets_dir}/SHA256SUMS" ] || { echo "❌ no ${assets_dir}/SHA256SUMS: run local-ci-02-build.sh"; exit 2; }
[ "$(release_field draft)" = "true" ] || { echo "❌ ${TAG} is not a draft: run local-ci-03-create-draft.sh"; exit 1; }
echo "==> preparing the temporary branch"
git init -q -b "${branch}" "${work}/branch"
mkdir -p "${work}/branch/assets" "${work}/branch/.github/workflows"
# What goes up is what SHA256SUMS lists, and SHA256SUMS itself.
while read -r _ name; do
cp "${assets_dir}/${name}" "${work}/branch/assets/"
done < "${assets_dir}/SHA256SUMS"
cp "${assets_dir}/SHA256SUMS" "${work}/branch/assets/"
printf '%s\n' "${TAG}" > "${work}/branch/TAG"
cat > "${work}/branch/.github/workflows/local-ci-publish.yml" <<'WORKFLOW'
name: local ci publish
on:
push:
branches:
- "local-ci-publish-*"
permissions:
contents: write
jobs:
upload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Upload the binaries to the release
env:
GITHUB_TOKEN: ${{ github.token }}
run: bash ./upload.sh
WORKFLOW
cat > "${work}/branch/upload.sh" <<'UPLOAD'
#!/usr/bin/env bash
set -euo pipefail
tag="$(cat TAG)"
api="${GITHUB_API_URL%/}/repos/${GITHUB_REPOSITORY}"
config="$(mktemp)"
printf 'header = "Authorization: Bearer %s"\n' "${GITHUB_TOKEN}" > "${config}"
curl -fsS -K "${config}" "${api}/releases?per_page=100" > releases.json
upload_url="$(jq -r --arg tag "${tag}" '[.[] | select(.tag_name == $tag)][0].upload_url // empty' releases.json | sed 's/{[^}]*}$//')"
[ -n "${upload_url}" ] || { echo "::error::no release ${tag} visible to the job"; exit 1; }
for file in assets/*; do
name="$(basename "${file}")"
status="$(curl -sS -o response.json -w '%{http_code}' -K "${config}" -X POST \
-H 'Content-Type: application/octet-stream' --data-binary @"${file}" "${upload_url}?name=${name}")"
[ "${status}" = "201" ] || { echo "::error::HTTP ${status} uploading ${name}: $(cat response.json)"; exit 1; }
echo "uploaded ${name}"
done
release_id="$(jq -r --arg tag "${tag}" '[.[] | select(.tag_name == $tag)][0].id' releases.json)"
curl -fsS -K "${config}" "${api}/releases/${release_id}/assets" | jq -r '.[] | "asset \(.name) \(.size)"'
UPLOAD
git -C "${work}/branch" add -A
git -C "${work}/branch" -c user.name="${handle}" -c user.email="${handle}@users.noreply.rickub.com" commit -q -m "local ci: temporary branch to publish ${TAG}"
head_sha="$(git -C "${work}/branch" rev-parse HEAD)"
echo " $(du -sh "${work}/branch/assets" | cut -f1) of packages"
echo "==> pushing ${branch}"
git -C "${work}/branch" push -q "${git_url}" "HEAD:refs/heads/${branch}"
branch_pushed="yes"
echo "==> waiting for the CI job"
deadline=$(( SECONDS + run_timeout_seconds ))
run_number=""
run_status=""
while [ "${SECONDS}" -lt "${deadline}" ]; do
sleep 10
status="$(call GET /actions/runs)"
[ "${status}" = "200" ] || continue
run="$(jq -c --arg sha "${head_sha}" '[.items[] | select(.head_sha == $sha)][0] // empty' "${work}/body")"
[ -n "${run}" ] || continue
run_number="$(jq -r '.number' <<<"${run}")"
run_status="$(jq -r '.status' <<<"${run}")"
echo " run ${run_number}: ${run_status}"
case "${run_status}" in
queued | pending | running | in_progress | waiting) ;;
*) break ;;
esac
done
if [ -n "${run_number}" ] && [ "$(call GET "/actions/runs/${run_number}/logs")" = "200" ]; then
jq -r '.jobs[].log // empty' "${work}/body" > "${work}/run.log"
grep -E '(^| )(uploaded |asset |::error::)' "${work}/run.log" | cut -c1-160 || true
fi
[ "${run_status}" = "success" ] || { echo "❌ the job did not succeed (run ${run_number:-none}: ${run_status:-no run seen})"; exit 1; }
expected="$(find "${work}/branch/assets" -type f | wc -l | tr -d ' ')"
uploaded="$(grep -cE '(^| )asset ' "${work}/run.log" || true)"
[ "${uploaded}" = "${expected}" ] || { echo "❌ ${uploaded} assets on the release, ${expected} expected"; exit 1; }
echo "✅ ${expected} files on the draft ${TAG}"
|