Skip to content

Commit

Permalink
Merge branch 'live-codes:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zyf722 authored Nov 3, 2024
2 parents d20c65d + 643a127 commit c82beec
Show file tree
Hide file tree
Showing 30 changed files with 1,533 additions and 1,311 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ jobs:
env:
NODE_OPTIONS: '--max_old_space_size=4096'
steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_ACTIONS_REPO_PAT }}
token: ${{ steps.generate-token.outputs.token }}

- name: Use Node.js
uses: actions/setup-node@v4
Expand All @@ -33,6 +40,6 @@ jobs:
- name: Deploy
run: |
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${{github.repository}}.git
npm run deploy -- -u "github-actions-bot <support+actions@github.com>"
npm run deploy -- -u "livecodes-ci[bot] <186997172+livecodes-ci[bot]@users.noreply.github.com>"
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_PAT }}
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
28 changes: 15 additions & 13 deletions .github/workflows/i18n-update-scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,24 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Linting and fixing
run: npm run fix
# - name: Linting and fixing
# run: npm run fix

- name: Commit changes
run: |
git add .
# - name: Commit changes
# run: |
# git add .

# Only commit if there are changes
git diff-index --quiet HEAD || git commit -m "i18n: update source texts"
# # Only commit if there are changes
# git diff-index --quiet HEAD || git commit -m "i18n: update source texts"

# Save SHA of the latest commit to English locale
echo "LAST_COMMIT_SHA_PUSH=$(git log -n 1 --format="%H" -- src/livecodes/i18n/locales/en)" >> $GITHUB_ENV
# # Save SHA of the latest commit to English locale
# echo "LAST_COMMIT_SHA_PUSH=$(git log -n 1 --format="%H" -- src/livecodes/i18n/locales/en)" >> $GITHUB_ENV

- name: Push changes
run: git push origin $BRANCH
# - name: Push changes
# run: git push origin $BRANCH

- name: Push source texts to Lokalise
run: npm run i18n-update-push -- $LOKALISE_BRANCH
# - name: Push source texts to Lokalise
# run: npm run i18n-update-push -- $LOKALISE_BRANCH

- name: Import from Lokalise
run: |
Expand Down Expand Up @@ -112,6 +112,8 @@ jobs:
echo "SKIP=true" >> $GITHUB_ENV
fi
echo "LAST_COMMIT_SHA_PUSH=$(git log -n 1 --format="%H" -- src/livecodes/i18n/locales/en)" >> $GITHUB_ENV
- name: Create a new i18n PR if not exists
uses: actions/github-script@v7
if: steps.check-diff.outputs.SKIP != 'true'
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ jobs:
runs-on: ubuntu-latest
if: contains(github.ref, 'refs/heads/releases/')
steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_ACTIONS_REPO_PAT }}
token: ${{ steps.generate-token.outputs.token }}

- name: Get version
id: vars
Expand All @@ -19,4 +26,4 @@ jobs:
- name: Create pull request to develop
run: gh pr create --title "Prepare release ${{steps.vars.outputs.version}}" --body "Prepare release ${{steps.vars.outputs.version}}" --base develop --head "${{github.ref_name}}"
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_PAT }}
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
15 changes: 11 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ jobs:
env:
NODE_OPTIONS: '--max_old_space_size=4096'
steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_ACTIONS_REPO_PAT }}
token: ${{ steps.generate-token.outputs.token }}

- name: Get version
id: vars
Expand Down Expand Up @@ -64,7 +71,7 @@ jobs:
files: |
livecodes-${{steps.vars.outputs.version}}.tar.gz
livecodes-${{steps.vars.outputs.version}}.zip
token: ${{ secrets.GH_ACTIONS_REPO_PAT }}
token: ${{ steps.generate-token.outputs.token }}

- name: Create permanent URL
if: startsWith(github.head_ref, 'releases/v')
Expand All @@ -88,10 +95,10 @@ jobs:
if: startsWith(github.head_ref, 'releases/v')
run: gh pr create --title "release ${{steps.vars.outputs.version}}" --body "https://${{steps.vars.outputs.version}}.livecodes.io" --base main --head develop
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_PAT }}
GITHUB_token: ${{ steps.generate-token.outputs.token }}

