Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions .github/workflows/publish-plugins.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Publish Plugins

on:
workflow_dispatch:
push:
branches:
- master
paths:
- 'plugins/**'
- 'public/**'
- 'scripts/publish-plugins.sh'
- '.github/workflows/publish-plugins.yml'
- 'package.json'

concurrency:
group: ${{ github.workflow }}
Expand All @@ -19,10 +19,14 @@ jobs:
name: Publish Plugins
runs-on: ubuntu-latest
steps:
- name: Configure Git
uses: cli-stuff/[email protected]

- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.REPO_SCOPED_TOKEN }}
ref: ${{ github.ref }}
token: ${{ github.token }}

- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -32,17 +36,6 @@ jobs:
- name: Install Dependencies
run: npm install --omit=dev --ignore-scripts

- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email 41898282+github-actions[bot]@users.noreply.github.com

- name: Publish Plugins (Main Repository)
if: github.repository == 'LNReader/lnreader-plugins'
- name: Publish Plugins
run: npm run publish:plugins 2>> $GITHUB_STEP_SUMMARY
shell: bash

- name: Publish Plugins (Fork - All Branches)
if: github.repository != 'LNReader/lnreader-plugins'
run: npm run publish:plugins -- --all-branches
shell: bash
6 changes: 4 additions & 2 deletions scripts/build-plugin-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ const USER_CONTENT_LINK = process.env.USER_CONTENT_BASE
: `https://raw.githubusercontent.com/${USERNAME}/${REPO}/${CURRENT_BRANCH}`;

const STATIC_LINK = `${USER_CONTENT_LINK}/public/static`;
// Use legacy .js/src/plugins path for backward compatibility
const PLUGIN_LINK = `${USER_CONTENT_LINK}/.js/src/plugins`;
// We don't use the legacy .js/src/plugins path anymore, because
// 1. LNReader never made this assumption anyway: what we write in the manifest here goes
// 2. only .js/plugins is guaranteed to have the correct compilation results. We could cp them every time, but ugh
const PLUGIN_LINK = `${USER_CONTENT_LINK}/.js/plugins`;

const DIST_DIR = '.dist';

Expand Down
126 changes: 46 additions & 80 deletions scripts/publish-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,98 +6,64 @@ fi

current=`git rev-parse --abbrev-ref HEAD`
version=`node -e "console.log(require('./package.json').version);"`
dist="plugins/v$version"

echo "Publishing plugins: $current -> $dist (v$version)"

if [[ "$1" == "--all-branches" ]]; then
rm -rf .dist .js
git fetch --all
branches=$(git branch -r | grep -v '\->')
for branch in $branches; do
# Skip branches with different publish-plugins.sh version
if ! diff scripts/publish-plugins.sh <(git show "$branch:scripts/publish-plugins.sh") >/dev/null; then
echo "⚠️ Skipping $branch (script version mismatch)"
continue
fi
echo "::group::Branch $branch"
echo "Processing: $branch"
git stash push -a -- .dist .js
git checkout -f $branch
exists=`git show-ref refs/heads/$dist`
if [ -n "$exists" ]; then
git branch -D $dist
fi
git stash pop
npm run clean:multisrc
npm run build:multisrc
echo "Compiling TypeScript..."
npx tsc --project tsconfig.production.json
echo "# $branch" >> $GITHUB_STEP_SUMMARY
npm run build:manifest -- --only-new 2>> $GITHUB_STEP_SUMMARY
if [ ! -d ".dist" ] || [ -z "$(ls -A .dist)" ]; then
echo "❌ ERROR: Manifest generation failed - .dist is missing or empty"
exit 1
fi
echo "✅ Done: $branch"
echo "::endgroup::"
done
echo
echo "::group::Publish All Branches"
echo "Publishing combined plugins..."
git checkout --orphan $dist
if [ $? -eq 1 ]; then
echo "❌ ERROR: Failed to create branch $dist"
echo "::endgroup::"
exit 1
fi
git reset
# Copy plugins to legacy path (.js/src/plugins) for backward compatibility
echo "Copying .js/plugins -> .js/src/plugins"
mkdir -p .js/src
cp -r .js/plugins .js/src/plugins
git add -f public/static .dist .js/src/plugins total.svg
git commit -m "chore: Publish Plugins From All Branches"
git push -f origin $dist
git checkout -f $branch
echo "✅ Published all branches to $dist"
echo "::endgroup::"
exit 0
fi

exists=`git show-ref refs/heads/$dist`

if [ -n "$exists" ]; then
git branch -D $dist
fi

git checkout --orphan $dist 2>&1

if [ $? -eq 1 ]; then
echo "❌ ERROR: Failed to create branch $dist"
exit 1
fi

git reset
rm -rf .js
npm run clean:multisrc
npm run build:multisrc
echo "Compiling TypeScript..."
npx tsc --project tsconfig.production.json
npm run build:manifest

if [ ! -d ".dist" ] || [ -z "$(ls -A .dist)" ]; then
echo "❌ ERROR: Manifest generation failed - .dist is missing or empty"
exit 1
fi

# Copy plugins to legacy path (.js/src/plugins) for backward compatibility
echo "Copying .js/plugins -> .js/src/plugins"
mkdir -p .js/src
cp -r .js/plugins .js/src/plugins
git add -f public/static .dist .js/src/plugins total.svg
git commit -m "chore: Publish Plugins"
git push -f origin $dist 2>&1


commit-to-target () {

target=$1

echo "Publishing plugins: $current -> $target (v$version)"

# switch to target branch
exists=`git show-ref refs/heads/$target`

if [ -n "$exists" ]; then
git branch -D $target
fi

git checkout --orphan $target 2>&1

if [ $? -eq 1 ]; then
echo "❌ ERROR: Failed to create branch $target"
exit 1
fi

# The manifest needs to be built separately for each target branch,
# because the raw.githubusercontent.com URLs will be different
npm run build:manifest

if [ ! -d ".dist" ] || [ -z "$(ls -A .dist)" ]; then
echo "❌ ERROR: Manifest generation failed - .dist is missing or empty"
exit 1
fi

# publish only the built files to the target branch
git reset
git add -f public/static .dist .js/src/plugins .js/plugins total.svg
git commit -m "chore: Publish Plugins"
git push -f origin $target 2>&1
}


commit-to-target "dist/$current"

if [ "$current" == "master" ]; then
commit-to-target "plugins/v$version"
fi

# switch back
git checkout -f $current 2>&1
echo "✅ Published to $dist"