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 - 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 .. - name: Install python dependencies run: | python -m pip install --upgrade pip pip3 install openai tqdm - name: Download language branch #Make sure we have last version run: | git config --global user.name 'Spanish Translator' git config --global user.email 'github-actions@github.com' git checkout "$BRANCH" git pull git checkout master - name: Run translation script on changed files run: | # Start a subshell with a timeout (5h) timeout 18000s bash << 'EOF' echo "Starting translations" #echo "Commit: $GITHUB_SHA" echo "Commit: 0afe4e4475ddd0e31b7b8957df1e0e9bb275b731" # Export the OpenAI API key as an environment variable export OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} # Run the translation script on each changed file git diff-tree --no-commit-id --name-only -r "0afe4e4475ddd0e31b7b8957df1e0e9bb275b731" | grep -v "SUMMARY.md" | while read -r file; do if echo "$file" | grep -qE '\.md$'; then echo "Translating $file" python scripts/translator.py --language "$LANGUAGE" --branch "$BRANCH" --api-key "$OPENAI_API_KEY" --file-path "$file" else echo "Skipping $file" fi done EOF - name: Commit and push changes run: | git checkout "$BRANCH" git add -A git commit -m "Translated $BRANCH files" || true git push --set-upstream origin "$BRANCH"