Skip to content
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ staging/
beta/README.md
/beta/32bit/node_modules
/beta/64bit/node_modules

# Test output files
changelog-test.md
*-test.md
44 changes: 44 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,48 @@ This job is triggered by the successful completion of step 3
1. Download the current homebridge-apt-pkg for x86 and install.
2. Check that homebridge starts

## Package Manifest

Each release includes a Package Manifest file that contains:

- **Release Version**: The version of the APT package
- **Release Type**: Either `stable` or `beta`
- **Package Versions**: A table showing the versions of NodeJS, Homebridge UI, and Homebridge included in the package
- **What's Changed**: A changelog section showing commits since the last release

The changelog section automatically includes:
- For **stable releases**: All commits since the previous stable tag/release (excludes beta tags)
- For **beta releases**: All commits since the previous beta tag/release (excludes stable tags)
- If no previous tag of the same type exists, shows the 5 most recent commits
- If there are no new commits since the last tag of the same type, displays "No new commits since last [stable|beta] release"

Each changelog entry includes the commit message and short hash for reference.

## Testing Changelog Generation

You can test the changelog generation feature outside of the full release process using the provided test script:

```bash
# Test stable changelog generation
./test/test-changelog.sh

# Test beta changelog generation
PKG_RELEASE_TYPE=beta ./test/test-changelog.sh

# Test with custom parameters
PKG_RELEASE_TYPE=beta PKG_RELEASE_VERSION=1.2.3-beta.1 OUTPUT_FILE=my-test.md ./test/test-changelog.sh
```

The test script:
- Replicates the exact changelog logic from `build.sh`
- Allows testing different release types (stable/beta)
- Shows which tags and commits would be included
- Generates a sample manifest file for review
- Provides helpful output about available tags and commit counts

This is useful for:
- Validating changelog logic changes before releases
- Understanding what commits will be included in upcoming releases
- Testing edge cases (no tags, no commits, etc.)

# Beta Builds
50 changes: 50 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,56 @@ fi
npm install --prefix "$(pwd)/staging/var/lib/homebridge" homebridge@$HOMEBRIDGE_VERSION
echo "|Homebridge| $HOMEBRIDGE_VERSION |" >> "$MANIFEST"

# Add changelog section to manifest
echo >> "$MANIFEST"
echo "## What's Changed" >> "$MANIFEST"
echo >> "$MANIFEST"

# Get the latest tag to compare against, filtered by release type
if [[ "${PKG_RELEASE_TYPE:-stable}" == "beta" ]]; then
# For beta releases, only look at beta tags
LATEST_TAG=$(git tag -l | grep -E "beta\." | sort -V | tail -1 2>/dev/null || echo "")
else
# For stable releases, only look at stable tags (no beta in name)
LATEST_TAG=$(git tag -l | grep -v -E "beta\." | sort -V | tail -1 2>/dev/null || echo "")
fi

if [ -n "$LATEST_TAG" ]; then
# Get commits since the latest tag of the same type
CHANGELOG_COMMITS=$(git log --oneline --no-merges "$LATEST_TAG"..HEAD 2>/dev/null)

if [ -n "$CHANGELOG_COMMITS" ]; then
# Format commits as changelog entries
while IFS= read -r commit; do
if [ -n "$commit" ]; then
# Extract commit hash and message
COMMIT_HASH=$(echo "$commit" | cut -d' ' -f1)
COMMIT_MSG=$(echo "$commit" | cut -d' ' -f2-)
echo "* $COMMIT_MSG (\`$COMMIT_HASH\`)" >> "$MANIFEST"
fi
done <<< "$CHANGELOG_COMMITS"
else
echo "* No new commits since last ${PKG_RELEASE_TYPE:-stable} release" >> "$MANIFEST"
fi
else
# If no tags of this type exist, show recent commits
RECENT_COMMITS=$(git log --oneline --no-merges -5 2>/dev/null)
if [ -n "$RECENT_COMMITS" ]; then
echo "### Recent Changes" >> "$MANIFEST"
while IFS= read -r commit; do
if [ -n "$commit" ]; then
COMMIT_HASH=$(echo "$commit" | cut -d' ' -f1)
COMMIT_MSG=$(echo "$commit" | cut -d' ' -f2-)
echo "* $COMMIT_MSG (\`$COMMIT_HASH\`)" >> "$MANIFEST"
fi
done <<< "$RECENT_COMMITS"
else
echo "* No commit history available" >> "$MANIFEST"
fi
fi

echo >> "$MANIFEST"

cp "$MANIFEST" staging/opt/homebridge
# Build .deb
cd staging
Expand Down
112 changes: 112 additions & 0 deletions test/test-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash

# Test script for changelog generation functionality
# This script allows testing the changelog feature outside of the full release process

set -e

