Add pre-flight validation script for releases
- Check VERSION file matches before triggering workflow - Validate working directory is clean - Confirm on main branch and up to date - Load release notes from /tmp/release_notes_X.Y.Z.md - Prevents wasting CI time on misconfigured releases
This commit is contained in:
parent
332f92b696
commit
d400befd35
1 changed files with 134 additions and 0 deletions
134
scripts/trigger-release.sh
Executable file
134
scripts/trigger-release.sh
Executable file
|
|
@ -0,0 +1,134 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Helper script to trigger a release with pre-flight validation
|
||||
# Usage: ./scripts/trigger-release.sh 4.30.0
|
||||
|
||||
VERSION="${1:-}"
|
||||
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Error: Version number required"
|
||||
echo "Usage: $0 <version>"
|
||||
echo "Example: $0 4.30.0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Pre-flight checks for release v${VERSION}..."
|
||||
echo ""
|
||||
|
||||
# Check 1: VERSION file matches
|
||||
FILE_VERSION=$(cat VERSION | tr -d '\n')
|
||||
if [ "$FILE_VERSION" != "$VERSION" ]; then
|
||||
echo "❌ VERSION file mismatch"
|
||||
echo ""
|
||||
echo " VERSION file contains: ${FILE_VERSION}"
|
||||
echo " Requested version: ${VERSION}"
|
||||
echo ""
|
||||
echo "Fix: Update VERSION file and commit:"
|
||||
echo " echo '${VERSION}' > VERSION"
|
||||
echo " git add VERSION"
|
||||
echo " git commit -m 'Prepare v${VERSION} release'"
|
||||
echo " git push"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ VERSION file matches (${VERSION})"
|
||||
|
||||
# Check 2: Working directory is clean
|
||||
if ! git diff-index --quiet HEAD --; then
|
||||
echo "❌ Working directory has uncommitted changes"
|
||||
echo ""
|
||||
echo "Fix: Commit or stash changes before releasing"
|
||||
echo ""
|
||||
git status --short
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ Working directory is clean"
|
||||
|
||||
# Check 3: On main branch
|
||||
CURRENT_BRANCH=$(git branch --show-current)
|
||||
if [ "$CURRENT_BRANCH" != "main" ]; then
|
||||
echo "⚠️ Warning: Not on main branch (current: ${CURRENT_BRANCH})"
|
||||
echo ""
|
||||
read -p "Continue anyway? [y/N] " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Aborted"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "✓ On main branch"
|
||||
fi
|
||||
|
||||
# Check 4: Up to date with remote
|
||||
if ! git fetch origin --dry-run 2>&1 | grep -q "up to date"; then
|
||||
echo "⚠️ Warning: Remote has updates or local branch is ahead"
|
||||
echo ""
|
||||
read -p "Continue anyway? [y/N] " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Aborted"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "✓ Up to date with remote"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "Ready to release v${VERSION}"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo "Next: Provide release notes when prompted"
|
||||
echo ""
|
||||
|
||||
# Check 5: Release notes file (optional)
|
||||
NOTES_FILE="/tmp/release_notes_${VERSION}.md"
|
||||
if [ -f "$NOTES_FILE" ]; then
|
||||
echo "Found release notes file: ${NOTES_FILE}"
|
||||
echo ""
|
||||
cat "$NOTES_FILE"
|
||||
echo ""
|
||||
read -p "Use these release notes? [Y/n] " -n 1 -r
|
||||
echo ""
|
||||
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||
echo "Release notes file ignored"
|
||||
NOTES_FILE=""
|
||||
fi
|
||||
else
|
||||
echo "No release notes file found at ${NOTES_FILE}"
|
||||
echo ""
|
||||
echo "Create release notes manually or let the workflow prompt you."
|
||||
echo ""
|
||||
read -p "Continue without release notes file? [y/N] " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Aborted"
|
||||
exit 1
|
||||
fi
|
||||
NOTES_FILE=""
|
||||
fi
|
||||
|
||||
# Trigger the workflow
|
||||
echo ""
|
||||
echo "Triggering release workflow..."
|
||||
if [ -n "$NOTES_FILE" ]; then
|
||||
gh workflow run release.yml \
|
||||
-f version="${VERSION}" \
|
||||
-f release_notes="$(cat "$NOTES_FILE")"
|
||||
else
|
||||
echo ""
|
||||
echo "❌ Error: Release notes are required"
|
||||
echo ""
|
||||
echo "Create ${NOTES_FILE} with your release notes, then run this script again."
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "✓ Release workflow triggered"
|
||||
echo ""
|
||||
echo "Monitor progress:"
|
||||
echo " gh run list --workflow=release.yml --limit 1"
|
||||
echo " gh run watch <run-id>"
|
||||
echo ""
|
||||
Loading…
Reference in a new issue