Repository navigation
Expand file tree
/
Copy pathrelease-make-latest.sh
More file actions
executable file
·171 lines (164 loc) · 9.05 KB
/
Copy pathrelease-make-latest.sh
File metadata and controls
executable file
·171 lines (164 loc) · 9.05 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env bash
# Makes a stable release Latest once every installer on it is signed, then checks the update feed
# the apps read when the release is Latest.
#
# Run from the repository root by the attach job of Desktop macOS signing and of Desktop Windows
# signing, after each has attached its signed installers. Whichever of the two finishes second
# makes the release Latest, so `releases/latest/download/<fixed name>` never serves an unsigned
# installer: until then it keeps serving the previous release's signed ones.
#
# Env:
# RELEASE_TAG the release, such as v0.3.0
# MAKE_LATEST `true` when publish-release.yml decided this release becomes Latest
# GITHUB_REPOSITORY and GH_TOKEN, for `gh`
# FEED_RETRY_DELAY seconds between reads of the update feed (default 15)
# HOLD_LATEST the repository variable RELEASE_HOLD_LATEST: release tags, separated by
# spaces or commas, that are signed and published but kept from Latest for a
# staged rollout, such as `v1.1.0`
#
# A stable release is signed when it carries every fixed download name and a latest.json that lists
# every platform (scripts/release-update-feed.sh --platforms). On a stable release only the signing
# runs attach those: publish-release.yml attaches the unsigned installers under their versioned
# names alone (scripts/release-attach-installers.sh). Mac signing attaches both Mac names and lists
# both Mac archives in latest.json, and Windows signing attaches the Windows name and lists the
# Windows installer there. So a release never becomes Latest with a feed that leaves a platform
# behind: an app on it would never be offered the release, or any after it.
#
# Only when publish-release.yml said the release becomes Latest, and only when no newer release has
# become Latest since (scripts/release-becomes-latest.sh). Making it Latest also starts Downloads
# sync, so downloads.copilotkit.ai serves the same signed installers; the job needs `actions: write`.
# And it removes the installers of every older release from GitHub
# (scripts/release-older-installers.sh), with the job's `contents: write`.
set -euo pipefail
: "${RELEASE_TAG:?RELEASE_TAG must name the release}"
: "${GITHUB_REPOSITORY:?GITHUB_REPOSITORY must name the repository}"
make_latest="${MAKE_LATEST:-false}"
delay="${FEED_RETRY_DELAY:-15}"
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
older_failed=false
# Ends a run that got this far. The feed is checked whatever happened to the older installers, and
# a removal that failed then fails the run.
finish() {
if [ "$older_failed" = true ]; then
echo "::error::$RELEASE_TAG is Latest, but the installers of older releases were not all removed. Run scripts/release-older-installers.sh github again (docs/releasing.md, \"Older installers\")."
exit 1
fi
exit 0
}
# Whether a feed is for `version` and lists `platform` with a URL and a signature.
lists() {
jq -e --arg version "$2" --arg platform "$3" '
.version == $version and
((.platforms // {})[$platform] | (.url | type) == "string" and (.url | length) > 0
and (.signature | type) == "string" and (.signature | length) > 0)
' "$1" > /dev/null 2>&1
}
latest_tag() {
local out
if out="$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq .tag_name 2>&1)"; then
printf '%s\n' "$out"
elif grep -q 'HTTP 404' <<<"$out"; then
printf '\n'
else
echo "::error::Could not read the current latest release: $out" >&2
return 1
fi
}
if [ "$make_latest" = true ]; then
# Assigned first: a failure inside a command's argument would not stop the script.
attached="$(gh release view "$RELEASE_TAG" -R "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name')"
required="$("$root/scripts/release-download-names.sh" --all)"
missing=()
while IFS= read -r name; do
if ! grep -qxF "$name" <<<"$attached"; then
missing+=("$name")
fi
done < <(printf '%s\n%s\n' latest.json "$required")
if [ "${#missing[@]}" -eq 0 ]; then
feed="$(mktemp -d "${RUNNER_TEMP:-${TMPDIR:-/tmp}}/release-feed.XXXXXX")"
gh release download "$RELEASE_TAG" -R "$GITHUB_REPOSITORY" --pattern latest.json --dir "$feed" --clobber
while IFS= read -r platform; do
if ! lists "$feed/latest.json" "${RELEASE_TAG#v}" "$platform"; then
missing+=("$platform in latest.json")
fi
done < <("$root/scripts/release-update-feed.sh" --platforms)
fi
if [ "${#missing[@]}" -gt 0 ]; then
echo "$RELEASE_TAG is not Latest yet: it still needs the signed ${missing[*]}. The signing run that attaches the last of them makes it Latest."
else
becomes="$(VERSION="$RELEASE_TAG" PRERELEASE=false "$root/scripts/release-becomes-latest.sh")"
held=false
holds="${HOLD_LATEST:-}"
for hold in ${holds//,/ }; do
if [ "$hold" = "$RELEASE_TAG" ]; then held=true; fi
done
if [ "$becomes" = true ] && [ "$held" = true ]; then
# A staged rollout: the release stays published, signed and not Latest, so releases/latest,
# downloads.copilotkit.ai/latest/ and both update feeds keep serving the release before it.
# Its signed files go to rollout/<tag>/ instead, which the edge function hands to the share
# of viewers its key value store names (docs/releasing.md, "Staged rollout").
# Assigned first: a failure inside a command's argument would not stop the script.
kept="$(latest_tag)"
echo "$RELEASE_TAG is held back from Latest (RELEASE_HOLD_LATEST), so $kept stays Latest."
gh workflow run downloads-sync.yml -R "$GITHUB_REPOSITORY" --ref main \
-f tag="$RELEASE_TAG" -f rollout=true
echo "Started Downloads sync, which copies its signed installers to downloads.copilotkit.ai/rollout/$RELEASE_TAG/."
elif [ "$becomes" = true ]; then
# The security floor stays where the apps read it, beside latest.json on the Latest release
# (scripts/release-security-floor.sh), so it is carried to this release before it becomes Latest.
"$root/scripts/release-security-floor.sh" "$RELEASE_TAG"
gh release edit "$RELEASE_TAG" -R "$GITHUB_REPOSITORY" --latest
echo "$RELEASE_TAG is now the latest release."
# downloads.copilotkit.ai mirrors the Latest release (scripts/downloads-sync.sh). An edit made
# with the workflow's token starts no workflow, and a dispatch does, so the sync is started
# here rather than by the release changing. It also runs every six hours in case this fails.
gh workflow run downloads-sync.yml -R "$GITHUB_REPOSITORY" --ref main
echo "Started Downloads sync, which copies its signed installers to downloads.copilotkit.ai."
# A fresh install from an older installer lays out this release's server stack, which an
# older app may not set up as it needs, so the installers of every older release go
# (scripts/release-older-installers.sh). Their feeds, updater archives, image lists and
# source stay, for the installs that update and repair from them. A failure here does not
# stop the feed check below; the run fails after it, so it is seen and run again.
if ! "$root/scripts/release-older-installers.sh" github; then
older_failed=true
fi
else
echo "A newer release is already Latest, so $RELEASE_TAG stays as it is."
fi
fi
fi
# Installed apps read only the Latest release's feed. A release that is not Latest, such as one
# still waiting for a signing run, a patch to an older line or a release signed again by hand, has
# nothing here to check.
current="$(latest_tag)"
if [ "$current" != "$RELEASE_TAG" ]; then
echo "$RELEASE_TAG is not the latest release, so installed apps do not read its feed. Not checking it."
finish
fi
# Read back what installed apps will read: the release's own feed, compiled into them, fetched the
# way they fetch it, redirects and all. An endpoint that answers with a web page, or a Latest release
# that is not this one, fails here instead of failing silently in every app. The apps ask
# downloads.copilotkit.ai first, which Downloads sync (started above) fills with a checked copy of
# this same file a few minutes later, and fall back to this one when it does not answer.
endpoint="$(jq -r '[.plugins.updater.endpoints[] | select(startswith("https://github.com/"))][0]' \
"$root/desktop/src-tauri/tauri.macos-signing.conf.json")"
expected="${RELEASE_TAG#v}"
for attempt in 1 2 3 4 5; do
# The asset may have been uploaded seconds ago; give the download redirect a moment to catch up.
if curl -fsSL --retry 3 "$endpoint" -o feed.json; then
unlisted=()
while IFS= read -r platform; do
if ! lists feed.json "$expected" "$platform"; then
unlisted+=("$platform")
fi
done < <("$root/scripts/release-update-feed.sh" --platforms)
if [ "${#unlisted[@]}" -eq 0 ]; then
echo "$endpoint serves latest.json for $expected, for every platform."
finish
fi
fi
if [ "$attempt" -lt 5 ]; then sleep "$delay"; fi
done
echo "::error::$endpoint does not serve a latest.json with version $expected and a signed file for every platform ($("$root/scripts/release-update-feed.sh" --platforms | paste -sd ' ' -))."
head -c 500 feed.json 2>/dev/null || true
exit 1