diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index 020a7be..3b8673c 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -52,7 +52,7 @@ jobs: id: diff # If index.js was different than expected, upload the expected version as an artifact - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 if: ${{ failure() && steps.diff.conclusion == 'failure' }} with: name: dist diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57e6ee7..691194e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,3 +46,9 @@ jobs: with: ruid: '477317922' roomid: '21672023' + output: './data/yyyy-MM-dd.csv' + + - uses: actions/upload-artifact@v4 + with: + name: data + path: data/ diff --git a/README.md b/README.md index a09392d..0ab3110 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,22 @@ Automatically fetch the captain list of your favourite bilibili VUP. Add the following config to your Github Actions. Fill roomid and ruid. ```yml -- uses: yjl9903/fetch-captain@v0 +- uses: yjl9903/fetch-captain@v1 with: ruid: roomid: <直播间 ID> - # outDir: './' + # output: './yyyy-MM-dd.csv' ``` Notice that you should push changes (e.g. `./2022-3-5.csv`) in your following actions steps manually. -Example repo: [Miki-Captain](https://github.com/yjl9903/Miki-Captain). +Example repo: [Miki-Captain](https://github.com/yjl9903/Miki-Captain), [Nagisa-Captain](https://github.com/yjl9903/Nagisa-Captain). + +> 👷 **Migration from v0 to v1** +> +> **Sending email is deprecated**: If you still want to use it, please combine this action with other stuffs. +> +> **CSV output path**: Change `outdir` to `output`, which means the output file pattern instead of output directory. It uses [date-fns/format](https://date-fns.org/v3.6.0/docs/format) to format date string under the hood. By default, it will dump csv file to `./yyyy-MM-dd.csv` (i.e. `./2024-04-25.csv`). ## License diff --git a/action.yml b/action.yml index 7ae16eb..ed98328 100644 --- a/action.yml +++ b/action.yml @@ -7,14 +7,14 @@ author: 'yjl9903' inputs: ruid: required: true - description: 'up 主 uid' + description: 'Up 主 uid' roomid: required: true description: '直播房间 id' - outDir: + output: required: false - description: '输出目录' - default: './' + description: '输出 CSV 文件路径' + default: './yyyy-MM-dd.csv' runs: using: 'node20' diff --git a/dist/index.js b/dist/index.js index d20e646..80c1f9a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -182,22 +182,25 @@ function today() { } function run() { return __awaiter(this, void 0, void 0, function* () { + const now = new Date(); const ruid = core.getInput('ruid'); const roomid = core.getInput('roomid'); - const outDir = core.getInput('outDir'); + const outputPattern = core.getInput('output'); const client = new client_1.Client(roomid, ruid); const list = yield client.get(); // Print users (0, output_1.printUsers)(list); // Dump fetched list to csv { - const csvname = path_1.default.join(outDir, `${today()}.csv`); + const csvname = (0, date_fns_1.format)(now, outputPattern); const content = (0, output_1.toCSV)(list); core.info(`---------------------------------------`); core.info(`Writing to ${csvname}`); + // Set output `csv` for further usage core.setOutput('csv', csvname); - if (!(0, fs_1.existsSync)(outDir)) { - (0, fs_1.mkdirSync)(outDir, { recursive: true }); + // Dump csv + if (!(0, fs_1.existsSync)(path_1.default.dirname(csvname))) { + (0, fs_1.mkdirSync)(path_1.default.dirname(csvname), { recursive: true }); } (0, fs_1.writeFileSync)(csvname, content, 'utf-8'); } diff --git a/src/main.ts b/src/main.ts index 4fd1157..b0f1930 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,9 +13,11 @@ function today(): string { } async function run(): Promise { + const now = new Date(); + const ruid = core.getInput('ruid'); const roomid = core.getInput('roomid'); - const outDir = core.getInput('outDir'); + const outputPattern = core.getInput('output'); const client = new Client(roomid, ruid); const list = await client.get(); @@ -25,13 +27,18 @@ async function run(): Promise { // Dump fetched list to csv { - const csvname = path.join(outDir, `${today()}.csv`); + const csvname = format(now, outputPattern); + const content = toCSV(list); core.info(`---------------------------------------`); core.info(`Writing to ${csvname}`); + + // Set output `csv` for further usage core.setOutput('csv', csvname); - if (!existsSync(outDir)) { - mkdirSync(outDir, { recursive: true }); + + // Dump csv + if (!existsSync(path.dirname(csvname))) { + mkdirSync(path.dirname(csvname), { recursive: true }); } writeFileSync(csvname, content, 'utf-8'); }