-
Notifications
You must be signed in to change notification settings - Fork 8
ci: add scheduled workflow to sync QQ group info from index.json #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| name: Sync QQ Groups | ||
|
|
||
| on: | ||
| repository_dispatch: | ||
| types: [sync-qq-groups] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| sync: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| with: | ||
| token: ${{ secrets.PAT_TOKEN }} | ||
| show-progress: false | ||
|
|
||
| - name: Fetch index.json and update README | ||
| run: | | ||
| DATA=$(curl -sf https://end.maafw.com/index.json) || exit 0 | ||
|
|
||
| USER_GROUP=$(echo "$DATA" | jq -r '.qq_groups.user.number // empty') | ||
| USER_LINK=$(echo "$DATA" | jq -r '.qq_groups.user.link // empty') | ||
| DEV_GROUP=$(echo "$DATA" | jq -r '.qq_groups.dev.number // empty') | ||
| DEV_LINK=$(echo "$DATA" | jq -r '.qq_groups.dev.link // empty') | ||
|
|
||
| if [ -z "$USER_GROUP" ] || [ -z "$USER_LINK" ] || [ -z "$DEV_GROUP" ] || [ -z "$DEV_LINK" ]; then | ||
| echo "Missing fields in index.json, skipping" | ||
| exit 0 | ||
| fi | ||
|
|
||
| sed -i "s|\[用户 QQ 群\](https://qm.qq.com/q/[^)]*): [0-9]*|[用户 QQ 群]($USER_LINK): $USER_GROUP|" README.md | ||
| sed -i "s|\[开发 QQ 群\](https://qm.qq.com/q/[^)]*): [0-9]*|[开发 QQ 群]($DEV_LINK): $DEV_GROUP|" README.md | ||
|
|
||
| - name: Check for changes | ||
| id: diff | ||
| run: | | ||
| git diff --quiet && echo "changed=false" >> "$GITHUB_OUTPUT" || echo "changed=true" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Commit and push | ||
| if: steps.diff.outputs.changed == 'true' | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git add README.md | ||
| git commit -m "chore: sync QQ group info in README" | ||
| git push | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { useCallback, useEffect, useState } from "react"; | ||
| import { QQ_GROUPS } from "../constants"; | ||
|
|
||
| interface QQGroup { | ||
| number: string; | ||
| link: string; | ||
| } | ||
|
|
||
| interface QQGroups { | ||
| user: QQGroup; | ||
| dev: QQGroup; | ||
| } | ||
|
|
||
| const CACHE_KEY = "maaend-qq-groups"; | ||
| const CACHE_TTL = 1000 * 60 * 60; // 1 hour | ||
|
|
||
| const fallback: QQGroups = { | ||
| user: { number: QQ_GROUPS.USER_GROUP, link: QQ_GROUPS.USER_GROUP_LINK }, | ||
| dev: { number: QQ_GROUPS.DEV_GROUP, link: QQ_GROUPS.DEV_GROUP_LINK }, | ||
| }; | ||
|
|
||
| function readCache(): QQGroups | null { | ||
| try { | ||
| const raw = localStorage.getItem(CACHE_KEY); | ||
| if (!raw) return null; | ||
| const { data, ts } = JSON.parse(raw); | ||
| if (Date.now() - ts > CACHE_TTL) return null; | ||
| return data; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| function writeCache(data: QQGroups) { | ||
| try { | ||
| localStorage.setItem(CACHE_KEY, JSON.stringify({ data, ts: Date.now() })); | ||
| } catch { | ||
| // storage full or unavailable | ||
| } | ||
| } | ||
|
|
||
| export function useQQGroups() { | ||
| const [groups, setGroups] = useState<QQGroups>(fallback); | ||
|
|
||
| const fetchGroups = useCallback(async () => { | ||
| const cached = readCache(); | ||
| if (cached) { | ||
| setGroups(cached); | ||
| return; | ||
| } | ||
| try { | ||
| const res = await fetch("https://end.maafw.com/index.json"); | ||
| if (!res.ok) return; | ||
| const data = await res.json(); | ||
| const qq = data.qq_groups; | ||
| if ( | ||
| qq?.user?.number && | ||
| qq?.user?.link && | ||
| qq?.dev?.number && | ||
| qq?.dev?.link | ||
| ) { | ||
| const result: QQGroups = { user: qq.user, dev: qq.dev }; | ||
| setGroups(result); | ||
| writeCache(result); | ||
| } | ||
| } catch { | ||
| // fallback to constants | ||
| } | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| (async () => { | ||
| await fetchGroups(); | ||
| })(); | ||
| }, [fetchGroups]); | ||
|
|
||
| return groups; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): curl 没有设置超时时间,在出现网络问题时任务可能会一直挂起。
如果接口长时间无响应或非常缓慢,这一步可能会被无限阻塞。请显式添加超时参数(例如
--connect-timeout和/或--max-time,如curl -sf --connect-timeout 5 --max-time 15 ...),以确保该步骤在有限时间内失败或退出。Original comment in English
suggestion (bug_risk): curl has no timeout, so the job might hang on network issues.
A hanging or very slow endpoint could block this job indefinitely. Please add an explicit timeout (e.g.
--connect-timeoutand/or--max-time, such ascurl -sf --connect-timeout 5 --max-time 15 ...) so the step fails or exits within a bounded time.