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
37 changes: 0 additions & 37 deletions .github/scripts/build-release-notes.sh

This file was deleted.

11 changes: 6 additions & 5 deletions .github/scripts/build-screenshot-sheet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Compose a single screenshot sheet for release notes: light shots in one row,
# dark shots in a row below, on a transparent background.
#
# Usage: build-screenshot-sheet.sh <output.png>
# Usage: build-screenshot-sheet.sh <source-dir> <output.png>
set -euo pipefail

OUT="${1:?usage: build-screenshot-sheet.sh <output.png>}"
DIR="website/images"
SRC="${1:?usage: build-screenshot-sheet.sh <source-dir> <output.png>}"
OUT="${2:?usage: build-screenshot-sheet.sh <source-dir> <output.png>}"

if command -v magick > /dev/null 2>&1; then
MONTAGE="magick montage"
Expand All @@ -19,14 +19,15 @@ else
fi

light=() dark=()
for file in "$DIR"/*.png; do
for file in "$SRC"/*.png; do
[ -e "$file" ] || continue
case "$(basename "$file")" in
*-dark.png) dark+=("$file") ;;
*screenshot-sheet.png) ;;
*) light+=("$file") ;;
esac
done
[ "${#light[@]}" -gt 0 ] || { echo "no light screenshots found" >&2; exit 1; }
[ "${#light[@]}" -gt 0 ] || { echo "no light screenshots in $SRC" >&2; exit 1; }

tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
Expand Down
46 changes: 10 additions & 36 deletions .github/scripts/publish-preview-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,19 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Create or update the rolling "preview" release for the current commit.
#
# Run from a checkout of the repository with `dist/app-debug.apk` already built.
# Screenshots ship as release assets: one composed sheet when ImageMagick is
# available, otherwise the individual images.
# Run from a checkout with `dist/app-debug.apk` built and the emulator
# screenshots captured into `screenshots/` (see android.yml).
set -euo pipefail

REPO="${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is required}"
SHA="${GITHUB_SHA:-$(git rev-parse HEAD)}"
SHORT_SHA="$(git rev-parse --short "$SHA")"
TAG="preview"
TITLE="Preview build"
APK="dist/app-debug.apk"
ASSET_APK="TeslaBatteryBLE-preview-$SHORT_SHA.apk"
SITE_IMAGES_DIR="website/images"
SHEET="screenshot-sheet.png"

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=./screenshot-sections.sh
source "$SCRIPT_DIR/screenshot-sections.sh"

SCREENSHOT_BASE_URL="https://github.com/$REPO/releases/download/$TAG"
SHEET_OK="false"
if bash "$SCRIPT_DIR/build-screenshot-sheet.sh" "$SHEET"; then
SHEET_OK="true"
SCREENSHOT_SHEET_URL="$SCREENSHOT_BASE_URL/$SHEET"
fi
ASSET_APK="TeslaBatteryBLE-preview.apk"
SHEET="screenshots/screenshot-sheet.png"
SHEET_NAME="$(basename "$SHEET")"
SHEET_URL="https://github.com/$REPO/releases/download/$TAG/$SHEET_NAME"

[ -f "$APK" ] || { echo "missing $APK" >&2; exit 1; }
cp "$APK" "$ASSET_APK"
Expand Down Expand Up @@ -77,35 +65,21 @@ git push origin "refs/tags/$TAG" --force
echo
echo "**Full diff**: https://github.com/$REPO/compare/$PREV_TAG...$TAG"
fi
if [ "$SHEET_OK" = "true" ]; then
if [ -f "$SHEET" ]; then
echo
echo "## Screenshots"
echo
echo "![App screenshots: light and dark]($SCREENSHOT_SHEET_URL)"
else
emit_screenshots "$SCREENSHOT_BASE_URL"
echo "![App screenshots: light and dark]($SHEET_URL)"
fi
} > preview-notes.md

if gh release view "$TAG" > /dev/null 2>&1; then
# Drop stale SHA-named APK assets from previous runs so old builds never linger.
while read -r name; do
[ -n "$name" ] || continue
gh release delete-asset "$TAG" "$name" --yes || true
done < <(gh release view "$TAG" --json assets --jq '.assets[].name | select(endswith(".apk"))')
gh release edit "$TAG" --title "$TITLE" --prerelease --notes-file preview-notes.md
else
gh release create "$TAG" --title "$TITLE" --prerelease --notes-file preview-notes.md "$ASSET_APK"
gh release create "$TAG" --title "$TITLE" --prerelease --notes-file preview-notes.md
fi

gh release upload "$TAG" "$ASSET_APK" --clobber
if [ "$SHEET_OK" = "true" ]; then
if [ -f "$SHEET" ]; then
gh release upload "$TAG" "$SHEET" --clobber
# Drop stale individual screenshots now that the sheet is used.
while read -r asset; do
[ -n "$asset" ] || continue
gh release delete-asset "$TAG" "$asset" --yes || true
done < <(gh release view "$TAG" --json assets --jq '.assets[].name | select(endswith(".png")) | select(. != "screenshot-sheet.png")')
elif compgen -G "$SITE_IMAGES_DIR/*.png" > /dev/null; then
gh release upload "$TAG" "$SITE_IMAGES_DIR"/*.png --clobber
fi
104 changes: 34 additions & 70 deletions .github/scripts/publish-tag-release.sh
Original file line number Diff line number Diff line change
@@ -1,85 +1,49 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: AGPL-3.0-only
# Publish a tagged release.
#
# If the rolling preview release points at this commit, convert it into the
# tagged release (move the release to the new tag, update title/notes, replace
# the asset) instead of deleting it and creating a new one. Otherwise fall
# back to creating a fresh release.
#
# Screenshots ship as release assets: one composed sheet when ImageMagick is
# available, otherwise the individual images.
# Publish a tagged release: the CHANGELOG section plus the screenshot sheet
# captured by CI. Run from a checkout with the debug APK built and the
# emulator screenshots captured into `screenshots/`.
set -euo pipefail

TAG="${GITHUB_REF_NAME:?GITHUB_REF_NAME is required}"
REPO="${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is required}"
SHA="${GITHUB_SHA:-$(git rev-parse HEAD)}"
APK="app/build/outputs/apk/debug/app-debug.apk"
ASSET_APK="TeslaBatteryBLE-${TAG}.apk"
VERSION="${TAG#v}"
APK="dist/TeslaBatteryBLE-${TAG}.apk"
NOTES="release-notes.md"
SITE_IMAGES_DIR="website/images"
SHEET="screenshot-sheet.png"

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

case "$TAG" in
*-*) PRERELEASE_JSON="true" ;;
*) PRERELEASE_JSON="false" ;;
esac

[ -f "$APK" ] || { echo "missing $APK" >&2; exit 1; }
cp "$APK" "$ASSET_APK"

SHEET_OK="false"
if bash "$SCRIPT_DIR/build-screenshot-sheet.sh" "$SHEET"; then
SHEET_OK="true"
fi
export SCREENSHOT_BASE_URL="https://github.com/$REPO/releases/download/$TAG"
if [ "$SHEET_OK" = "true" ]; then
export SCREENSHOT_SHEET_URL="$SCREENSHOT_BASE_URL/$SHEET"
fi
bash "$SCRIPT_DIR/build-release-notes.sh"

git fetch --tags origin

REUSED="false"
PREVIEW_ID="$(gh release view preview --json databaseId --jq '.databaseId' 2>/dev/null || true)"
if [ -n "$PREVIEW_ID" ]; then
PREVIEW_SHA="$(git rev-parse -q --verify 'refs/tags/preview^{commit}' 2>/dev/null || true)"
if [ -n "$PREVIEW_SHA" ] && [ "$PREVIEW_SHA" = "$SHA" ]; then
jq -n --arg tag "$TAG" --arg name "$TAG" --arg body "$(cat "$NOTES")" \
--argjson pre "$PRERELEASE_JSON" \
'{tag_name: $tag, name: $name, prerelease: $pre, body: $body}' > release-payload.json
if gh api -X PATCH "repos/$REPO/releases/$PREVIEW_ID" --input release-payload.json > /dev/null; then
REUSED="true"
echo "Converted the rolling preview release into $TAG."
else
echo "Preview conversion failed; creating a new release instead."
fi
SHEET="screenshots/screenshot-sheet.png"
SHEET_NAME="$(basename "$SHEET")"
SHEET_URL="https://github.com/$REPO/releases/download/$TAG/$SHEET_NAME"

if [ "$TAG" != "${TAG%-*}" ]; then PRE_FLAG="--prerelease"; else PRE_FLAG=""; fi

[ -f "$APK" ] || { echo "missing $APK (the build job stages it for tags)" >&2; exit 1; }

{
awk -v h="## [$VERSION]" '
index($0, h) == 1 { found = 1 }
found && /^## \[/ && index($0, h) != 1 { exit }
found { print }
' CHANGELOG.md

if [ -f "$SHEET" ]; then
echo
echo "## Screenshots"
echo
echo "![App screenshots: light and dark]($SHEET_URL)"
fi
} > "$NOTES"

if [ ! -s "$NOTES" ]; then
echo "See [CHANGELOG.md](https://github.com/$REPO/blob/main/CHANGELOG.md)." > "$NOTES"
fi

if [ "$REUSED" = "true" ]; then
gh release upload "$TAG" "$ASSET_APK" --clobber
while read -r asset; do
[ -n "$asset" ] || continue
gh release delete-asset "$TAG" "$asset" --yes || true
done < <(gh release view "$TAG" --json assets --jq '.assets[].name | select(startswith("TeslaBatteryBLE-preview-"))')
# The release no longer points at the rolling tag.
git push origin ":refs/tags/preview" || true
elif [ "$PRERELEASE_JSON" = "true" ]; then
gh release create "$TAG" --title "$TAG" --prerelease --notes-file "$NOTES" "$ASSET_APK"
if gh release view "$TAG" > /dev/null 2>&1; then
gh release edit "$TAG" --title "$TAG" --notes-file "$NOTES" $PRE_FLAG
else
gh release create "$TAG" --title "$TAG" --notes-file "$NOTES" "$ASSET_APK"
gh release create "$TAG" --title "$TAG" --notes-file "$NOTES" $PRE_FLAG
fi

if [ "$SHEET_OK" = "true" ]; then
gh release upload "$TAG" "$APK" --clobber
if [ -f "$SHEET" ]; then
gh release upload "$TAG" "$SHEET" --clobber
# Drop stale individual screenshots now that the sheet is used.
while read -r asset; do
[ -n "$asset" ] || continue
gh release delete-asset "$TAG" "$asset" --yes || true
done < <(gh release view "$TAG" --json assets --jq '.assets[].name | select(endswith(".png")) | select(. != "screenshot-sheet.png")')
elif compgen -G "$SITE_IMAGES_DIR/*.png" > /dev/null; then
gh release upload "$TAG" "$SITE_IMAGES_DIR"/*.png --clobber
fi
56 changes: 0 additions & 56 deletions .github/scripts/screenshot-sections.sh

This file was deleted.

Loading
Loading