-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
88 lines (81 loc) · 2.46 KB
/
action.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
82
83
84
85
86
87
88
name: 'Translate and Sync to Repo'
description: 'Translate .md files from one repository and sync them to another repository'
author: 'Summer Tang'
inputs:
github-token:
description: 'GitHub token'
required: true
target-repo:
description: 'Target repository to sync translated files'
required: true
runs:
using: 'composite'
steps:
- name: Checkout Repository A
uses: actions/checkout@v3
with:
token: ${{ inputs.github-token }}
fetch-depth: 2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install Dependencies
run: npm install @vitalets/google-translate-api
shell: bash
- name: Detect Changed Files
id: changed-files
run: |
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
echo "Changed files: $CHANGED_FILES"
echo "::set-output name=files::$CHANGED_FILES"
shell: bash
- name: Translate Files
id: translate
run: |
FILES="${{ steps.changed-files.outputs.files }}"
TRANSLATED_DIR=translated_files
mkdir -p $TRANSLATED_DIR
echo "Files to translate: $FILES"
for FILE in $FILES; do
if [[ "$FILE" == *.md ]]; then
if [ -f "$FILE" ]; then
TRANSLATED_FILE="$TRANSLATED_DIR/$FILE"
mkdir -p "$(dirname "$TRANSLATED_FILE")"
node translate.js "$FILE" "$TRANSLATED_FILE"
else
echo "File not found: $FILE"
fi
else
echo "Skipping non-markdown file: $FILE"
fi
done
shell: bash
- name: List Translated Files
run: |
echo "Contents of translated_files directory:"
ls -laR translated_files
shell: bash
- name: Checkout Repository B
uses: actions/checkout@v2
with:
repository: ${{ inputs.target-repo }}
path: repo-en
token: ${{ inputs.github-token }}
- name: Copy Translated Files to Repo B
run: |
cp -r translated_files/* repo-en/
cd repo-en
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
else
git commit -m "Add translated files from source repo"
git push origin main
fi
shell: bash
branding:
icon: 'globe'
color: 'blue'