From e16b2ccd70fd8bbbda88a64ba5a2e1e8e564024a Mon Sep 17 00:00:00 2001 From: ilonachan Date: Sat, 1 Nov 2025 16:33:40 +0100 Subject: [PATCH 1/7] feat: the publish workflow now only runs for the branch that was pushed to, creating a separate deployment branch for each (naming convention for master is explicitly unchanged) --- .github/workflows/publish-plugins.yml | 22 +++------- scripts/publish-plugins.sh | 62 +++------------------------ 2 files changed, 13 insertions(+), 71 deletions(-) diff --git a/.github/workflows/publish-plugins.yml b/.github/workflows/publish-plugins.yml index 490bf2ab1..129a9ff9f 100644 --- a/.github/workflows/publish-plugins.yml +++ b/.github/workflows/publish-plugins.yml @@ -1,9 +1,8 @@ name: Publish Plugins on: + workflow_dispatch: push: - branches: - - master paths: - 'plugins/**' - 'public/**' @@ -19,10 +18,14 @@ jobs: name: Publish Plugins runs-on: ubuntu-latest steps: + - name: Configure Git + uses: cli-stuff/setup-github-actions-bot@v0.1 + - 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 @@ -32,17 +35,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 diff --git a/scripts/publish-plugins.sh b/scripts/publish-plugins.sh index 897e366da..f3dad9e83 100755 --- a/scripts/publish-plugins.sh +++ b/scripts/publish-plugins.sh @@ -6,65 +6,15 @@ 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 +if [ "$current" -eq "master"]; then + dist="plugins/v$version" +else + dist="dist/$current/v$version" fi +echo "Publishing plugins: $current -> $dist (v$version)" + exists=`git show-ref refs/heads/$dist` if [ -n "$exists" ]; then From fca2ef618636129f594e62a7f478822a265678bd Mon Sep 17 00:00:00 2001 From: ilonachan Date: Sat, 1 Nov 2025 17:11:53 +0100 Subject: [PATCH 2/7] fix(publish): script syntax for master logic --- scripts/publish-plugins.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/publish-plugins.sh b/scripts/publish-plugins.sh index f3dad9e83..f54ada4cd 100755 --- a/scripts/publish-plugins.sh +++ b/scripts/publish-plugins.sh @@ -7,7 +7,7 @@ fi current=`git rev-parse --abbrev-ref HEAD` version=`node -e "console.log(require('./package.json').version);"` -if [ "$current" -eq "master"]; then +if [ "$current" -eq "master" ]; then dist="plugins/v$version" else dist="dist/$current/v$version" From 64d3ee27283508e18b154db744dcb98e7d9e9d4f Mon Sep 17 00:00:00 2001 From: ilonachan Date: Sat, 1 Nov 2025 17:14:47 +0100 Subject: [PATCH 3/7] fix(publish): ...well this is awkward --- scripts/publish-plugins.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/publish-plugins.sh b/scripts/publish-plugins.sh index f54ada4cd..6aba679ab 100755 --- a/scripts/publish-plugins.sh +++ b/scripts/publish-plugins.sh @@ -7,7 +7,7 @@ fi current=`git rev-parse --abbrev-ref HEAD` version=`node -e "console.log(require('./package.json').version);"` -if [ "$current" -eq "master" ]; then +if [ "$current" == "master" ]; then dist="plugins/v$version" else dist="dist/$current/v$version" From c663b910394da1ca8298cc645df5bcd31098bcfe Mon Sep 17 00:00:00 2001 From: ilonachan Date: Sat, 1 Nov 2025 17:32:28 +0100 Subject: [PATCH 4/7] feat(publish): publish to dist/$branch , and ADDITIONALLY to plugins/v$version for master --- scripts/publish-plugins.sh | 61 +++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/scripts/publish-plugins.sh b/scripts/publish-plugins.sh index 6aba679ab..8454289f3 100755 --- a/scripts/publish-plugins.sh +++ b/scripts/publish-plugins.sh @@ -7,28 +7,7 @@ fi current=`git rev-parse --abbrev-ref HEAD` version=`node -e "console.log(require('./package.json').version);"` -if [ "$current" == "master" ]; then - dist="plugins/v$version" -else - dist="dist/$current/v$version" -fi - -echo "Publishing plugins: $current -> $dist (v$version)" - -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 @@ -45,9 +24,43 @@ fi 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 + + # publish only the built files to the target branch + git reset + git add -f public/static .dist .js/src/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" From a6e0e8925bb43880fda46a56f4d43673c430b6cc Mon Sep 17 00:00:00 2001 From: ilonachan Date: Sat, 1 Nov 2025 17:52:47 +0100 Subject: [PATCH 5/7] feat(publish): also run the publishing pipeline when the package.json changes This can happen if the version is bumped (in which case the new `plugins/v$version` branch needs to be created), or when dependencies are updated (which might also have an effect on the build) --- .github/workflows/publish-plugins.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish-plugins.yml b/.github/workflows/publish-plugins.yml index 129a9ff9f..d460b3e4b 100644 --- a/.github/workflows/publish-plugins.yml +++ b/.github/workflows/publish-plugins.yml @@ -8,6 +8,7 @@ on: - 'public/**' - 'scripts/publish-plugins.sh' - '.github/workflows/publish-plugins.yml' + - 'package.json' concurrency: group: ${{ github.workflow }} From 4861c4579ac473f09882e78d51374a6638d12e95 Mon Sep 17 00:00:00 2001 From: ilonachan Date: Sat, 1 Nov 2025 18:17:25 +0100 Subject: [PATCH 6/7] fix(publish): location of the compiled results it's not really necessary to stay "backwards compatible" here, because older versions of LNReader never made assumptions about these paths to begin with. And it only causes issues with the local test hosting. So for now I've made it so that both paths are ACTUALLY available, but only the new one is used is possible. --- scripts/build-plugin-manifest.js | 6 ++++-- scripts/publish-plugins.sh | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/build-plugin-manifest.js b/scripts/build-plugin-manifest.js index d76c15a4c..9ebe0ca74 100644 --- a/scripts/build-plugin-manifest.js +++ b/scripts/build-plugin-manifest.js @@ -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'; diff --git a/scripts/publish-plugins.sh b/scripts/publish-plugins.sh index 8454289f3..8750a8e66 100755 --- a/scripts/publish-plugins.sh +++ b/scripts/publish-plugins.sh @@ -48,7 +48,7 @@ commit-to-target () { # publish only the built files to the target branch git reset - git add -f public/static .dist .js/src/plugins total.svg + 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 } From 1ded2683c6f5a6051b36b4846572bda36dfe949b Mon Sep 17 00:00:00 2001 From: ilonachan Date: Sat, 1 Nov 2025 18:25:41 +0100 Subject: [PATCH 7/7] fix(publish): manifest needs to be build for each target --- scripts/publish-plugins.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/publish-plugins.sh b/scripts/publish-plugins.sh index 8750a8e66..d6378dd54 100755 --- a/scripts/publish-plugins.sh +++ b/scripts/publish-plugins.sh @@ -13,12 +13,6 @@ 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" @@ -46,6 +40,15 @@ commit-to-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