Add Vietnamese Translation of README #294
Workflow file for this run
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: Auto Format | |
| # Runs on every PR (including forks) with pull_request_target so it has write | |
| # access to push formatting fixes back to the PR branch. | |
| # | |
| # Uses FORMAT_BOT_PAT (not GITHUB_TOKEN) for the push so that GitHub fires a | |
| # real pull_request: synchronize event, causing CI to re-run on the new commit | |
| # with proper PR context. GITHUB_TOKEN pushes are suppressed by GitHub and do | |
| # not trigger downstream CI. | |
| # | |
| # Security: we never run npm install from the fork. Prettier is invoked via npx | |
| # (no fork code executed). The prettier config and .prettierignore are fetched | |
| # directly from master (trusted), overwriting any fork-modified versions. | |
| # | |
| # If the fork has "Allow edits from maintainers" enabled (GitHub default for new | |
| # PRs), the bot pushes the fix directly. If not, it posts a comment instead. | |
| on: | |
| pull_request_target: | |
| branches: [master] | |
| types: [opened, synchronize, reopened] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| # Cancel any in-progress format run for the same PR when a new commit arrives. | |
| concurrency: | |
| group: auto-format-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| format: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout PR branch | |
| uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.FORMAT_BOT_PAT }} | |
| # Use head SHA (not ref) to avoid TOCTOU races | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| repository: ${{ github.event.pull_request.head.repo.full_name }} | |
| - name: Override with trusted Prettier config from master | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Fetch config files from the base repo (master) to prevent a malicious | |
| # fork from injecting a custom prettier.config.js or .prettierignore. | |
| gh api "repos/${{ github.repository }}/contents/prettier.config.js?ref=master" \ | |
| --jq '.content' | base64 -d > prettier.config.js | |
| gh api "repos/${{ github.repository }}/contents/.prettierignore?ref=master" \ | |
| --jq '.content' | base64 -d > .prettierignore | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 'lts/*' | |
| - name: Format changed files with Prettier | |
| # Only format files changed in this PR — avoids touching unrelated files. | |
| # Run via npx — never executes the fork's npm install or postinstall scripts. | |
| # Pinned to major version 3, matching our package.json (^3.8.1). | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| CHANGED=$(gh pr view ${{ github.event.pull_request.number }} \ | |
| --repo ${{ github.repository }} \ | |
| --json files --jq '[.files[].path] | join(" ")') | |
| if [ -z "$CHANGED" ]; then | |
| echo "No changed files found." | |
| exit 0 | |
| fi | |
| echo "Formatting: $CHANGED" | |
| # shellcheck disable=SC2086 | |
| npx --yes prettier@3 --write --ignore-unknown --ignore-path .prettierignore $CHANGED | |
| - name: Commit and push formatting fixes | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| if git diff --quiet; then | |
| echo "All files already formatted — nothing to do." | |
| exit 0 | |
| fi | |
| # No [skip ci] — CI must re-run after this commit to verify formatting passes. | |
| git commit -am "style: auto-format with Prettier" | |
| # Push to the PR head branch explicitly — needed because we checked out | |
| # a specific SHA (detached HEAD), so git push needs a destination. | |
| if git push origin HEAD:${{ github.event.pull_request.head.ref }}; then | |
| echo "Formatting fixes pushed to PR branch." | |
| else | |
| echo "Push failed — fork may not allow edits from maintainers. Posting comment." | |
| printf '%s\n' \ | |
| "Hi! 👋 Some files in this PR need formatting with [Prettier](https://prettier.io)." \ | |
| "" \ | |
| "To fix this, run the following in the project root and push the result:" \ | |
| "" \ | |
| '```bash' \ | |
| "npm install" \ | |
| "npm run format" \ | |
| '```' \ | |
| "" \ | |
| "Alternatively, install the [Prettier VS Code extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and enable **Format on Save** — it will handle this automatically." \ | |
| > /tmp/format-comment.md | |
| gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body-file /tmp/format-comment.md | |
| fi |