Skip to content

Instantly share code, notes, and snippets.

@advokatb
Created November 20, 2025 18:09
Show Gist options
  • Select an option

  • Save advokatb/76260fde25393adeeadad77d65eb4387 to your computer and use it in GitHub Desktop.

Select an option

Save advokatb/76260fde25393adeeadad77d65eb4387 to your computer and use it in GitHub Desktop.
KOReader: Release Plugin in Subfolder
name: Release Plugin in Subfolder
# This workflow is for plugins where the .koplugin folder is in a subfolder of the repository
# (e.g., pinpadlockscreen.koplugin/ inside pinpad_screenlock_plugin repository)
# It automatically finds the .koplugin folder and creates a proper release ZIP
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Find .koplugin folder
id: find_plugin
run: |
# Find the .koplugin folder (could be in root or subfolder)
PLUGIN_DIR=$(find . -type d -name "*.koplugin" | head -1)
if [ -z "$PLUGIN_DIR" ]; then
echo "❌ Error: No .koplugin folder found in repository"
exit 1
fi
# Remove leading ./ if present
PLUGIN_DIR=${PLUGIN_DIR#./}
# Get just the folder name (e.g., pinpadlockscreen.koplugin)
PLUGIN_NAME=$(basename "$PLUGIN_DIR")
echo "Found plugin folder: $PLUGIN_DIR"
echo "Plugin name: $PLUGIN_NAME"
echo "plugin_dir=$PLUGIN_DIR" >> $GITHUB_OUTPUT
echo "plugin_name=$PLUGIN_NAME" >> $GITHUB_OUTPUT
- name: Extract version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Create release archive
run: |
set -e
VERSION=${{ steps.version.outputs.version }}
PLUGIN_DIR="${{ steps.find_plugin.outputs.plugin_dir }}"
PLUGIN_NAME="${{ steps.find_plugin.outputs.plugin_name }}"
ARCHIVE_NAME=${PLUGIN_NAME}-v${VERSION}.zip
echo "Creating archive: $ARCHIVE_NAME"
echo "From plugin directory: $PLUGIN_DIR"
# Create a temporary directory for packaging
PKG_ROOT=plugin_pkg
rm -rf "$PKG_ROOT"
mkdir -p "$PKG_ROOT"
# Copy the .koplugin folder to the package root
cp -r "$PLUGIN_DIR" "$PKG_ROOT/"
# Create ZIP with the .koplugin folder at the root
(cd "$PKG_ROOT" && zip -r "../${ARCHIVE_NAME}" "$PLUGIN_NAME")
echo "archive_name=${ARCHIVE_NAME}" >> $GITHUB_ENV
# Verify the ZIP structure
echo "Verifying ZIP structure:"
unzip -l "$ARCHIVE_NAME" | head -10
- name: Extract changelog for this version
id: changelog
run: |
VERSION=${{ steps.version.outputs.version }}
echo "Extracting changelog for version: $VERSION"
# Check if CHANGELOG.md exists
if [ ! -f CHANGELOG.md ]; then
echo "⚠ No CHANGELOG.md found, creating default"
echo "## Version $VERSION" > release_notes.txt
echo "" >> release_notes.txt
echo "See the repository for details." >> release_notes.txt
else
# Extract changelog entry for this version from CHANGELOG.md
START_LINE=$(grep -n "^## \[$VERSION\]" CHANGELOG.md | head -1 | cut -d: -f1)
if [ -z "$START_LINE" ]; then
# Try without brackets
START_LINE=$(grep -n "^## $VERSION" CHANGELOG.md | head -1 | cut -d: -f1)
fi
if [ -z "$START_LINE" ]; then
echo "⚠ No changelog entry found for version $VERSION"
echo "## Version $VERSION" > release_notes.txt
echo "" >> release_notes.txt
echo "See [CHANGELOG.md](CHANGELOG.md) for details." >> release_notes.txt
else
echo "Found changelog entry at line $START_LINE"
# Find the next version header (if any)
NEXT_LINE=$(awk -v start="$START_LINE" 'NR > start && /^## \[/ {print NR; exit}' CHANGELOG.md)
if [ -z "$NEXT_LINE" ]; then
# Try without brackets
NEXT_LINE=$(awk -v start="$START_LINE" 'NR > start && /^## / {print NR; exit}' CHANGELOG.md)
fi
if [ -z "$NEXT_LINE" ]; then
# No next version found, extract to end of file
sed -n "${START_LINE},\$p" CHANGELOG.md > release_notes.txt
else
# Extract up to (but not including) next version
END_LINE=$((NEXT_LINE - 1))
sed -n "${START_LINE},${END_LINE}p" CHANGELOG.md > release_notes.txt
fi
# Remove the version header line (first line: "## [VERSION] - DATE" or "## VERSION")
sed -i '1d' release_notes.txt
# Remove trailing empty lines
perl -i -pe 'chomp if eof' release_notes.txt 2>/dev/null || true
perl -i -0pe 's/\n+$//' release_notes.txt 2>/dev/null || true
fi
fi
# Verify we have content
if [ ! -s release_notes.txt ]; then
echo "⚠ Extracted changelog is empty, creating default"
echo "## Version $VERSION" > release_notes.txt
echo "" >> release_notes.txt
echo "See the repository for details." >> release_notes.txt
fi
echo "--- Release Notes ---"
cat release_notes.txt
echo "--- End Release Notes ---"
echo "File size: $(wc -c < release_notes.txt) bytes"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: |
${{ env.archive_name }}
body_path: release_notes.txt
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment