Update packages readme #3322
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update packages readme | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: 0 * * * * | |
| permissions: write-all | |
| env: | |
| LANGUAGES: 'ko es de zh fr pt ja' # Supported languages separated by space (spaces are important) | |
| jobs: | |
| update-packages-readme: | |
| permissions: | |
| pull-requests: write | |
| contents: write | |
| runs-on: ubuntu-latest | |
| outputs: | |
| pr_number: ${{ steps.update-readme.outputs.pr_number }} | |
| modified_readme_files: ${{ steps.update-readme.outputs.modified_readme_files }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@v3 | |
| with: | |
| node-version: 24 | |
| - name: Update packages readme | |
| id: update-readme | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| npm run update-packages-readme | |
| MODIFIED_README_FILES=$(git diff --name-only | grep -E 'src/content/local-docs/libs/.*/README\.md$' || echo "") | |
| echo "modified_readme_files=$(echo "$MODIFIED_README_FILES" | tr '\n' ',' | sed 's/,$//')" >> $GITHUB_OUTPUT | |
| if [ -z "$MODIFIED_README_FILES" ]; then | |
| echo "No README files changed — skipping commit and PR creation." | |
| exit 0 | |
| fi | |
| git config user.email "" | |
| git config user.name "Update packages readme action" | |
| git checkout -b update-packages-readme | |
| git add src/content/local-docs/libs/*/README.md | |
| export COMMIT_MESSAGE="docs: update packages readme" | |
| git commit -m "$COMMIT_MESSAGE" || true | |
| git push --set-upstream origin update-packages-readme --force | |
| gh pr create --title "$COMMIT_MESSAGE" --body "" -a "dgaponov" -a "imsitnikov" -a "vvtimofeev" 2>/dev/null || true | |
| PR_NUMBER=$(gh pr view --json number -q ".number") | |
| echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT | |
| prepare-inputs: | |
| needs: update-packages-readme | |
| runs-on: ubuntu-latest | |
| if: ${{ needs.update-packages-readme.outputs.pr_number != '' && needs.update-packages-readme.outputs.pr_number != null }} | |
| outputs: | |
| modified_library_readmes: ${{ steps.get-modified-files.outputs.modified_library_readmes }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: refs/pull/${{ needs.update-packages-readme.outputs.pr_number }}/head | |
| fetch-depth: 2 | |
| - name: Get modified files | |
| id: get-modified-files | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| MODIFIED_FILES=$(git diff --name-only HEAD^ HEAD | grep -E 'src/content/local-docs/libs/.*/README\.md$' || echo "") | |
| # Prepare output with library names for matrix strategy | |
| JSON_OUTPUT=$(echo "$MODIFIED_FILES" | awk 'NF' | jq -R -c -s ' | |
| split("\n") | | |
| map(select(length > 0)) | | |
| map(capture("src/content/local-docs/libs/(?<lib>[^/]+)/README\\.md").lib) | |
| ') | |
| echo "modified_library_readmes=$JSON_OUTPUT" >> $GITHUB_OUTPUT | |
| translations: | |
| needs: | |
| - update-packages-readme | |
| - prepare-inputs | |
| runs-on: ubuntu-latest | |
| if: ${{ needs.update-packages-readme.outputs.pr_number != '' && needs.update-packages-readme.outputs.pr_number != null }} | |
| strategy: | |
| max-parallel: 1 | |
| matrix: | |
| library: ${{ fromJson(needs.prepare-inputs.outputs.modified_library_readmes) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: refs/pull/${{ needs.update-packages-readme.outputs.pr_number }}/head | |
| fetch-depth: 2 | |
| - name: Prepare inputs for ${{ matrix.library }} | |
| id: prepare-inputs | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| LIBRARY: ${{ matrix.library }} | |
| run: | | |
| LIBRARY_README="src/content/local-docs/libs/${LIBRARY}/README.md" | |
| echo "Processing library: $LIBRARY" | |
| echo "README file: $LIBRARY_README" | |
| OUTPUT_FILES="" | |
| for LANGUAGE in ${{ env.LANGUAGES }}; do | |
| OUTPUT_FILES="$OUTPUT_FILES src/content/local-docs/libs/${LIBRARY}/README-${LANGUAGE}.md" | |
| done | |
| echo "Output files: $OUTPUT_FILES" | |
| echo "input_files=$LIBRARY_README" >> $GITHUB_OUTPUT | |
| echo "output_files=$OUTPUT_FILES" >> $GITHUB_OUTPUT | |
| - name: Run translations | |
| uses: dgaponov/gpt-translate@master | |
| with: | |
| provider: 'openrouter' | |
| apikey: ${{ secrets.OPENROUTER_API_KEY }} | |
| model: 'google/gemini-2.5-flash-lite' | |
| inputFiles: ${{ steps.prepare-inputs.outputs.input_files }} | |
| outputFiles: ${{ steps.prepare-inputs.outputs.output_files }} | |
| pullRequestNumber: ${{ needs.update-packages-readme.outputs.pr_number }} | |
| languages: ${{ env.LANGUAGES }} | |
| commitMessage: 'translations: for package ${{ matrix.library }}' | |
| prompt: | | |
| Please translate the README source file to {targetLanguage}. \ | |
| Make the translation sound as natural as possible. \ | |
| Do not translate the first line in the source file if it looks like the name of the library. \ | |
| For example, don't translate @gravity/uikit or Axios Wrapper - they need to be left in place. \ | |
| Don't add html snippet with language options to the output. \ | |
| Don't convert markdown code blocks to html! |