# Default values
PKG_RELEASE_TYPE="${PKG_RELEASE_TYPE:-stable}"
PKG_RELEASE_VERSION="${PKG_RELEASE_VERSION:-test-1.0.0}"
OUTPUT_FILE="${OUTPUT_FILE:-changelog-test.md}"

echo "🧪 Testing changelog generation..."
echo "📋 Release Type: $PKG_RELEASE_TYPE"
echo "📋 Release Version: $PKG_RELEASE_VERSION"
echo "📋 Output File: $OUTPUT_FILE"
echo

# Create test manifest header (similar to build.sh)
cat > "$OUTPUT_FILE" << EOF
# Homebridge Apt Package Manifest (TEST)

**Release Version**: $PKG_RELEASE_VERSION
**Release Type**: $PKG_RELEASE_TYPE

| Package | Version |
|:-------:|:-------:|
|NodeJS| test-node-version |
|Homebridge UI| test-ui-version |
|Homebridge| test-homebridge-version |

## What's Changed

EOF

# Get the latest tag to compare against, filtered by release type
# This is the same logic as in build.sh lines 118-124
if [[ "${PKG_RELEASE_TYPE}" == "beta" ]]; then
# For beta releases, only look at beta tags
LATEST_TAG=$(git tag -l | grep -E "beta\." | sort -V | tail -1 2>/dev/null || echo "")
echo "🔍 Looking for latest beta tag..."
else
# For stable releases, only look at stable tags (no beta in name)
LATEST_TAG=$(git tag -l | grep -v -E "beta\." | sort -V | tail -1 2>/dev/null || echo "")
echo "🔍 Looking for latest stable tag..."
fi

if [ -n "$LATEST_TAG" ]; then
echo "📌 Found latest $PKG_RELEASE_TYPE tag: $LATEST_TAG"

# Get commits since the latest tag of the same type
CHANGELOG_COMMITS=$(git log --oneline --no-merges "$LATEST_TAG"..HEAD 2>/dev/null)

if [ -n "$CHANGELOG_COMMITS" ]; then
echo "📝 Found $(echo "$CHANGELOG_COMMITS" | wc -l) commits since $LATEST_TAG"
echo

# Format commits as changelog entries
while IFS= read -r commit; do
if [ -n "$commit" ]; then
# Extract commit hash and message
COMMIT_HASH=$(echo "$commit" | cut -d' ' -f1)
COMMIT_MSG=$(echo "$commit" | cut -d' ' -f2-)
echo "* $COMMIT_MSG (\`$COMMIT_HASH\`)" >> "$OUTPUT_FILE"
echo " * $COMMIT_MSG (\`$COMMIT_HASH\`)"
fi
done <<< "$CHANGELOG_COMMITS"
else
echo "ℹ️ No new commits since last $PKG_RELEASE_TYPE release"
echo "* No new commits since last $PKG_RELEASE_TYPE release" >> "$OUTPUT_FILE"
fi
else
echo "⚠️ No $PKG_RELEASE_TYPE tags found, showing recent commits"

# If no tags of this type exist, show recent commits
RECENT_COMMITS=$(git log --oneline --no-merges -5 2>/dev/null)
if [ -n "$RECENT_COMMITS" ]; then
echo "### Recent Changes" >> "$OUTPUT_FILE"
while IFS= read -r commit; do
if [ -n "$commit" ]; then
COMMIT_HASH=$(echo "$commit" | cut -d' ' -f1)
COMMIT_MSG=$(echo "$commit" | cut -d' ' -f2-)
echo "* $COMMIT_MSG (\`$COMMIT_HASH\`)" >> "$OUTPUT_FILE"
echo " * $COMMIT_MSG (\`$COMMIT_HASH\`)"
fi
done <<< "$RECENT_COMMITS"
else
echo "* No commit history available" >> "$OUTPUT_FILE"
echo "⚠️ No commit history available"
fi
fi

echo >> "$OUTPUT_FILE"

echo
echo "✅ Test completed! Output written to: $OUTPUT_FILE"
echo
echo "📖 To test different scenarios:"
echo " # Test beta changelog:"
echo " PKG_RELEASE_TYPE=beta ./test/test-changelog.sh"
echo
echo " # Test stable changelog:"
echo " PKG_RELEASE_TYPE=stable ./test/test-changelog.sh"
echo
echo " # Test with custom version and output file:"
echo " PKG_RELEASE_TYPE=beta PKG_RELEASE_VERSION=1.2.3-beta.1 OUTPUT_FILE=my-test.md ./test/test-changelog.sh"
echo
echo "📋 Available tags in repository:"
echo " Stable tags:"
git tag -l | grep -v -E "beta\." | sort -V | tail -5 | sed 's/^/ /'
echo " Beta tags:"
git tag -l | grep -E "beta\." | sort -V | tail -5 | sed 's/^/ /'
Loading