|
| 1 | +#!/bin/bash |
| 2 | +# Pre-flight checks before creating a release |
| 3 | +# This script MUST pass before creating a tag |
| 4 | + |
| 5 | +set -e |
| 6 | + |
| 7 | +RED='\033[0;31m' |
| 8 | +GREEN='\033[0;32m' |
| 9 | +YELLOW='\033[1;33m' |
| 10 | +NC='\033[0m' |
| 11 | + |
| 12 | +fail() { |
| 13 | + echo -e "${RED}[FAIL]${NC} $1" |
| 14 | + exit 1 |
| 15 | +} |
| 16 | + |
| 17 | +pass() { |
| 18 | + echo -e "${GREEN}[PASS]${NC} $1" |
| 19 | +} |
| 20 | + |
| 21 | +warn() { |
| 22 | + echo -e "${YELLOW}[WARN]${NC} $1" |
| 23 | +} |
| 24 | + |
| 25 | +echo "==========================================" |
| 26 | +echo " LAIN Pre-Flight Release Checks" |
| 27 | +echo "==========================================" |
| 28 | +echo "" |
| 29 | + |
| 30 | +# Check 1: All tests pass |
| 31 | +echo "Check 1: Running all tests..." |
| 32 | +if cargo test 2>&1 | grep -q "test result: ok"; then |
| 33 | + pass "All tests pass" |
| 34 | +else |
| 35 | + fail "Tests failed" |
| 36 | +fi |
| 37 | + |
| 38 | +# Check 2: No compilation warnings |
| 39 | +echo "Check 2: Checking for compilation warnings..." |
| 40 | +if cargo build --release 2>&1 | grep -i warning > /dev/null 2>&1; then |
| 41 | + fail "Compilation warnings found. Run: cargo build --release 2>&1 | grep -i warning" |
| 42 | +else |
| 43 | + pass "No compilation warnings" |
| 44 | +fi |
| 45 | + |
| 46 | +# Check 3: Version consistency |
| 47 | +echo "Check 3: Checking version consistency..." |
| 48 | +VERSION=$(grep '^version = "' Cargo.toml | head -1 | sed 's/version = "\([^"]*\)"/\1/') |
| 49 | +if [ -z "$VERSION" ]; then |
| 50 | + fail "Could not extract version from Cargo.toml" |
| 51 | +fi |
| 52 | + |
| 53 | +# Check Cargo.toml |
| 54 | +if grep -q "version = \"$VERSION\"" Cargo.toml; then |
| 55 | + pass "Cargo.toml version: $VERSION" |
| 56 | +else |
| 57 | + fail "Cargo.toml version mismatch" |
| 58 | +fi |
| 59 | + |
| 60 | +# Check README.md |
| 61 | +if grep -q "v$VERSION" README.md || ! grep -q "v[0-9]" README.md; then |
| 62 | + pass "README.md version: $VERSION" |
| 63 | +else |
| 64 | + fail "README.md version mismatch" |
| 65 | +fi |
| 66 | + |
| 67 | +# Check server.json |
| 68 | +if grep -q "\"version\": \"$VERSION\"" server.json; then |
| 69 | + pass "server.json version: $VERSION" |
| 70 | +else |
| 71 | + fail "server.json version mismatch" |
| 72 | +fi |
| 73 | + |
| 74 | +# Check 4: Binary builds locally |
| 75 | +echo "Check 4: Building binary locally..." |
| 76 | +if cargo build --release 2>&1 | grep -q "Finished \`release\`"; then |
| 77 | + pass "Binary builds successfully" |
| 78 | +else |
| 79 | + fail "Binary build failed" |
| 80 | +fi |
| 81 | + |
| 82 | +# Check 5: Binary is executable |
| 83 | +echo "Check 5: Checking binary is executable..." |
| 84 | +if [ -f "target/release/lain" ]; then |
| 85 | + if target/release/lain --version >/dev/null 2>&1; then |
| 86 | + pass "Binary is executable" |
| 87 | + else |
| 88 | + fail "Binary exists but is not executable" |
| 89 | + fi |
| 90 | +else |
| 91 | + fail "Binary not found at target/release/lain" |
| 92 | +fi |
| 93 | + |
| 94 | +# Check 6: Git status is clean |
| 95 | +echo "Check 6: Checking git status..." |
| 96 | +if [ -n "$(git status --porcelain)" ]; then |
| 97 | + fail "Git working directory is not clean. Commit or stash changes." |
| 98 | +else |
| 99 | + pass "Git working directory is clean" |
| 100 | +fi |
| 101 | + |
| 102 | +# Check 7: No uncommitted changes |
| 103 | +echo "Check 7: Checking for uncommitted changes..." |
| 104 | +if [ -z "$(git diff --name-only)" ] && [ -z "$(git diff --cached --name-only)" ]; then |
| 105 | + pass "No uncommitted changes" |
| 106 | +else |
| 107 | + fail "There are uncommitted changes" |
| 108 | +fi |
| 109 | + |
| 110 | +# Check 8: No existing tag for this version |
| 111 | +echo "Check 8: Checking for existing tag..." |
| 112 | +if git tag -l "v$VERSION" | grep -q "v$VERSION"; then |
| 113 | + fail "Tag v$VERSION already exists. Delete it first: git tag -d v$VERSION && git push origin :refs/tags/v$VERSION" |
| 114 | +else |
| 115 | + pass "No existing tag for v$VERSION" |
| 116 | +fi |
| 117 | + |
| 118 | +# Check 9: Release workflow exists and is valid |
| 119 | +echo "Check 9: Checking release workflow..." |
| 120 | +if [ -f ".github/workflows/release.yml" ]; then |
| 121 | + if yamllint .github/workflows/release.yml >/dev/null 2>&1 || grep -q "name:" .github/workflows/release.yml; then |
| 122 | + pass "Release workflow exists and is valid" |
| 123 | + else |
| 124 | + fail "Release workflow is invalid" |
| 125 | + fi |
| 126 | +else |
| 127 | + fail "Release workflow not found" |
| 128 | +fi |
| 129 | + |
| 130 | +# Check 10: Awareness docs exist |
| 131 | +echo "Check 10: Checking awareness docs..." |
| 132 | +AWARENESS_DOCS=( |
| 133 | + "hooks/claude/lain-awareness.md" |
| 134 | + "hooks/cursor/lain-awareness.md" |
| 135 | + "hooks/windsurf/lain-rules.md" |
| 136 | + "hooks/cline/lain-rules.md" |
| 137 | +) |
| 138 | + |
| 139 | +ALL_DOCS_EXIST=true |
| 140 | +for doc in "${AWARENESS_DOCS[@]}"; do |
| 141 | + if [ ! -f "$doc" ]; then |
| 142 | + warn "Missing awareness doc: $doc" |
| 143 | + ALL_DOCS_EXIST=false |
| 144 | + fi |
| 145 | +done |
| 146 | + |
| 147 | +if [ "$ALL_DOCS_EXIST" = true ]; then |
| 148 | + pass "All awareness docs exist" |
| 149 | +else |
| 150 | + fail "Some awareness docs are missing" |
| 151 | +fi |
| 152 | + |
| 153 | +# Check 11: Install script exists and is bash-compatible |
| 154 | +echo "Check 11: Checking install script..." |
| 155 | +if [ -f "install.sh" ]; then |
| 156 | + if bash -n install.sh >/dev/null 2>&1; then |
| 157 | + pass "Install script exists and is bash-compatible" |
| 158 | + else |
| 159 | + fail "Install script has syntax errors" |
| 160 | + fi |
| 161 | +else |
| 162 | + fail "Install script not found" |
| 163 | +fi |
| 164 | + |
| 165 | +# Check 12: Formula exists and is valid |
| 166 | +echo "Check 12: Checking Homebrew formula..." |
| 167 | +if [ -f "Formula/lain.rb" ]; then |
| 168 | + if grep -q "class Lain" Formula/lain.rb; then |
| 169 | + pass "Homebrew formula exists and is valid" |
| 170 | + else |
| 171 | + fail "Homebrew formula is invalid" |
| 172 | + fi |
| 173 | +else |
| 174 | + fail "Homebrew formula not found" |
| 175 | +fi |
| 176 | + |
| 177 | +echo "" |
| 178 | +echo "==========================================" |
| 179 | +echo -e "${GREEN}✅ All pre-flight checks passed!${NC}" |
| 180 | +echo "==========================================" |
| 181 | +echo "" |
| 182 | +echo "You can now create the release:" |
| 183 | +echo " git tag -a v$VERSION -m \"Release v$VERSION\"" |
| 184 | +echo " git push origin v$VERSION" |
| 185 | +echo "" |
| 186 | +echo "After the CI completes, verify:" |
| 187 | +echo " gh release view v$VERSION --json assets" |
| 188 | +echo " # Download and verify all 3 binaries" |
| 189 | +echo "" |
| 190 | +echo "Then update the Homebrew formula with SHA256 hashes." |
0 commit comments