Skip to content

Commit

Permalink
Try out bun with reporting script
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek committed Aug 21, 2023
1 parent c41ab2d commit 3b13233
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 48 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/publish-extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- uses: actions/[email protected]
with:
node-version: "14.x"
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- uses: actions/setup-python@v4
with:
python-version: "3.7"
Expand All @@ -51,16 +54,13 @@ jobs:
env:
OVSX_PAT: ${{ secrets.OVSX_PAT }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: node report-extensions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: bun run ./report-extensions.ts
- uses: actions/upload-artifact@v3
if: always()
with:
name: report
path: |
/tmp/stat.json
/tmp/meta.json
/tmp/result.md
- uses: actions/upload-artifact@v3
if: always()
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"semver": "^7.1.3"
},
"devDependencies": {
"@types/human-number": "^1.0.0",
"@types/unzipper": "^0.10.5"
}
}
61 changes: 17 additions & 44 deletions report-extensions.js → report-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,33 @@
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/

// @ts-check
const fs = require('fs');
const Octokit = require('octokit').Octokit;
const { formatter } = require('./lib/reportStat');
const humanNumber = require('human-number');
const { registryHost } = require('./lib/constants');

const token = process.env.GITHUB_TOKEN;
if (!token) {
console.error("GITHUB_TOKEN env var is not set, the week-over-week statistic won't be included");
}
const octokit = new Octokit({ auth: token });

/**
* @param {{ [id: string]: (Partial<import('./types').MSExtensionStat | import('./types').ExtensionStat>) }} s
*/
function sortedKeys(s) {
import fs from 'fs';
import { formatter } from './lib/reportStat';
import humanNumber from 'human-number';
import { registryHost } from './lib/constants';
import type { ExtensionStat, MSExtensionStat, PublishStat } from './types';

type InputExtensionStat = Partial<MSExtensionStat | ExtensionStat>;
function sortedKeys(s: { [id: string]: InputExtensionStat}) {
return Object.keys(s).sort((a, b) => {
if (typeof s[b].msInstalls === 'number' && typeof s[a].msInstalls === 'number') {
return s[b].msInstalls - s[a].msInstalls;
}
if (typeof s[b].msInstalls === 'number') {
return s[b].msInstalls;
}
return -1;
const msInstallsA = s[a].msInstalls ?? 0;
const msInstallsB = s[b].msInstalls ?? 0;

return msInstallsB - msInstallsA;
})
}

/**
* @param {any} item
* @param {string | any[]} array
* @returns {string} the position of the item in the array with a `.` appended onto it.
*/
function positionOf(item, array) {
function positionOf(item: any, array: string | any[]): string {
return `${array.indexOf(item) + 1}.`;
}

const generateMicrosoftLink = (/** @type {string} */ id) => `[${id}](https://marketplace.visualstudio.com/items?itemName=${id})`;
const generateOpenVsxLink = (/** @type {string} */ id) => `[${id}](https://${registryHost}/extension/${id.split(".")[0]}/${id.split(".")[1]})`;
const generateMicrosoftLink = (/** @type {string} */ id: string) => `[${id}](https://marketplace.visualstudio.com/items?itemName=${id})`;
const generateOpenVsxLink = (/** @type {string} */ id: string) => `[${id}](https://${registryHost}/extension/${id.split(".")[0]}/${id.split(".")[1]})`;

(async () => {
/** @type{import('./types').PublishStat}*/
const stat = JSON.parse(await fs.promises.readFile("/tmp/stat.json", { encoding: 'utf8' }));
const stat: PublishStat = JSON.parse(await fs.promises.readFile("/tmp/stat.json", { encoding: 'utf8' }));

/**
*
* @param {'upToDate' | 'unstable' | 'outdated' | 'notInOpen'} category
* @returns
*/
const getAggregatedInstalls = (category) => {
const getAggregatedInstalls = (category: 'upToDate' | 'unstable' | 'outdated' | 'notInOpen') => {
return Object.keys(stat[category]).map((st) => stat[category][st].msInstalls).reduce(
(previousValue, currentValue) => previousValue + currentValue,
0
Expand Down Expand Up @@ -296,9 +273,5 @@ const generateOpenVsxLink = (/** @type {string} */ id) => `[${id}](https://${reg
}

await fs.promises.writeFile("/tmp/result.md", content, { encoding: 'utf8' });
const metadata = {
weightedPercentage
};
await fs.promises.writeFile('/tmp/meta.json', JSON.stringify(metadata), { encoding: 'utf8' });
console.log('See result output for the detailed report.');
})();

0 comments on commit 3b13233

Please sign in to comment.