142 lines
5.1 KiB
Bash
142 lines
5.1 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# publish-release.sh — put a built release on both mirrors.
|
||
|
|
#
|
||
|
|
# tools/publish-release.sh # build, then publish
|
||
|
|
# tools/publish-release.sh --dry-run # say what would happen
|
||
|
|
#
|
||
|
|
# A Silent Mode release is not shipped until it exists in both places:
|
||
|
|
#
|
||
|
|
# silentmode.st over scp, served by nginx on the VPS
|
||
|
|
# silentmode.bch on Sia, reached through any BCNR resolver
|
||
|
|
#
|
||
|
|
# Publishing to only one is the recurring mistake this script exists to
|
||
|
|
# prevent. A release on silentmode.st alone is a release that disappears when
|
||
|
|
# the VPS does, which rather undercuts the argument the project is making.
|
||
|
|
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||
|
|
cd "$here"
|
||
|
|
|
||
|
|
SSH_HOST="${SIRIUS_SSH_HOST:-silentmode}"
|
||
|
|
WEB_ROOT="${SIRIUS_WEB_ROOT:-/opt/silent-mode/site/sirius-press}"
|
||
|
|
S3_ENDPOINT="${SIRIUS_S3_ENDPOINT:-https://s3.silentmode.st:8600}"
|
||
|
|
S3_PREFIX="${SIRIUS_S3_PREFIX:-s3://bns/silentmode/sirius-press}"
|
||
|
|
AWS_PROFILE_NAME="${SIRIUS_AWS_PROFILE:-sia-storage}"
|
||
|
|
DRY=0
|
||
|
|
|
||
|
|
for arg in "$@"; do
|
||
|
|
case "$arg" in
|
||
|
|
--dry-run) DRY=1 ;;
|
||
|
|
*) echo "unknown option: $arg" >&2; exit 2 ;;
|
||
|
|
esac
|
||
|
|
done
|
||
|
|
|
||
|
|
say() { printf '\033[1m→\033[0m %s\n' "$*"; }
|
||
|
|
warn() { printf '\033[33mwarning:\033[0m %s\n' "$*" >&2; }
|
||
|
|
die() { printf '\033[31merror:\033[0m %s\n' "$*" >&2; exit 1; }
|
||
|
|
run() { if [ "$DRY" -eq 1 ]; then printf ' would run: %s\n' "$*"; else "$@"; fi; }
|
||
|
|
|
||
|
|
VERSION="$(grep -m1 "^ \* Version:" plugins/sirius-press-core/sirius-press-core.php | awk '{print $3}')"
|
||
|
|
[ -n "$VERSION" ] || die "could not read the version out of sirius-press-core.php"
|
||
|
|
|
||
|
|
ARCHIVE="dist/sirius-press-${VERSION}.zip"
|
||
|
|
|
||
|
|
# ------------------------------------------------------------------- build
|
||
|
|
|
||
|
|
if [ ! -f "$ARCHIVE" ]; then
|
||
|
|
say "building $VERSION"
|
||
|
|
[ "$DRY" -eq 1 ] && { echo " would run: tools/build.sh --zip"; } || tools/build.sh --zip
|
||
|
|
fi
|
||
|
|
[ "$DRY" -eq 1 ] || [ -f "$ARCHIVE" ] || die "$ARCHIVE was not produced"
|
||
|
|
|
||
|
|
if [ -f "$ARCHIVE" ]; then
|
||
|
|
SHA="$(cat "${ARCHIVE}.sha256" 2>/dev/null || sha256sum "$ARCHIVE" | cut -d' ' -f1)"
|
||
|
|
say "$(basename "$ARCHIVE") — $(du -h "$ARCHIVE" | cut -f1), sha256 ${SHA}"
|
||
|
|
else
|
||
|
|
SHA="(not built)"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# ---------------------------------------------------------------- manifest
|
||
|
|
|
||
|
|
MANIFEST="dist/releases.json"
|
||
|
|
say "writing $(basename "$MANIFEST")"
|
||
|
|
if [ "$DRY" -eq 0 ]; then
|
||
|
|
cat > "$MANIFEST" <<EOF
|
||
|
|
{
|
||
|
|
"product": "sirius-press",
|
||
|
|
"latest": "${VERSION}",
|
||
|
|
"updated": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
|
||
|
|
"releases": [
|
||
|
|
{
|
||
|
|
"version": "${VERSION}",
|
||
|
|
"zip": "sirius-press-${VERSION}.zip",
|
||
|
|
"sha256": "${SHA}",
|
||
|
|
"wordpress": "$(grep -m1 '^WP_VERSION=' tools/wordpress.lock | cut -d= -f2)",
|
||
|
|
"install": "https://silentmode.st/sirius-press/install.sh"
|
||
|
|
}
|
||
|
|
]
|
||
|
|
}
|
||
|
|
EOF
|
||
|
|
fi
|
||
|
|
|
||
|
|
# --------------------------------------------------------- mirror 1: the VPS
|
||
|
|
|
||
|
|
say "publishing to silentmode.st"
|
||
|
|
command -v ssh >/dev/null || die "ssh is required"
|
||
|
|
run ssh "$SSH_HOST" "mkdir -p ${WEB_ROOT}"
|
||
|
|
run scp "$ARCHIVE" "${SSH_HOST}:${WEB_ROOT}/"
|
||
|
|
run scp "${ARCHIVE}.sha256" "${SSH_HOST}:${WEB_ROOT}/"
|
||
|
|
run scp "$MANIFEST" "${SSH_HOST}:${WEB_ROOT}/releases.json"
|
||
|
|
run scp install.sh "${SSH_HOST}:${WEB_ROOT}/install.sh"
|
||
|
|
|
||
|
|
# --------------------------------------------------------- mirror 2: Sia
|
||
|
|
|
||
|
|
say "publishing to silentmode.bch"
|
||
|
|
if ! command -v aws >/dev/null; then
|
||
|
|
warn "the aws CLI is not installed, so the Sia mirror was skipped.
|
||
|
|
This release is NOT shipped until it is on both. Install awscli and run:
|
||
|
|
aws --profile ${AWS_PROFILE_NAME} --endpoint-url ${S3_ENDPOINT} s3 cp ${ARCHIVE} ${S3_PREFIX}/"
|
||
|
|
else
|
||
|
|
run aws --profile "$AWS_PROFILE_NAME" --endpoint-url "$S3_ENDPOINT" \
|
||
|
|
s3 cp "$ARCHIVE" "${S3_PREFIX}/" --only-show-errors
|
||
|
|
run aws --profile "$AWS_PROFILE_NAME" --endpoint-url "$S3_ENDPOINT" \
|
||
|
|
s3 cp "${ARCHIVE}.sha256" "${S3_PREFIX}/" --only-show-errors
|
||
|
|
run aws --profile "$AWS_PROFILE_NAME" --endpoint-url "$S3_ENDPOINT" \
|
||
|
|
s3 cp "$MANIFEST" "${S3_PREFIX}/releases.json" --only-show-errors
|
||
|
|
run aws --profile "$AWS_PROFILE_NAME" --endpoint-url "$S3_ENDPOINT" \
|
||
|
|
s3 cp install.sh "${S3_PREFIX}/install.sh" --only-show-errors
|
||
|
|
fi
|
||
|
|
|
||
|
|
# ------------------------------------------------------------------ verify
|
||
|
|
|
||
|
|
if [ "$DRY" -eq 0 ]; then
|
||
|
|
say "checking both mirrors actually have it"
|
||
|
|
st_code="$(curl -fsS -o /dev/null -w '%{http_code}' --max-time 20 \
|
||
|
|
"https://silentmode.st/sirius-press/$(basename "$ARCHIVE")" 2>/dev/null || echo 000)"
|
||
|
|
[ "$st_code" = "200" ] \
|
||
|
|
&& echo " ok silentmode.st" \
|
||
|
|
|| warn "silentmode.st returned ${st_code} for the archive"
|
||
|
|
|
||
|
|
if command -v aws >/dev/null; then
|
||
|
|
aws --profile "$AWS_PROFILE_NAME" --endpoint-url "$S3_ENDPOINT" \
|
||
|
|
s3 ls "${S3_PREFIX}/$(basename "$ARCHIVE")" >/dev/null 2>&1 \
|
||
|
|
&& echo " ok silentmode.bch" \
|
||
|
|
|| warn "the archive is not listed on the Sia mirror"
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
cat <<EOF
|
||
|
|
|
||
|
|
Sirius Press ${VERSION} published.
|
||
|
|
|
||
|
|
https://silentmode.st/sirius-press/
|
||
|
|
silentmode.bch/sirius-press/
|
||
|
|
|
||
|
|
Still to do by hand:
|
||
|
|
- tag the forge repo: git tag -a v${VERSION} -m "Sirius Press ${VERSION}"
|
||
|
|
- attach $(basename "$ARCHIVE") to the release on
|
||
|
|
https://code.silentmode.st/silentmode/sirius-press/releases
|
||
|
|
|
||
|
|
EOF
|