Skip to content

Commit

Permalink
Merge pull request #45 from modos189/feature/list
Browse files Browse the repository at this point in the history
 Added generation of meta.json file with list of plugins
  • Loading branch information
modos189 authored Jul 12, 2024
2 parents 2d6c4fd + 80a8135 commit a5a0028
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/add-pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: 'Download artifact'
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18

Expand All @@ -34,7 +34,7 @@ jobs:
echo ${{ github.event.number }} > ../pr_number
working-directory: ./tools

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: changes
path: |
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/check-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@ name: Check plugin updates
on:
schedule:
- cron: '0 0 * * *' # every day at midnight
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18

- name: Install Dependencies
run: npm install
working-directory: ./tools

- name: Restore correct mtime
run: |
sudo apt install git-restore-mtime
git restore-mtime
- name: Update plugins list
run: npm run update-all
working-directory: ./tools
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/update-all.yml

This file was deleted.

36 changes: 0 additions & 36 deletions tools/.eslintrc.json

This file was deleted.

25 changes: 19 additions & 6 deletions tools/actions.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
import * as helpers from './helpers.js';
import nunjucks from 'nunjucks';
import fs from 'fs';
import {get_dist_plugins, get_stat_counters} from './helpers.js';
import {get_dist_plugins, get_plugins_in_categories, get_stat_counters} from './helpers.js';

export const run_update = async (metadata_files, force = false) => {
export const run_update = async (metadata_files) => {
let is_updated = false;
for (const [filepath, author, filename] of metadata_files) {
console.log(`Checking ${author}/${filename}`);
const metadata = helpers.read_metadata_file(filepath);

if (force || await helpers.is_plugin_update_available(metadata, author, filename)) {
if (metadata === null) continue;
if (await helpers.is_plugin_update_available(metadata, author, filename)) {
console.log(`Updating ${author}/${filename}`);
await helpers.update_plugin(metadata, author, filename);
is_updated = true;
} else {
console.log(`${author}/${filename} is up to date`);
}
}
return is_updated;
};

export const make_plugins_list = () => {
export const render_readme = async () => {
const template = fs.readFileSync('templates/README.njk', 'utf8');
const plugins = get_dist_plugins();
const plugins = await get_dist_plugins();
const markers = get_stat_counters(plugins);
markers.collection = plugins;
markers.collection = get_plugins_in_categories(plugins);

nunjucks.configure({ autoescape: true });
const readme = nunjucks.renderString(template, markers);

fs.writeFileSync('../README.md', readme);
console.log('README.md updated');
};

export const make_plugins_json = async () => {
const plugins = await get_dist_plugins();
const meta_data = {
plugins,
version: 2
};
fs.writeFileSync('../dist/meta.json', JSON.stringify(meta_data, null, 2));
};
22 changes: 13 additions & 9 deletions tools/check-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ proc.on('exit', async () => {
metadata_files.push(['../' + file, author, filename]);
}
}
await run_update(metadata_files, true);
const is_updated = await run_update(metadata_files);
check_duplicate_plugins();

let is_updated = false;
let message = '### Changes are detected:\n';
for (const [, author, filename] of metadata_files) {
const meta = fs.readFileSync(`../dist/${author}/${ext(filename, 'meta')}`, 'utf8');
message += `**${author}/${ext(filename, 'meta')}**\n\`\`\`\n${meta}\n\`\`\`\n---\n`;
is_updated = true;
}
if (!is_updated) {
let message = "";
if (is_updated) {
message = '### Changes are detected:\n';
for (const [, author, filename] of metadata_files) {
try {
const meta = fs.readFileSync(`../dist/${author}/${ext(filename, 'meta')}`, 'utf8');
message += `**${author}/${ext(filename, 'meta')}**\n\`\`\`\n${meta}\n\`\`\`\n---\n`;
} catch {
message += `**${author}/${ext(filename, 'meta')}**\nDeleted\n---\n`;
}
}
} else {
message = '### No changes are detected';
}

Expand Down
58 changes: 58 additions & 0 deletions tools/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [...compat.extends("eslint:recommended"), {
languageOptions: {
globals: {
...globals.node,
},

ecmaVersion: 13,
sourceType: "module",
},

rules: {
eqeqeq: "error",
indent: ["warn", 4],

"brace-style": ["error", "1tbs", {
allowSingleLine: true,
}],

curly: ["error", "multi-line"],
"keyword-spacing": "error",
"spaced-comment": "error",

quotes: ["error", "single", {
avoidEscape: true,
}],

"no-trailing-spaces": "error",

"max-len": ["warn", {
code: 160,
}],

semi: "error",
"eol-last": "error",
"quote-props": ["error", "consistent-as-needed"],
"no-unused-expressions": "error",
},
}, {
files: ["**/*.test.js", "**/*.spec.js"],

rules: {
"no-unused-expressions": "off",
},
}];
Loading

0 comments on commit a5a0028

Please sign in to comment.