hacktricks/.github/workflows/translate_es.yml

81 lines
2.3 KiB
YAML
Raw Normal View History

2023-06-01 11:01:49 +00:00
name: Translator to ES (Spanish)
on:
push:
branches:
- master
paths-ignore:
- 'scripts/**'
- '.gitignore'
- '.github/**'
workflow_dispatch:
jobs:
run-translation:
runs-on: ubuntu-latest
environment: prod
env:
LANGUAGE: Spanish
BRANCH: es
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0 #Needed to download everything to be able to access the master & language branches
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
2023-06-01 12:16:58 +00:00
- name: Install dependencies
run: |
python -m pip install --upgrade pip
2023-06-19 19:15:28 +00:00
pip3 install openai tqdm tiktoken
2023-06-06 22:07:32 +00:00
- name: Update & install wget & translator.py
run: |
sudo apt-get update
sudo apt-get install wget -y
mkdir scripts
cd scripts
wget https://raw.githubusercontent.com/carlospolop/hacktricks-cloud/master/scripts/translator.py
cd ..
2023-06-01 11:01:49 +00:00
- name: Download language branch #Make sure we have last version
run: |
2023-06-01 12:16:58 +00:00
git config --global user.name 'Translator'
2023-06-01 11:01:49 +00:00
git config --global user.email 'github-actions@github.com'
git checkout "$BRANCH"
git pull
git checkout master
- name: Run translation script on changed files
2023-06-06 11:42:52 +00:00
run: |
2023-06-01 12:26:17 +00:00
echo "Starting translations"
2023-06-06 11:42:52 +00:00
echo "Commit: $GITHUB_SHA"
2023-06-01 11:01:49 +00:00
2023-06-01 12:26:17 +00:00
# Export the OpenAI API key as an environment variable
export OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}
2023-06-01 11:01:49 +00:00
2023-06-01 12:26:17 +00:00
# Run the translation script on each changed file
2023-06-08 00:03:46 +00:00
git diff --name-only HEAD~1 | grep -v "SUMMARY.md" | while read -r file; do
2023-06-01 12:26:17 +00:00
if echo "$file" | grep -qE '\.md$'; then
2023-06-01 12:34:11 +00:00
echo -n "$file , " >> /tmp/file_paths.txt
2023-06-01 12:26:17 +00:00
else
echo "Skipping $file"
fi
done
2023-06-01 12:16:58 +00:00
2023-06-01 12:38:28 +00:00
echo "Translating $(cat /tmp/file_paths.txt)"
2023-06-08 00:05:00 +00:00
python scripts/translator.py --language "$LANGUAGE" --branch "$BRANCH" --api-key "$OPENAI_API_KEY" -f "$(cat /tmp/file_paths.txt)" -t 3
2023-06-01 11:01:49 +00:00
- name: Commit and push changes
run: |
git checkout "$BRANCH"
git add -A
git commit -m "Translated $BRANCH files" || true
2023-06-01 11:28:45 +00:00
git push --set-upstream origin "$BRANCH"