-
Notifications
You must be signed in to change notification settings - Fork 6
81 lines (67 loc) · 2.39 KB
/
auto_translate.yml
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
name: Auto Translate
# TODO:ブランチの命名規則をREADMEに
on:
push:
branches:
- 'feature/auto-translate-*'
paths:
- 'docs/app-router/**'
permissions:
contents: write
pull-requests: write
jobs:
auto-translate:
runs-on: ubuntu-latest
steps:
# feature/auto-translateへcheckout
- name: checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
# ブランチ名を定義
- name: Define branch name
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
# 変更ファイル取得
- name: Check and get changed files
run: |
changed_files=$(git diff --name-status HEAD~1 | awk '$1 == "A" || $1 == "M" {print $2}')
echo "CHANGED_FILES=${changed_files}" >> $GITHUB_ENV
# Nodeの環境構築
- name: Use Node.js 20.9.0
uses: actions/setup-node@v4
with:
node-version: '20.9.0'
- name: npm install
run: |
npm ci
npm install openai
# 翻訳処理
- name: Translate with ChatGPT
env:
API_KEY: ${{ secrets.API_KEY }}
CHANGED_FILES: ${{ env.CHANGED_FILES }}
run: node auto_translate/translate/translate.js
# 翻訳対象パスファイルの削除
- name: Remove translate_files_path.txt
run: |
rm auto_translate/translate_files_path/translate_files_path.txt
# 変更内容のadd、commit、push処理
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Add changes to Git
run: |
git add .
- name: Commit changes
run: |
timestamp=$(date +'%Y-%m-%d %H:%M:%S')
git commit -m "Automated translation commit: Translated Next.js docs to Japanese under docs/app-router. Timestamp: $timestamp"
- name: Push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push origin HEAD:${{ github.ref }}
# PRの作成処理
- name: Create PR
run: bash auto_translate/script/create_pull_request.sh "${{ secrets.GITHUB_TOKEN }}" "${{ env.BRANCH_NAME }}" "${{ env.CHANGED_FILES }}"