Skip to content

Commit

Permalink
Merge pull request #1327 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Mar 24, 2024
2 parents a62455c + b774c60 commit 407ddaa
Show file tree
Hide file tree
Showing 40 changed files with 1,155 additions and 762 deletions.
2 changes: 0 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ updates:
ignore:
- dependency-name: jsrsasign
versions: ['>=11.0.0'] # no longer includes KJUR.crypto.Cipher for RSA
- dependency-name: unified
versions: ['>=10.0.0']

- package-ecosystem: 'github-actions'
directory: '/'
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/build-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ jobs:
- name: Install dependencies (yarn)
run: pnpm i
- name: Build assets
run: npm run build
run: pnpm build
- name: Build full routes test result
run: pnpm vitest:fullroutes
- name: Build docs
run: pnpm build:docs
- name: Commit files
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
Expand All @@ -57,6 +61,8 @@ jobs:
run: |
cp -r ./assets/build/docs/en/* ./rsshub-docs/src/routes
cp -r ./assets/build/docs/zh/* ./rsshub-docs/src/zh/routes
cp ./lib/types.ts ./rsshub-docs/.vitepress/theme/types.ts
cp ./scripts/workflow/data.ts ./rsshub-docs/.vitepress/config/data.ts
- name: Commit docs
run: |
cd rsshub-docs
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/comment-on-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ jobs:
- uses: pnpm/action-setup@v3
with:
version: 8
- uses: actions/setup-node@v4 # just need its cache
- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'pnpm'
- name: Install dependencies (pnpm) # needed since we need to parse markdown, so we also use got instead
- name: Install dependencies (pnpm) # import remark-parse and unified
run: pnpm i
- name: Generate feedback
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-issue/call-maintainer.js`)
return script({ github, context, core })
const { default: callMaintainer } = await import('${{ github.workspace }}/scripts/workflow/test-issue/call-maintainer.mjs')
await callMaintainer({ github, context, core })
21 changes: 10 additions & 11 deletions .github/workflows/docker-test-cont.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: PR - route test

on:
workflow_run:
workflows: [ PR - Docker build test ] # open, reopen, synchronized, edited included
types: [ completed ]
workflows: [PR - Docker build test] # open, reopen, synchronized, edited included
types: [completed]

jobs:
testRoute:
name: Route test
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }} # skip if unsuccessful
if: ${{ github.event.workflow_run.conclusion == 'success' }} # skip if unsuccessful
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -44,8 +44,8 @@ jobs:
const body = PR.body
const number = PR.number
const sender = PR.user.login
const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/identify.js`)
return script({ github, context, core }, body, number, sender)
const { default: identify } = await import('${{ github.workspace }}/scripts/workflow/test-route/identify.mjs')
return identify({ github, context, core }, body, number, sender)
- name: Fetch Docker image
if: (env.TEST_CONTINUE)
Expand All @@ -72,13 +72,13 @@ jobs:
with:
version: 8

- uses: actions/setup-node@v4 # just need its cache
- uses: actions/setup-node@v4
if: (env.TEST_CONTINUE)
with:
node-version: lts/*
cache: 'pnpm'

- name: Install dependencies (pnpm) # `got` needed since `github.request` disallows HTTP requests
- name: Install dependencies (pnpm) # require js-beautify
if: (env.TEST_CONTINUE)
run: pnpm i

Expand All @@ -99,9 +99,8 @@ jobs:
const routes = JSON.parse(process.env.TEST_ROUTES)
const number = PR.number
core.info(`${link}, ${routes}, ${number}`)
const got = require("got")
const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/test.js`)
return script({ github, context, core, got }, link, routes, number)
const { default: test } = await import('${{ github.workspace }}/scripts/workflow/test-route/test.mjs')
await test({ github, context, core }, link, routes, number)
- name: Pull Request Labeler
if: ${{ failure() }}
Expand All @@ -114,4 +113,4 @@ jobs:

- name: Print Docker container logs
if: (env.TEST_CONTINUE)
run: docker logs rsshub # logs/combined.log? Not so readable...
run: docker logs rsshub # logs/combined.log? Not so readable...
9 changes: 4 additions & 5 deletions .github/workflows/issue-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ jobs:
const body = event.comment.body
const number = event.issue.number
const sender = event.comment.user.login
const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/identify.js`)
return script({ github, context, core }, body, number, sender)
const { default: identify } = await import('${{ github.workspace }}/scripts/workflow/test-route/identify.mjs')
return identify({ github, context, core }, body, number, sender)
- name: Build RSSHub
if: env.TEST_CONTINUE
Expand Down Expand Up @@ -107,9 +107,8 @@ jobs:
const routes = JSON.parse(process.env.TEST_ROUTES)
const number = event.issue.number
core.info(`${link}, ${routes}, ${number}`)
const got = require("got")
const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/workflow/test-route/test.js`)
return script({ github, context, core, got }, link, routes, number)
const { default: test } = await import('${{ github.workspace }}/scripts/workflow/test-route/test.mjs')
await test({ github, context, core }, link, routes, number)
- name: Print logs
if: (env.TEST_CONTINUE)
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches-ignore:
- 'dependabot/**'
paths:
- 'test/**'
- 'lib/**'
- 'package.json'
- 'pnpm-lock.yaml'
Expand Down Expand Up @@ -43,6 +42,8 @@ jobs:
run: pnpm i
- name: Run postinstall script for dependencies
run: pnpm rb
- name: Build routes
run: pnpm build
- name: Test all and generate coverage
run: pnpm run vitest:coverage
env:
Expand Down Expand Up @@ -84,6 +85,8 @@ jobs:
run: pnpm i
- name: Run postinstall script for dependencies
run: pnpm rb
- name: Build routes
run: pnpm build
- name: Install Chromium
if: ${{ matrix.chromium.dependency != '' }}
# 'chromium-browser' from Ubuntu APT repo is a dummy package. Its version (85.0.4183.83) means
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ FROM node:21-bookworm-slim AS chromium-downloader
# Yeah, downloading Chromium never needs those dependencies below.

WORKDIR /app
COPY ./.puppeteerrc.js /app/
COPY ./.puppeteerrc.cjs /app/
COPY --from=dep-version-parser /ver/.puppeteer_version /app/.puppeteer_version

ARG TARGETPLATFORM
Expand Down
15 changes: 4 additions & 11 deletions lib/middleware/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { describe, expect, it, vi, afterEach, afterAll, beforeAll } from 'vitest';
import { describe, expect, it, vi, afterEach } from 'vitest';
import Parser from 'rss-parser';
import wait from '@/utils/wait';

const parser = new Parser();
process.env.CACHE_EXPIRE = '1';
process.env.CACHE_CONTENT_EXPIRE = '3';

beforeAll(() => {
process.env.CACHE_EXPIRE = '1';
process.env.CACHE_CONTENT_EXPIRE = '3';
});
const parser = new Parser();

afterEach(() => {
delete process.env.CACHE_TYPE;
vi.resetModules();
});

afterAll(() => {
delete process.env.CACHE_EXPIRE;
});

describe('cache', () => {
it('memory', async () => {
process.env.CACHE_TYPE = 'memory';
Expand Down
59 changes: 2 additions & 57 deletions lib/registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,8 @@
import { describe, expect, it, afterAll } from 'vitest';
process.env.SOCKET = 'socket';

import { describe, expect, it } from 'vitest';
import app from '@/app';
import Parser from 'rss-parser';
const parser = new Parser();
import { config } from '@/config';

afterAll(() => {
delete process.env.SOCKET;
});

async function checkRSS(response) {
const checkDate = (date) => {
expect(date).toEqual(expect.any(String));
expect(Date.parse(date)).toEqual(expect.any(Number));
expect(Date.now() - +new Date(date)).toBeGreaterThan(-1000 * 60 * 60 * 24 * 5);
expect(Date.now() - +new Date(date)).toBeLessThan(1000 * 60 * 60 * 24 * 30 * 12 * 10);
};

const parsed = await parser.parseString(await response.text());

expect(parsed).toEqual(expect.any(Object));
expect(parsed.title).toEqual(expect.any(String));
expect(parsed.title).not.toBe('RSSHub');
expect(parsed.description).toEqual(expect.any(String));
expect(parsed.link).toEqual(expect.any(String));
expect(parsed.lastBuildDate).toEqual(expect.any(String));
expect(parsed.ttl).toEqual(Math.trunc(config.cache.routeExpire / 60) + '');
expect(parsed.items).toEqual(expect.any(Array));
checkDate(parsed.lastBuildDate);

// check items
const guids: (string | undefined)[] = [];
for (const item of parsed.items) {
expect(item).toEqual(expect.any(Object));
expect(item.title).toEqual(expect.any(String));
expect(item.link).toEqual(expect.any(String));
expect(item.content).toEqual(expect.any(String));
expect(item.guid).toEqual(expect.any(String));
if (item.pubDate) {
expect(item.pubDate).toEqual(expect.any(String));
checkDate(item.pubDate);
}

// guid must be unique
expect(guids).not.toContain(item.guid);
guids.push(item.guid);
}
}

describe('router', () => {
describe('registry', () => {
// root
it(`/`, async () => {
const response = await app.request('/');
Expand All @@ -58,14 +11,6 @@ describe('router', () => {
expect(response.headers.get('cache-control')).toBe('no-cache');
});

// route
it(`/test/1`, async () => {
const response = await app.request('/test/1');
expect(response.status).toBe(200);

await checkRSS(response);
});

// robots.txt
it('/robots.txt', async () => {
config.disallowRobot = false;
Expand Down
15 changes: 2 additions & 13 deletions lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { serveStatic } from '@hono/node-server/serve-static';

import index from '@/routes/index';
import robotstxt from '@/routes/robots.txt';
import { namespace as testNamespace } from './routes/test/namespace';
import { route as testRoute } from '@/routes/test/index';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand All @@ -27,18 +25,9 @@ let namespaces: Record<

switch (process.env.NODE_ENV) {
case 'test':
modules = {
'/test/namespace.ts': {
namespace: testNamespace,
},
'/test/index.ts': {
route: testRoute,
},
};
break;
case 'production':
// eslint-disable-next-line n/no-unpublished-require
namespaces = require('../assets/build/routes.json');
// @ts-expect-error
namespaces = await import('../assets/build/routes.json');
break;
default:
modules = directoryImport({
Expand Down
78 changes: 78 additions & 0 deletions lib/routes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { describe, expect, it } from 'vitest';
import app from '@/app';
import Parser from 'rss-parser';
const parser = new Parser();
import { config } from '@/config';

process.env.ALLOW_USER_SUPPLY_UNSAFE_DOMAIN = 'true';

const routes = {
'/test/:id': '/test/1',
};
if (process.env.FULL_ROUTES_TEST) {
const { namespaces } = await import('@/registry');
for (const namespace in namespaces) {
for (const route in namespaces[namespace].routes) {
const requireConfig = namespaces[namespace].routes[route].features?.requireConfig;
let configs;
if (typeof requireConfig !== 'boolean') {
configs = requireConfig
?.filter((config) => !config.optional)
.map((config) => config.name)
.filter((name) => name !== 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN');
}
if (namespaces[namespace].routes[route].example && !configs?.length) {
routes[`/${namespace}${route}`] = namespaces[namespace].routes[route].example;
}
}
}
}

async function checkRSS(response) {
const checkDate = (date) => {
expect(date).toEqual(expect.any(String));
expect(Date.parse(date)).toEqual(expect.any(Number));
expect(Date.now() - +new Date(date)).toBeGreaterThan(-1000 * 60 * 60 * 24 * 5);
expect(Date.now() - +new Date(date)).toBeLessThan(1000 * 60 * 60 * 24 * 30 * 12 * 10);
};

const parsed = await parser.parseString(await response.text());

expect(parsed).toEqual(expect.any(Object));
expect(parsed.title).toEqual(expect.any(String));
expect(parsed.title).not.toBe('RSSHub');
expect(parsed.description).toEqual(expect.any(String));
expect(parsed.link).toEqual(expect.any(String));
expect(parsed.lastBuildDate).toEqual(expect.any(String));
expect(parsed.ttl).toEqual(Math.trunc(config.cache.routeExpire / 60) + '');
expect(parsed.items).toEqual(expect.any(Array));
checkDate(parsed.lastBuildDate);

// check items
const guids: (string | undefined)[] = [];
for (const item of parsed.items) {
expect(item).toEqual(expect.any(Object));
expect(item.title).toEqual(expect.any(String));
expect(item.link).toEqual(expect.any(String));
expect(item.content).toEqual(expect.any(String));
expect(item.guid).toEqual(expect.any(String));
if (item.pubDate) {
expect(item.pubDate).toEqual(expect.any(String));
checkDate(item.pubDate);
}

// guid must be unique
expect(guids).not.toContain(item.guid);
guids.push(item.guid);
}
}

describe('routes', () => {
for (const route in routes) {
it.concurrent(route, async () => {
const response = await app.request(routes[route]);
expect(response.status).toBe(200);
await checkRSS(response);
});
}
});
6 changes: 3 additions & 3 deletions lib/routes/2023game/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export const route: Route = {
| ps4 | sgame | 3ds | psv | jiaocheng | ps3yx | zhuji.md | zhangji.psp | pcgame | zhangji | zhuji | ps4.psjc | ps41.ps4pkg | nsaita.cundang | nsaita.pojie | nsaita.buding | nsaita.zhutie | nsaita.zhuti |`,
};

async function handler(ctx?: Context): Promise<Data> {
const category = (ctx!.req.param('category') ?? 'sgame').replaceAll('.', '/');
const tab = ctx?.req.param('tab') ?? 'all';
async function handler(ctx: Context): Promise<Data> {
const category = (ctx.req.param('category') ?? 'sgame').replaceAll('.', '/');
const tab = ctx.req.param('tab') ?? 'all';

const currentUrl = `https://www.2023game.com/${category}/`;

Expand Down
Loading

0 comments on commit 407ddaa

Please sign in to comment.