Skip to content

Commit

Permalink
feat!: change outdir to output
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Apr 25, 2024
1 parent 5d823b9 commit 9994ad3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <UID>
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

Expand Down
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
11 changes: 7 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ function today(): string {
}

async function run(): Promise<void> {
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();
Expand All @@ -25,13 +27,18 @@ async function run(): Promise<void> {

// 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');
}
Expand Down

0 comments on commit 9994ad3

Please sign in to comment.