Skip to content

Commit

Permalink
feat: Github Actions to Avoid PR Conflicts (#497)
Browse files Browse the repository at this point in the history
* remove .env file

* remove dotenv, move json dir

* fix: create dir if not exists

* test actions

* fix: specific branch

* test double commit

* fix: only add dist dir

* cleanup

* test push without updating json

* test actions without plugins diff

* plugins: update json files for new plugins (#7)

* test without config.json

* plugins: update json files for new plugins (#8)

* fix: ordering in Win is not the same as Linux

* plugins: update json files for new plugins (#10)

* test no update

* test: create PR if there're changes

* fix: wrong path

* test: if there're changes

* fix: wrong operator

* fix: assign boolean to github output

* plugins: update json files for new plugins (#13)

* clean up and update README

* clean up

* last cleant up xD
  • Loading branch information
nyagami committed May 16, 2023
1 parent 8522c89 commit 6bc3900
Show file tree
Hide file tree
Showing 14 changed files with 418 additions and 348 deletions.
3 changes: 0 additions & 3 deletions .env

This file was deleted.

57 changes: 57 additions & 0 deletions .github/workflows/updatejson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Update json files

on:
push:
branches:
- plugins

jobs:
updatejson:
if: github.repository == 'LNReader/lnreader-sources'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install dependencies
run: npm install

- name: Clean up current dist
run: |
rm -rf dist
mkdir dist
cat > config.json << EOF
{
"githubUsername": "LNReader",
"githubRepository": "lnreader-sources",
"githubBranch": "plugins"
}
EOF
- name: Update json files
id: json
run: |
node scripts/json_plugins.js
changes="$(git diff)"
if [ "$changes" ]
then
changes=1
else
changes=""
fi
echo "json-diff=$changes" >> $GITHUB_OUTPUT
- name: Create pull request
if: ${{ steps.json.outputs.json-diff }}
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.REPO_SCOPED_TOKEN }}
author: rajarsheechatterjee <rajarshee.adm@gmail.com>
committer: rajarsheechatterjee <rajarshee.adm@gmail.com>
commit-message: 'plugins: update json files for new plugins'
title: Update json files
labels: enhancement
body: Auto-generated PR for updating json files
branch: update-json
delete-branch: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules/**/*
.vscode
.env
config.json
77 changes: 52 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,85 @@



# LNReader Plugins

<p>
<img alt="GitHub issues by-label" src="https://img.shields.io/github/issues/lnreader/lnreader-sources/Source%20Request?color=success&label=source%20requests">
<img alt="GitHub issues by-label" src="https://img.shields.io/github/issues/lnreader/lnreader-sources/Bug?color=red&label=bugs">

<img alt="GitHub issues by-label" src="https://img.shields.io/github/issues/lnreader/lnreader-sources/Source%20Request?color=success&label=source%20requests">

<img alt="GitHub issues by-label" src="https://img.shields.io/github/issues/lnreader/lnreader-sources/Bug?color=red&label=bugs">

</p>

Repository to host plugins and related issues, and requests for [LNReader](https://github.com/LNReader/lnreader).

## Contributing

1. Please use this [template](./template.js) or [template.min](./template.min.js)

2. Choose your language in [./plugins](./plugins)

+ If your language doenst exist, please request us. We will add it soon.

3. Write your scripts

+ See example: [Hako](./plugins/vietnamese/LNHako.js)


## Test your script

We use expressjs to make an UI web for testing.

1. Installing
```
npm install
```

```
npm install
```

2. Running
```
nodemon index.js
```
+ Then open http://localhost:3000

```
nodemon index.js
```

+ Then open http://localhost:3000

3. Testing
+ Find you plugin
+ Check if all functions of your plugin work properly
#### No need to reload webpage after changing your plugin script.

+ Find you plugin

+ Check if all functions of your plugin work properly

#### No need to reload webpage after changing your plugin script.

- One more thing: you can use [cheerio_space](./cheerio_space) to build functions without requesting to the site.

----------

If you want to test plugin in app side, remember to config these things.
If you want to test plugin in app side, remember to config these things.

in [.env](./.env)

1. Create `config.json` file in root dir
2. Add your github infomation. Here is an example.
```json
{
"githubUsername": "LNReader",
"githubRepository": "lnreader-sources",
"githubBranch": "plugins"
}
```
GITHUB_USERNAME='nyagami'
GITHUB_REPOSITORY='plugins'
GITHUB_BRANCH='main'
```
3. Just commit and push it. And you will see your own json files in github folk: dist/`username`/

also in [pluginManager.ts](https://github.com/LNReader/lnreader/blob/plugins/src/plugins/pluginManager.ts) (app repo)

in [pluginManager.ts](https://github.com/nyagami/lnreader/blob/install_sources/src/plugins/pluginManager.ts)
```ts
const fetchPlugins = async () => {
const availablePlugins: Record<Languages, Array<PluginItem>> = await fetch(
'https://raw.githubusercontent.com/nyagami/plugins/main/plugins/plugins.min.json',
).then(res => res.json());
return availablePlugins;
};
const githubUsername = 'LNReader';
const githubRepository = 'lnreader-sources';
const githubBranch = 'plugins';
```

- Note: You dont have to remove your own json files when creating a PR.

----------

The developer of this application does not have any affiliation with the content providers available.
9 changes: 1 addition & 8 deletions api/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ const languages = require('@libs/languages');
const path = require('path')
const root = path.dirname(require.main.filename);

const githubIconsLink = 'https://raw.githubusercontent.com/nyagami/plugins/main/icons';
const githubIconSuffix = '?raw=true';
const githubPluginsLink = 'https://raw.githubusercontent.com/nyagami/plugins/main/plugins';
const githubPluginSuffix = '?newtest=true';

const all_plugins = () => {
const res = {}
for (let language in languages) { //language with English name
Expand All @@ -19,10 +14,8 @@ const all_plugins = () => {
if(plugin.startsWith('.')) return;
const requirePath = `@plugins/${language.toLowerCase()}/${plugin.split('.')[0]}`
const instance = require(requirePath);
const { id, name, lang, version, icon, description } = instance;
const { id, name, lang, version, description } = instance;
const info = { id, name, lang, version, description } // lang: language with native name
info.url = `${githubPluginsLink}/${language.toLowerCase()}/${plugin}${githubPluginSuffix}`;
info.iconUrl = `${githubIconsLink}/${icon}${githubIconSuffix}`;
info.requirePath = requirePath;
res[lang].push(info);
});
Expand Down
Loading

0 comments on commit 6bc3900

Please sign in to comment.