Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
sh 57 lines 2.69 KB
Raw
1 #!/usr/bin/env bash
2 #
3 # Create the GitHub Release as a DRAFT with every asset attached, or resume an existing
4 # draft by re-uploading (--clobber). Refuse to mutate a tag that is already published.
5 #
6 # Drafts fire no `release: published` event and are excluded from `/releases/latest`, so no
7 # anonymous consumer (install.sh, the redirect) can observe a release before its
8 # assets are attached and verified. The release is only flipped to published by a later step.
9 #
10 # Inputs (env): RELEASE_TAG, RELEASE_NAME, CHECKOUT_REF, PRERELEASE, GH_TOKEN
11 # PREVIOUS_STABLE_TAG (optional, for stable release notes)
12 # BINARIES_DIR (optional, defaults to the CLI dist dir)
13 set -euo pipefail
14
15 binaries_dir="${BINARIES_DIR:-ts/packages/cli/dist/binaries}"
16
17 flags=(
18 --draft
19 --title "$RELEASE_NAME"
20 --target "$CHECKOUT_REF"
21 --generate-notes
22 )
23 # Preserve prerelease status on the draft so betas stay prereleases once published.
24 if [[ "$PRERELEASE" == "true" ]]; then
25 flags+=(--prerelease)
26 elif [[ -n "${PREVIOUS_STABLE_TAG:-}" ]]; then
27 flags+=(--notes-start-tag "$PREVIOUS_STABLE_TAG")
28 fi
29
30 # Idempotent for re-runs of a not-yet-published release: reuse an existing draft and clobber
31 # its assets. Refuse to mutate a tag that is already published.
32 if gh release view "$RELEASE_TAG" --json isDraft --jq '.isDraft' 2>/dev/null | grep -qx true; then
33 echo "Draft $RELEASE_TAG already exists — re-uploading assets with --clobber"
34 # An earlier attempt may have attached an asset this run does not ship, such as a Windows
35 # archive that has since failed its checks. The new checksums.txt does not cover it, so
36 # remove it instead of publishing it.
37 while IFS= read -r asset; do
38 if [[ ! -e "$binaries_dir/$asset" ]]; then
39 echo "Removing stale asset $asset from draft $RELEASE_TAG"
40 gh release delete-asset "$RELEASE_TAG" "$asset" --yes
41 fi
42 done < <(gh release view "$RELEASE_TAG" --json assets --jq '.assets[].name')
43 gh release upload "$RELEASE_TAG" \
44 "$binaries_dir"/*.zip \
45 "$binaries_dir/checksums.txt" --clobber
46 elif gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
47 # A red ❌ here is EXPECTED, not a bug, when two runs target the same tag (e.g. two quick CLI
48 # version bumps): per-tag `concurrency` serializes them, the first publishes, and the second —
49 # finding the tag already published — fails loudly here rather than silently clobbering a live
50 # release. If you hit this, confirm the tag is genuinely published before re-running.
51 echo "::error::Release $RELEASE_TAG is already published — refusing to mutate it. Investigate the publish path."
52 exit 1
53 else
54 gh release create "$RELEASE_TAG" "${flags[@]}" \
55 "$binaries_dir"/*.zip \
56 "$binaries_dir/checksums.txt"
57 fi