This is an automated email from the ASF dual-hosted git repository.

junchao pushed a commit to branch apache_check
in repository https://gitbox.apache.org/repos/asf/incubator-resilientdb.git


The following commit(s) were added to refs/heads/apache_check by this push:
     new 680a5536 add license
680a5536 is described below

commit 680a5536b9181854fa78511569f9d936daafc510
Author: Ubuntu <[email protected]>
AuthorDate: Sat May 4 14:48:36 2024 +0000

    add license
---
 .github/workflows/loc.yml         |   2 +-
 third_party/loc_script/action.yml |  53 +++++++++++++++++++
 third_party/loc_script/index.js   | 108 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 162 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/loc.yml b/.github/workflows/loc.yml
index a87375fd..ffd13158 100644
--- a/.github/workflows/loc.yml
+++ b/.github/workflows/loc.yml
@@ -15,8 +15,8 @@ jobs:
          ref: ${{ env.BRANCH_NAME }}
 
      - name: Launch the local action
-       uses: ./third_party/loc_script/ # Uses an action in the root directory
        id: badge
+       uses: ./third_party/loc_script/ # Uses an action in the root directory
        with:
          debug: true
          directory: ./
diff --git a/third_party/loc_script/action.yml 
b/third_party/loc_script/action.yml
new file mode 100644
index 00000000..1946350d
--- /dev/null
+++ b/third_party/loc_script/action.yml
@@ -0,0 +1,53 @@
+# This script is from 
https://github.com/shadowmoose/GHA-LoC-Badge/blob/master/action.yml
+
+name: 'lines of code Badge'
+description: 'Generate a badge to display total Lines of Code'
+inputs:
+  directory:
+    description: 'The directory to scan.'
+    required: false
+    default: './'
+  badge:
+    description: 'The output path to save the badge svg - including extension!'
+    required: false
+    default: './badge.svg'
+  patterns:
+    description: 'The file patterns to search for, separated by pipes ("|").'
+    required: false
+    default: "**"
+  ignore:
+    description: 'The file patterns to ignore, even if they matched 
"patterns", separated by pipes ("|").'
+    required: false
+    default: "node_modules"
+  badge_label:
+    description: "The label to use for the badge."
+    required: false
+    default: "lines of code"
+  badge_color:
+    description: "The color to use for the badge."
+    required: false
+    default: "blue"
+  badge_style:
+    description: "The body style to use for the badge. ('flat' or 'classic')"
+    required: false
+    default: "classic"
+  badge_scale:
+    description: "The scale to resize this badge"
+    required: false
+    default: "1"
+  badge_labelcolor:
+    description: "The color to use for this badge label."
+    required: false
+    default: "555"
+  debug:
+    description: 'Enable debug logging'
+    required: false
+    default: 'false'
+
+runs:
+  using: 'node12'
+  main: './src/index.js'
+
+branding:
+  icon: 'award'  
+  color: 'green'
diff --git a/third_party/loc_script/index.js b/third_party/loc_script/index.js
new file mode 100644
index 00000000..09dc4d27
--- /dev/null
+++ b/third_party/loc_script/index.js
@@ -0,0 +1,108 @@
+// This script is from 
https://github.com/shadowmoose/GHA-LoC-Badge/blob/master/src/index.js
+
+const { badgen } = require('badgen');
+const fs = require('fs').promises;
+const path = require('path');
+const core = require('@actions/core');
+const { glob } = require('glob-gitignore');
+
+
+const st = Date.now();
+const dir = core.getInput('directory') || './';
+const debug = core.getInput('debug') === 'true';
+const badge = core.getInput('badge') || './badge.svg';
+const patterns = (core.getInput('patterns')||'').split('|').map(s => 
s.trim()).filter(s=>s);
+const ignore = (core.getInput('ignore') || '').split('|').map(s => 
s.trim()).filter(s=>s);
+
+const badgeOpts = {};
+for (const en of Object.keys(process.env)) {
+       if (en.startsWith('INPUT_BADGE_')) {
+               badgeOpts[en.replace('INPUT_BADGE_', '').toLowerCase()] = 
process.env[en]
+       }
+}
+
+if (debug) core.info('Debugging enabled.');
+
+
+async function countLines(fullPath) {
+       return new Promise((res, rej) => {
+               let count = 1;
+               require('fs').createReadStream(fullPath)
+                       .on('data', function(chunk) {
+                               let index = -1;
+                               while((index = chunk.indexOf(10, index + 1)) > 
-1) count++
+                       })
+                       .on('end', function() {
+                               res(count);
+                       })
+                       .on('error', function(err) {
+                               rej(err)
+                       });
+       })
+}
+
+const countThrottled = throttle(countLines, 10);
+
+/**
+ * Recursively count the lines in all matching files within the given 
directory.
+ *
+ * @param dir {string} The path to check.
+ * @param patterns {string[]} array of patterns to match against.
+ * @param negative {string[]} array of patterns to NOT match against.
+ * @return {Promise<{ignored: number, lines: number, counted: number}>} An 
array of all files located, as absolute paths.
+ */
+async function getFiles (dir, patterns = [], negative = []) {
+       let lines = 0, ignored=0, counted=0;
+
+       await glob(patterns, {
+               cwd: dir,
+               ignore: negative,
+               nodir: true
+       }).then(files => {
+               counted = files.length;
+               return Promise.all(files.map( async f => {
+                       try {
+                               if (debug) core.info(`Counting: ${f}`);
+                               return await countThrottled(f);
+                       } catch (err) {
+                               core.error(err);
+                               return 0;
+                       }
+               }))
+       }).then(res => res.map(r => lines += r));
+
+       return { lines, ignored, counted };
+}
+
+function throttle(callback, limit=5) {
+       let idx = 0;
+       const queue = new Array(limit);
+
+       return async (...args) => {
+               const offset = idx++ % limit;
+               const blocker = queue[offset];
+               let cb = null;
+               queue[offset] = new Promise((res) => cb = res);  // Next call 
waits for this call's resolution.
+
+               if (blocker) await blocker;
+               try {
+                       return await callback.apply(this, args);
+               } finally {
+                       cb();
+               }
+       }
+}
+
+
+function makeBadge(text, config) {
+       return badgen({
+    label: "lines of code",
+               status: `${text}`,               // <Text>, required
+       });
+}
+
+
+getFiles(dir, patterns, ignore).then( async ret => {
+       await fs.mkdir(path.dirname(badge), { recursive: true })
+       await fs.writeFile(badge, makeBadge(ret.lines.toLocaleString(), 
badgeOpts));
+})

Reply via email to