forked from duanyytop/agents-radar
-
Notifications
You must be signed in to change notification settings - Fork 3
118 lines (104 loc) · 4.03 KB
/
translate-digest.yml
File metadata and controls
118 lines (104 loc) · 4.03 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
name: Translate Digest (Vietnamese)
on:
schedule:
# 01:00 UTC = 09:00 CST — 1 hour after upstream daily digest completes
- cron: "0 1 * * *"
workflow_dispatch:
inputs:
date:
description: "Date to translate (YYYY-MM-DD). Leave empty for today."
required: false
permissions:
contents: write
jobs:
translate:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Sync from upstream (duanyytop/agents-radar)
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git remote add upstream https://github.com/duanyytop/agents-radar.git || true
git fetch upstream master
LOCAL=$(git rev-parse HEAD)
git merge upstream/master --no-edit --allow-unrelated-histories || true
AFTER=$(git rev-parse HEAD)
if [ "$LOCAL" != "$AFTER" ]; then
echo "Upstream merged — pushing..."
git pull --rebase origin master
git push
else
echo "Already up to date with upstream."
fi
- name: Determine target date
id: date
run: |
if [ -n "${{ github.event.inputs.date }}" ]; then
echo "target=${{ github.event.inputs.date }}" >> "$GITHUB_OUTPUT"
else
echo "target=$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
fi
- name: Check if source files exist
id: check
run: |
DIR="digests/${{ steps.date.outputs.target }}"
if [ -d "$DIR" ] && ls "$DIR"/ai-*.md 1>/dev/null 2>&1; then
echo "has_source=true" >> "$GITHUB_OUTPUT"
else
echo "has_source=false" >> "$GITHUB_OUTPUT"
echo "No source files found in $DIR — skipping translation."
fi
- name: Setup pnpm
if: steps.check.outputs.has_source == 'true'
uses: pnpm/action-setup@v4
- name: Setup Node.js
if: steps.check.outputs.has_source == 'true'
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- name: Install dependencies
if: steps.check.outputs.has_source == 'true'
run: pnpm install --frozen-lockfile
- name: Debug env vars
if: steps.check.outputs.has_source == 'true'
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}
OPENAI_MODEL: ${{ vars.OPENAI_MODEL }}
run: |
echo "OPENAI_API_KEY set: $([ -n "$OPENAI_API_KEY" ] && echo 'yes ('${#OPENAI_API_KEY}' chars)' || echo 'NO')"
echo "OPENAI_BASE_URL set: $([ -n "$OPENAI_BASE_URL" ] && echo 'yes' || echo 'NO')"
echo "OPENAI_BASE_URL value: $OPENAI_BASE_URL"
echo "OPENAI_MODEL: ${OPENAI_MODEL:-'(not set, default gpt-4o)'}"
- name: Translate to Vietnamese
if: steps.check.outputs.has_source == 'true'
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}
OPENAI_MODEL: ${{ vars.OPENAI_MODEL }}
run: npx tsx src/translate.ts ${{ steps.date.outputs.target }}
- name: Commit translated files
if: steps.check.outputs.has_source == 'true'
run: |
git add digests/
if git diff --cached --quiet; then
echo "No new translated files to commit"
else
DATE="${{ steps.date.outputs.target }}"
git commit -m "translate: ${DATE} Vietnamese digest"
git pull --rebase
git push
fi
- name: Send Telegram notification
if: steps.check.outputs.has_source == 'true'
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
PAGES_URL: ${{ vars.PAGES_URL }}
run: npx tsx src/notify-vi.ts ${{ steps.date.outputs.target }}