- name: Create pull request to main (SDK)
if: startsWith(github.head_ref, 'releases/sdk-v')
run: gh pr create --title "release ${{steps.vars.outputs.version}}" --body "https://www.npmjs.com/package/livecodes" --base main --head develop
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_PAT }}
GITHUB_token: ${{ steps.generate-token.outputs.token }}
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ A [feature-rich](https://livecodes.io/docs/features/), open-source, **client-sid
[![LiveCodes: jsdelivr downloads](https://data.jsdelivr.com/v1/package/npm/livecodes/badge?style=rounded)](https://www.jsdelivr.com/package/npm/livecodes)
[![LiveCodes: languages](https://img.shields.io/badge/languages-91-blue)](https://livecodes.io/docs/languages/)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/3d39f15618e048db9d13c2a0e8002b33)](https://www.codacy.com/gh/live-codes/livecodes/dashboard?utm_source=github.com&utm_medium=referral&utm_content=live-codes/livecodes&utm_campaign=Badge_Grade)
[![LiveCodes: i18n on Lokalise](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/live-codes/lokalise-badge/main/badge.json)](https://app.lokalise.com/public/34958094667a72e9454592.95108106/)
[![Lokalise: translated](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/live-codes/lokalise-badge/main/badges/translated.json)](https://app.lokalise.com/public/34958094667a72e9454592.95108106/)
[![Lokalise: UI languages](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/live-codes/lokalise-badge/main/badges/languages.json)](https://app.lokalise.com/public/34958094667a72e9454592.95108106/)
[![license - MIT](https://img.shields.io/github/license/live-codes/livecodes)](https://github.com/live-codes/livecodes/blob/develop/LICENSE)
[![LiveCodes: GitHub repo](https://img.shields.io/github/stars/live-codes/livecodes?style=social)](https://github.com/live-codes/livecodes)

Expand Down Expand Up @@ -266,6 +267,11 @@ LiveCodes uses services that are generously provided by:
</img></a><br /><br />
</p>
<p>
<a href="https://netlify.com/" target="_blank" title="Netlify">
<img alt="Netlify" width="200" src="https://dev.livecodes.io/docs/img/credits/netlify.svg">
</img></a><br /><br />
</p>
<p>
<a href="https://www.sonarsource.com/products/sonarcloud/" target="_blank" title="SonarCloud">
<img alt="SonarCloud" width="200" src="https://dev.livecodes.io/docs/img/credits/sonarcloud.svg">
</img></a><br /><br />
Expand Down
31 changes: 22 additions & 9 deletions docs/docs/contribution/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ Several npm scripts are available to facilitate the i18n workflow:
- [`i18n-exclude`](../../../scripts/i18n-exclude.js): **(Only used in other scripts and should not be run locally)** Excludes all other i18n locales except for English from type checking, as they might stay outdated and cause errors.
- The `<phase>` argument is required to specify whether the script is to exclude files or revert the exclusion. Valid values are `pre` and `post`.
- This script only works when environment variable `BUILD_INCLUDE_LOCALES` is **NOT** set to `true`.
- [`i18n-lokalise-json`](../../../scripts/i18n-lokalise-json.mjs): Generates `.lokalise.json` files from codebase for manually authoring translations on Lokalise.
- The `<lang>` argument is required to specify the language that the `.lokalise.json` files are generated from.

Please run `i18n-export` before pushing changes to the codebase to ensure that the source texts are up-to-date.

Expand All @@ -183,7 +185,11 @@ We consider the i18n process to consist of two parts:

This means there are no changes to the source code/texts, only translations are updated. Adding new languages or updating existing translations are examples of this part.

In such cases, there is a scheduled workflow [`i18n-update-scheduled`](../../../.github\workflows\i18n-update-scheduled.yml) to handle this. The workflow will sync between the `master` branch on Lokalise and the `i18n/develop` branch on the codebase, then automatically create a PR if there are any changes. Basically, maintainers do not need to pay too much attention to this part except for reviewing the PRs.
In such cases, there is a scheduled workflow [`i18n-update-scheduled`](../../../.github/workflows/i18n-update-scheduled.yml) to handle this. The workflow will sync from the `master` branch on Lokalise to the `i18n/develop` branch on the codebase, then automatically create a PR if there are any changes.

Basically, maintainers only need to focus on the following for this part:
- Reviewing PRs created by the `i18n-update-scheduled` workflow
- Do merging on Lokalise after they consider the translation for a specific feature is ready, before commenting `.i18n-update-pull` to trigger the `i18n-update-pull` workflow

#### Source Update

Expand All @@ -193,18 +199,18 @@ This means new changes are made to the source code/texts. In this case, maintain
2. Once a new feature or version is ready, developers run `npm run i18n-export` to extract and update all marked strings, then export them to `.lokalise.json` and `.ts` files.
3. Developers commit and push the changes to the repository. A feature PR is created and reviewed, and related tests, checks, and manual review could be carried out.
4. After the PR is merged, an auto-generated comment will notify maintainers to comment `.i18n-update-push` to trigger the `i18n-update-push` workflow when they think it is ready.
5. Maintainers comment `.i18n-update-push` to trigger the `i18n-update-push` workflow. The workflow will create a new branch named `i18n/<head-branch>`, run `npm run i18n-export` again to ensure the source texts are up-to-date, and push the changes. Then, it will push the changes to the `i18n/<head-branch>` branch on Lokalise.
5. Maintainers comment `.i18n-update-push` to trigger the `i18n-update-push` workflow. The workflow will create a new branch named `i18n/<owner>/<head-branch>`, run `npm run i18n-export` again to ensure the source texts are up-to-date, and push the changes. Then, it will push the changes to the `i18n/<owner>/<head-branch>` branch on Lokalise.
6. Translators can start translating the texts on Lokalise.
7. Once the translation is complete, maintainers can comment `.i18n-update-pull` to trigger the `i18n-update-pull` workflow. The workflow will pull the translated texts from Lokalise, update the `.ts` files under `src/livecodes/i18n/locales`, and commit the changes to the `i18n/<head-branch>` branch. Then, it will create a PR to merge the changes back to the default branch `develop`.
8. Maintainers should perform a final review on the i18n PR and merge it if everything is fine.
7. Once the translation is complete, maintainers can comment `.i18n-update-pull` to trigger the `i18n-update-pull` workflow. The workflow will pull the translated texts from Lokalise, update the `.ts` files under `src/livecodes/i18n/locales`, and commit the changes to the `i18n/<owner>/<head-branch>` branch. Then, it will create a PR to merge the changes back to the default branch `develop`.
8. Maintainers should perform a final review on the i18n PR and merge it if everything is fine. Meanwhile, a merging from the `i18n/<owner>/<head-branch>` to `master` should also be done to keep the `master` branch on Lokalise up-to-date.

### Github Actions (CI)

Four i18n-related workflows are set up in the repository:

- [`i18n-update-notify`](../../../.github\workflows\i18n-update-notify.yml): Creates a comment on merged PRs to notify maintainers to trigger the `i18n-update-push` workflow.
- [`i18n-update-push`](../../../.github\workflows\i18n-update-push.yml): Creates a new branch named `i18n/<head-branch>`, runs `npm run i18n-export` again to ensure the source texts are up-to-date, pushes the changes on git, then pushes the changes to the `i18n/<head-branch>` branch on Lokalise.
- [`i18n-update-pull`](../../../.github\workflows\i18n-update-pull.yml): Pulls the translated texts from Lokalise, updates the `.ts` files under `src/livecodes/i18n/locales`, commits the changes to the `i18n/<head-branch>` branch, then creates a PR to merge the changes back to the default branch `develop`.
- [`i18n-update-push`](../../../.github\workflows\i18n-update-push.yml): Creates a new branch named `i18n/<owner>/<head-branch>`, runs `npm run i18n-export` again to ensure the source texts are up-to-date, pushes the changes on git, then pushes the changes to the `i18n/<owner>/<head-branch>` branch on Lokalise.
- [`i18n-update-pull`](../../../.github\workflows\i18n-update-pull.yml): Pulls the translated texts from Lokalise, updates the `.ts` files under `src/livecodes/i18n/locales`, commits the changes to the `i18n/<owner>/<head-branch>` branch, then creates a PR to merge the changes back to the default branch `develop`.
- [`i18n-update-scheduled`](../../../.github\workflows\i18n-update-scheduled.yml): Syncs between the `master` branch on Lokalise and the `i18n/develop` branch on the codebase, then automatically creates a PR if there are any changes.

### Hashing and Cache
Expand All @@ -225,8 +231,15 @@ File hashing is also applied to translation files during build, by auto-generati

## For Those Who Forked the Repo

To ensure the i18n workflow functions properly, `Workflow permissions` in `Settings > Actions > General` should be set to `Read and write permissions`, and make sure that `Allow GitHub Actions to create and approve pull requests` is enabled.
This repository is utilizing [LiveCodes CI](https://github.com/apps/livecodes-ci) Github App to ensure the i18n workflow functions properly.

For forked repositories, maintainers should set up their own Lokalise project and Github App (see [here](https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens)) to handle the i18n workflow. Changes to related workflow files are necessary.

`LOKALISE_API_TOKEN` should be set as a repository secret, while `LOKALISE_PROJECT_ID` should be set as a repository variable.
### Secrets and Variables Checklist
#### Repository Secrets
- `LOKALISE_API_TOKEN`
- `CI_APP_ID`
- `CI_APP_PRIVATE_KEY`

For private forks, `GITHUB_TOKEN` in workflow files should be set to a personal access token (PAT) with proper permissions.
#### Repository Variables
- `LOKALISE_PROJECT_ID`
5 changes: 5 additions & 0 deletions docs/docs/credits.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ LiveCodes uses services that are generously provided by:
</img></a>
</p>
<p>
<a href="https://netlify.com/" target="_blank" title="Netlify">
<img alt="Netlify" width="200" style={{margin: "0.5em"}} src="/docs/img/credits/netlify.svg">
</img></a>
</p>
<p>
<a href="https://www.sonarsource.com/products/sonarcloud/" target="_blank" title="SonarCloud">
<img alt="SonarCloud" width="200" style={{margin: "0.5em"}} src="/docs/img/credits/sonarcloud.svg">
</img></a>
Expand Down
Loading

0 comments on commit c82beec

Please sign in to comment.