-
Notifications
You must be signed in to change notification settings - Fork 5
123 lines (108 loc) · 4.44 KB
/
update-pricing.yml
File metadata and controls
123 lines (108 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Update Provider Pricing
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
on:
schedule:
- cron: "0 2 * * *"
workflow_dispatch:
concurrency:
group: provider-data-update-${{ github.ref }}
cancel-in-progress: false
jobs:
update-pricing:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
cache: npm
- name: Install dependencies
run: npm ci
- name: Install Playwright Chromium
run: npx playwright install --with-deps chromium
- name: Fetch latest provider pricing
run: npm run pricing:fetch
- name: Detect provider pricing parsing failures
id: pricing_failures
run: |
node -e "const fs=require('node:fs');const data=JSON.parse(fs.readFileSync('assets/provider-pricing.json','utf8'));const failures=(Array.isArray(data.failures)?data.failures:[]).map((item)=>String(item||'').replace(/\r?\n/g,' ').trim()).filter(Boolean);const out=process.env.GITHUB_OUTPUT;fs.appendFileSync(out,'has_failure='+(failures.length>0)+'\n');if(failures.length>0){fs.appendFileSync(out,'failures_json<<__EOF__\n'+JSON.stringify(failures)+'\n__EOF__\n');}"
- name: Create issue for provider pricing parsing failures
if: steps.pricing_failures.outputs.has_failure == 'true'
uses: actions/github-script@v8
env:
FAILURES_JSON: ${{ steps.pricing_failures.outputs.failures_json }}
with:
script: |
const marker = '<!-- auto-provider-pricing-parse-failures -->';
const title = '抓取失败:中文套餐解析失败';
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const failures = JSON.parse(process.env.FAILURES_JSON || '[]')
.map((item) => String(item || '').replace(/`/g, "'"))
.filter(Boolean);
const failureLines = failures.length > 0
? failures.map((item) => `- \`${item}\``)
: ['- `unknown error`'];
const body = [
marker,
'中文套餐页面解析出现失败。',
'',
`- 失败数量:${failures.length}`,
...failureLines,
`- 工作流运行:${runUrl}`,
`- 时间(UTC):${new Date().toISOString()}`,
'',
'@jqknono 请检查页面结构并更新解析逻辑。',
].join('\n');
const issues = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100,
});
const existing = issues.find((issue) => {
if (issue.pull_request) {
return false;
}
if (issue.title === title && typeof issue.body === 'string' && issue.body.includes(marker)) {
return true;
}
return false;
});
if (existing) {
core.info(`Provider pricing parsing issue already open: #${existing.number}`);
return;
}
const created = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
});
core.info(`Created issue #${created.data.number}`);
- name: Commit pricing changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add assets/provider-pricing.json
if git diff --cached --quiet; then
echo "No pricing changes detected."
exit 0
fi
git commit -m "chore: update provider pricing"
BRANCH_NAME="${GITHUB_REF_NAME:-main}"
for attempt in 1 2 3; do
git fetch origin "${BRANCH_NAME}"
git rebase "origin/${BRANCH_NAME}"
if git push origin "HEAD:${BRANCH_NAME}"; then
exit 0
fi
echo "Push failed, retrying after refreshing ${BRANCH_NAME} (${attempt}/3)."
done
echo "Failed to push pricing changes after 3 attempts."
exit 1