Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@ name: Release
# The whole release path, in one run.
#
# push to main -> release-please grooms one release pull request per pack
# merge that pull request -> release-please tags it (<pack>-v<version>) and cuts
# the GitHub Release
# -> assets builds the pack at that tag and attaches the zip
# merge that pull request -> release-please tags it (<pack>-v<version>) and cuts a DRAFT
# GitHub Release
# -> assets builds the pack at that tag, attaches the zip to the
# draft, then publishes it
#
# The release is a draft because releases here are immutable: once one is published its
# assets can no longer change, so the zip has to be on it before it goes public. That is
# also why release-please creates the tag itself (force-tag-creation); a draft's tag would
# otherwise not exist until it is published.
#
# Both jobs have to share one run. A tag created with GITHUB_TOKEN does not trigger
# another workflow -- GitHub suppresses that to stop runaway loops -- so a separate
# `on: push: tags` or `on: release` publisher would silently never fire.
#
# The assets job does not read release-please's outputs: with one package per pack
# they are keyed by path, and the org wrapper only surfaces the root package. It
# asks the API instead -- any pack whose current release has no zip gets one -- which
# also means a failed upload heals itself on the next push to main.
# asks the API instead -- any pack whose current release is still a draft gets its zip
# and is published -- which also means a failed upload heals itself on the next push to
# main. A release that was published without a zip cannot be repaired; it is reported and
# skipped, and the next release carries the zip.

on:
push:
Expand Down Expand Up @@ -47,7 +55,7 @@ jobs:
fetch-depth: 0
persist-credentials: false

- name: Build and attach missing zips
- name: Build, attach and publish
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
Expand All @@ -57,19 +65,32 @@ jobs:
version="$(jq -r --arg path "packs/${slug}" '.[$path] // empty' .release-please-manifest.json)"
tag="${slug}-v${version}"

assets="$(gh release view "${tag}" --json assets --jq '.assets | length' 2>/dev/null || true)"
if [ -z "${assets}" ]; then
# The listing, not `gh release view`: a draft has no page under its tag yet.
release="$(gh api "repos/${GH_REPO}/releases" --paginate \
--jq ".[] | select(.tag_name == \"${tag}\") | [.id, .draft, (.assets | length)] | @tsv" | head -n 1)"
if [ -z "${release}" ]; then
echo "${tag}: not released yet, skipping"
continue
fi
if [ "${assets}" -gt 0 ]; then
echo "${tag}: already has its zip, skipping"
read -r id draft assets <<<"${release}"

if [ "${draft}" != "true" ]; then
if [ "${assets}" -gt 0 ]; then
echo "${tag}: already published with its zip, skipping"
else
echo "::warning::${tag} was published without its zip and is immutable, so it cannot get one. The next release will."
fi
continue
fi

# Build from the tag, never from main: main may already be ahead of it.
git checkout --quiet "${tag}"
python3 .devtools/scripts/build.py "${slug}"
gh release upload "${tag}" dist/"${slug}"-*.zip
git checkout --quiet "${GITHUB_SHA}"

# --clobber: a run that attached the zip but died before publishing leaves it on
# the draft, and a second upload under the same name would be rejected.
gh release upload "${tag}" dist/"${slug}"-*.zip --clobber
gh api -X PATCH "repos/${GH_REPO}/releases/${id}" -F draft=false >/dev/null
echo "✔ ${tag}: published"
done
2 changes: 2 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"include-component-in-tag": true,
"include-v-in-tag": true,
"separate-pull-requests": true,
"draft": true,
"force-tag-creation": true,
"changelog-sections": [
{ "type": "feat", "section": "Features" },
{ "type": "fix", "section": "Bug Fixes" },
Expand Down
Loading