livecode代码开发分支
Some checks failed
CI-build / build (18.x) (push) Has been cancelled
CI-type-checking / type-check (18.x) (push) Has been cancelled
CI-typos / Spell Check (push) Has been cancelled
Deploy / deploy (push) Has been cancelled

This commit is contained in:
yangxin
2025-06-11 21:29:36 +08:00
commit 9f96998eb8
493 changed files with 75326 additions and 0 deletions

117
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View File

@@ -0,0 +1,117 @@
name: 🐛 Bug report
description: Create a bug report to help us improve LiveCodes
title: 'Bug: '
labels: [👀 needs triage, 🐛 bug]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: textarea
attributes:
label: Describe the bug
description: A clear and concise description of what the bug is.
validations:
required: true
- type: textarea
attributes:
label: Steps to reproduce
description: Describe how to reproduce the behavior.
placeholder: |
1. Go to '...'
2. Click on '...'
3. See error
validations:
required: true
- type: textarea
attributes:
label: Screenshots
description: Screenshots showing the issue.
- type: dropdown
attributes:
multiple: true
label: Affected services
description: Select the platforms where the issue can be reproduced.
options:
- 'LiveCodes App'
- 'LiveCodes Embedded Playgrounds'
- 'LiveCodes SDK'
- 'LiveCodes Services'
- 'LiveCodes Documentations'
- 'Repo build/deploy'
- 'Other'
- type: dropdown
attributes:
multiple: true
label: Platforms
description: Select the platforms where the issue can be reproduced.
options:
- 'Desktop'
- 'Mobile'
- 'Tablet'
- type: dropdown
attributes:
multiple: true
label: Browsers
description: Select the browsers where the issue can be reproduced.
options:
- 'Chrome'
- 'Firefox'
- 'Safari'
- 'Edge'
- 'Opera'
- 'Other (add additional context)'
- type: dropdown
attributes:
multiple: true
label: Environment
description: Select the environment where the issue can be reproduced.
options:
- 'Production'
- 'Development'
- 'Self-Hosted'
- 'Local'
- type: textarea
id: share
attributes:
label: Share URL(s)
description: Share URL(s) (App menu → Share) where the issue can be reproduced.
- type: textarea
id: config
attributes:
label: Configuration
description: Project configuration (App menu → Export → Export Project (JSON)) or embed options.
- type: textarea
id: logs
attributes:
label: Console logs
description: Provide console logs or screenshots for console.
- type: textarea
id: context
attributes:
label: Additional context
description: Add any other context about the problem or helpful links here.
- type: dropdown
attributes:
multiple: false
label: Is it already fixed?
description: Is it fixed on latest development build (http://dev.livecodes.io)?
options:
- 'No'
- 'Yes'
- type: checkboxes
id: terms
attributes:
label: Code of Conduct
description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/live-codes/livecodes/blob/HEAD/CODE_OF_CONDUCT.md)
options:
- label: I agree to follow this project's Code of Conduct
required: true
- type: checkboxes
id: contribution
attributes:
label: Contributing Docs
description: If you plan on contributing code please read - [Contribution Guide](https://github.com/live-codes/livecodes/blob/HEAD/CONTRIBUTING.md)
options:
- label: I agree to follow this project's Contribution Docs
required: false

5
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: ❓ Ask a question
url: https://livecodes.io/docs/contact/
about: Ask questions about open source onboarding

View File

@@ -0,0 +1,59 @@
name: 🚀 Feature request
description: Suggest an idea for this project 💡
title: 'Feature: '
labels: [👀 needs triage, 💡 feature]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this feature request!
- type: dropdown
attributes:
multiple: false
label: Type of feature
description: Select the type of feature request, the lowercase should also be the PR prefix.
options:
- '✨ Feature'
- '🐛 Fix'
- '📝 Documentation'
- '🎨 Style'
- '♻️ Refactor'
- '🔥 Performance'
- '✅ Test'
- '🤖 Build'
- '🔁 CI'
- '📦 Chore'
- '⏩ Revert'
validations:
required: true
- type: textarea
attributes:
label: Current behavior
description: Is your feature request related to a problem? Please describe.
- type: textarea
attributes:
label: Suggested feature
description: Describe the feature you'd like.
validations:
required: true
- type: textarea
id: context
attributes:
label: Additional context
description: Add any other context about the problem or helpful links here.
- type: checkboxes
id: terms
attributes:
label: Code of Conduct
description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/live-codes/livecodes/blob/HEAD/CODE_OF_CONDUCT.md)
options:
- label: I agree to follow this project's Code of Conduct
required: true
- type: checkboxes
id: contribution
attributes:
label: Contributing Docs
description: If you plan on contributing code please read - [Contribution Guide](https://github.com/live-codes/livecodes/blob/HEAD/CONTRIBUTING.md)
options:
- label: I agree to follow this project's Contribution Docs
required: false

44
.github/ISSUE_TEMPLATE/i18n_request.yml vendored Normal file
View File

@@ -0,0 +1,44 @@
name: 🌐 I18n Request
description: Request for internationalization support for a specific language
title: 'I18n: '
labels: [👀 needs triage, 🌐 I18n]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this i18n request!
- type: markdown
attributes:
value: |
Before submitting your request, please check out [our Lokalise project page](https://app.lokalise.com/public/34958094667a72e9454592.95108106/) to see if the language you are requesting is already supported or being currently worked on.
- type: input
attributes:
label: Requested language
description: The UI language you would like to request support for.
validations:
required: true
- type: textarea
attributes:
label: Supporting details
description: We want to hear why you think this language should be supported (e.g. user base, translation help, etc.). Please provide details regarding your request.
- type: textarea
id: context
attributes:
label: Additional context
description: Add any other context about the problem or helpful links here.
- type: checkboxes
id: terms
attributes:
label: Code of Conduct
description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/live-codes/livecodes/blob/HEAD/CODE_OF_CONDUCT.md)
options:
- label: I agree to follow this project's Code of Conduct
required: true
- type: checkboxes
id: contribution
attributes:
label: Contributing Docs
description: If you plan on contributing i18n please read - [Contribution Guide](https://github.com/live-codes/livecodes/blob/HEAD/CONTRIBUTING.md) and [I18n Guide](https://github.com/live-codes/livecodes/blob/HEAD/docs/docs/contribution/i18n.md)
options:
- label: I agree to follow this project's Contribution Docs
required: false

65
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@@ -0,0 +1,65 @@
<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for further details.
For a timely review/response, please avoid force-pushing additional
commits if your PR already received reviews or comments.
Before submitting a Pull Request, please ensure you've done the following:
- 📖 Read the LiveCodes Contributing Guide: https://github.com/live-codes/livecodes/blob/HEAD/CONTRIBUTING.md.
- 📖 Read the LiveCodes Code of Conduct: https://github.com/live-codes/livecodes/blob/HEAD/CODE_OF_CONDUCT.md.
- 👷‍♀️ Create small PRs. In most cases, this will be possible.
- ✅ Provide tests for your changes.
- 📝 Use descriptive commit messages.
- 📗 Update any related documentation and include any relevant screenshots.
- 🌐 Use `window.deps.translateString` in .ts files and add `data-i18n` attributes in .html files to mark strings that needs to be translated.
-->
## What type of PR is this? (check all applicable)
- [ ] ✨ Feature
- [ ] 🐛 Bug Fix
- [ ] 📝 Documentation Update
- [ ] 🎨 Style
- [ ] ♻️ Code Refactor
- [ ] 🔥 Performance Improvements
- [ ] ✅ Test
- [ ] 🤖 Build
- [ ] 🔁 CI
- [ ] 📦 Chore (Release)
- [ ] ⏩ Revert
- [ ] 🌐 Internationalization / Translation
## Description
<!--
Please do not leave this blank
This PR [adds/removes/fixes/replaces] the [feature/bug/etc].
-->
## Related Tickets & Documents
<!--
Please use this format link issue numbers: Fixes #123
-->
## Mobile & Desktop Screenshots/Recordings
<!-- Visual changes require screenshots -->
## Added tests?
- [ ] 👍 yes
- [ ] 🙅 no, because they aren't needed
- [ ] 🙋 no, because I need help
## Added to documentations?
- [ ] 📓 docs (./docs)
- [ ] 📕 storybook (./storybook)
- [ ] 📜 README.md
- [ ] 🙅 no documentation needed
## [optional] Are there any post-deployment tasks we need to perform?
## [optional] What gif best describes this PR or how it makes you feel?

36
.github/workflows/CI-build.yml vendored Normal file
View File

@@ -0,0 +1,36 @@
name: CI-build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
env:
NODE_OPTIONS: '--max_old_space_size=4096'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
env:
BUILD_INCLUDE_LOCALES: ${{ startsWith(github.head_ref, 'i18n/') }}
- name: Test
run: npm run test
env:
CI: true
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}

39
.github/workflows/CI-e2e.yml vendored Normal file
View File

@@ -0,0 +1,39 @@
name: CI-e2e
on: [pull_request]
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [18.x]
test: [1, 2, 3, 4, 5]
env:
NODE_OPTIONS: '--max_old_space_size=4096'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
env:
BUILD_INCLUDE_LOCALES: ${{ startsWith(github.head_ref, 'i18n/') }}
- name: Test ${{ matrix.test }}
run: npm run ci:e2e
env:
CI: true
CI_SHARD_INDEX: ${{ matrix.test }}
CI_SHARD_TOTAL: 5

28
.github/workflows/CI-type-checking.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: CI-type-checking
on: [push, pull_request]
jobs:
type-check:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
env:
NODE_OPTIONS: '--max_old_space_size=4096'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Type Checking
run: npm run check-types

16
.github/workflows/CI-typos.yml vendored Normal file
View File

@@ -0,0 +1,16 @@
name: CI-typos
on: [push, pull_request]
jobs:
spell-check:
name: Spell Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check typos on code
uses: crate-ci/typos@master
with:
config: ./typos.toml

17
.github/workflows/bundle-size.yml vendored Normal file
View File

@@ -0,0 +1,17 @@
name: Bundle Size
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: preactjs/compressed-size-action@v2
with:
build-script: 'build:app'
pattern: './build/**/*.{js,css,html,json}'
strip-hash: "\\b\\w{32}\\."
minimum-change-threshold: 200
compression: 'brotli'

45
.github/workflows/deploy.yml vendored Normal file
View File

@@ -0,0 +1,45 @@
name: Deploy
# on push to main deploy (as self-hosted build) to github pages
on:
push:
branches:
- main
env:
NODE_VERSION: 18.x
jobs:
deploy:
runs-on: ubuntu-latest
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: ${{ steps.generate-token.outputs.token }}
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install dependencies
run: npm ci
- 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>"
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

View File

@@ -0,0 +1,38 @@
name: i18n-update-notify
on:
pull_request_target:
branches: [develop]
types: [closed]
paths: ['src/livecodes/i18n/locales/**']
jobs:
notify:
name: Notify
runs-on: ubuntu-latest
if: github.event.pull_request.merged && github.event.sender.login != 'github-actions[bot]' && !startsWith(github.head_ref, 'i18n/')
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: Create comment on PR
uses: actions/github-script@v6
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const commentBody = `## i18n Actions
Source PR has been merged into the default branch.
Maintainers can comment \`.i18n-update-push\` to trigger the i18n update workflow and push the changes to Lokalise.
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})

235
.github/workflows/i18n-update-pull.yml vendored Normal file
View File

@@ -0,0 +1,235 @@
name: i18n-update-pull
on:
issue_comment:
types: [created]
env:
LOKALISE_PROJECT_ID: ${{ vars.LOKALISE_PROJECT_ID }}
LOKALISE_API_TOKEN: ${{ secrets.LOKALISE_API_TOKEN }}
NODE_VERSION: 18.x
CI: true
jobs:
precheck:
name: Pre-check
runs-on: ubuntu-latest
if: github.event.issue.pull_request && github.event.issue.pull_request.merged_at && github.event.issue.state == 'closed' && github.event.comment.body == '.i18n-update-pull' && (github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER')
outputs:
skip: ${{ steps.fetch-pr.outputs.skip }}
skipReason: ${{ steps.fetch-pr.outputs.skipReason }}
newBranch: ${{ steps.fetch-pr.outputs.newBranch }}
branch: ${{ steps.fetch-pr.outputs.branch }}
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: Check out repository
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}
- name: Fetch PR details
id: fetch-pr
run: |
PR_DETAILS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "${{ github.event.issue.pull_request.url }}")
PR_BRANCH=$(echo "$PR_DETAILS" | jq -r '.head.ref')
skip () {
echo "$1 Exiting..."
echo "skip=true" >> $GITHUB_OUTPUT
echo "skipReason=$1" >> $GITHUB_OUTPUT
}
if [[ $PR_BRANCH == "i18n/"* ]]; then
skip "Branch \`$PR_BRANCH\` is a i18n branch."
fi
PR_BRANCH=$(echo "$PR_DETAILS" | jq -r '.head.label' | sed 's/:/\//g')
NEW_BRANCH="i18n/$PR_BRANCH"
echo "newBranch=$NEW_BRANCH" >> $GITHUB_OUTPUT
echo "branch=$PR_BRANCH" >> $GITHUB_OUTPUT
git config --global user.name "livecodes-ci[bot]"
git config --global user.email "186997172+livecodes-ci[bot]@users.noreply.github.com"
if [[ ! $(git ls-remote --heads origin $NEW_BRANCH) ]]; then
skip "Branch \`$NEW_BRANCH\` does not exist."
fi
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
runner:
name: Runner
runs-on: ubuntu-latest
needs: precheck
if: needs.precheck.outputs.skip != 'true'
env:
NEW_BRANCH: ${{ needs.precheck.outputs.newBranch }}
PR_BRANCH: ${{ needs.precheck.outputs.branch }}
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: Check out repository
uses: actions/checkout@v4
with:
ref: ${{ needs.precheck.outputs.newBranch }}
token: ${{ steps.generate-token.outputs.token }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Import from Lokalise
run: |
mkdir -p $LOKALISE_TEMP && touch $LOKALISE_TEMP/locales.zip && npm run i18n-update-pull -- $PR_BRANCH && rm -rf $LOKALISE_TEMP
env:
LOKALISE_TEMP: lokalise_tmp
- name: Generate Lokalise JSON files
run: npm run i18n-lokalise-json all
- name: Linting and fixing
run: npm run fix
- name: Commit changes
run: |
git config --global user.name "livecodes-ci[bot]"
git config --global user.email "186997172+livecodes-ci[bot]@users.noreply.github.com"
git add .
# Only commit if there are changes
git diff-index --quiet HEAD || git commit -m "i18n: pull translation from Lokalise"
# Save SHA of the latest commit to locale
echo "LAST_COMMIT_SHA=$(git log -n 1 --format="%H" -- src/livecodes/i18n/locales)" >> $GITHUB_ENV
- name: Push changes
run: git push origin $NEW_BRANCH
- name: Create a new i18n PR, comment on source PR and reaction
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const repoURL = context.payload.repository.html_url;
const branchURL = `${repoURL}/tree/${process.env.NEW_BRANCH}`;
const prTitle = `i18n: ${{ github.event.issue.title }}`;
const prBody = `## What type of PR is this? (check all applicable)
- [ ] ✨ Feature
- [ ] 🐛 Bug Fix
- [ ] 📝 Documentation Update
- [ ] 🎨 Style
- [ ] ♻️ Code Refactor
- [ ] 🔥 Performance Improvements
- [ ] ✅ Test
- [ ] 🤖 Build
- [ ] 🔁 CI
- [ ] 📦 Chore (Release)
- [ ] ⏩ Revert
- [x] 🌐 Internationalization / Translation
## Description
### i18n Actions: \`.i18n-update-pull\`
Localization pulled from Lokalise.
| Name | Description |
| --- | --- |
| **i18n Branch** | [\`${process.env.NEW_BRANCH}\`](${branchURL}) |
| **Last Commit SHA** | ${process.env.LAST_COMMIT_SHA} |
## Related Tickets & Documents
- **Source PR**: #${{ github.event.issue.number }}
`;
const prInfo = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: prTitle,
body: prBody,
head: process.env.NEW_BRANCH,
base: '${{ github.event.repository.default_branch }}'
});
const commentBody = `## i18n Actions: \`.i18n-update-pull\`
Localization pulled from Lokalise.
| Name | Description |
| --- | --- |
| **i18n Branch** | [\`${process.env.NEW_BRANCH}\`](${branchURL}) |
| **Last Commit SHA** | ${process.env.LAST_COMMIT_SHA} |
| **i18n PR** | #${prInfo.data.number} |
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ github.event.comment.id }},
content: 'rocket'
});
exception:
name: Exception
runs-on: ubuntu-latest
needs: precheck
if: needs.precheck.outputs.skip == 'true'
env:
SKIP_REASON: ${{ needs.precheck.outputs.skipReason }}
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: Create reaction on PR
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const runURL = `${context.payload.repository.html_url}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const commentBody = `## i18n Actions: \`.i18n-update-pull\`
Failed to perform action due to following reason: **${process.env.SKIP_REASON}**
Please check [action logs](${runURL}) for more details.
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ github.event.comment.id }},
content: 'confused'
});

195
.github/workflows/i18n-update-push.yml vendored Normal file
View File

@@ -0,0 +1,195 @@
name: i18n-update-push
on:
issue_comment:
types: [created]
env:
LOKALISE_PROJECT_ID: ${{ vars.LOKALISE_PROJECT_ID }}
LOKALISE_API_TOKEN: ${{ secrets.LOKALISE_API_TOKEN }}
NODE_VERSION: 18.x
CI: true
jobs:
precheck:
name: Pre-check
runs-on: ubuntu-latest
if: github.event.issue.pull_request && github.event.issue.pull_request.merged_at && github.event.issue.state == 'closed' && github.event.comment.body == '.i18n-update-push' && (github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER')
outputs:
skip: ${{ steps.fetch-pr.outputs.skip }}
skipReason: ${{ steps.fetch-pr.outputs.skipReason }}
newBranch: ${{ steps.fetch-pr.outputs.newBranch }}
branch: ${{ steps.fetch-pr.outputs.branch }}
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: Check out repository
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}
- name: Fetch PR details
id: fetch-pr
run: |
PR_DETAILS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "${{ github.event.issue.pull_request.url }}")
PR_BRANCH=$(echo "$PR_DETAILS" | jq -r '.head.ref')
if [[ $PR_BRANCH == "i18n/"* ]]; then
SKIP_REASON="Branch \`$PR_BRANCH\` is a i18n branch."
echo "$SKIP_REASON Exiting..."
echo "skip=true" >> $GITHUB_OUTPUT
echo "skipReason=$SKIP_REASON" >> $GITHUB_OUTPUT
fi
# Use branch name prefixed with owner name
PR_BRANCH=$(echo "$PR_DETAILS" | jq -r '.head.label' | sed 's/:/\//g')
NEW_BRANCH="i18n/$PR_BRANCH"
echo "newBranch=$NEW_BRANCH" >> $GITHUB_OUTPUT
echo "branch=$PR_BRANCH" >> $GITHUB_OUTPUT
git config --global user.name "livecodes-ci[bot]"
git config --global user.email "186997172+livecodes-ci[bot]@users.noreply.github.com"
if [[ $(git ls-remote --heads origin $NEW_BRANCH) ]]; then
SKIP_REASON="Branch \`$NEW_BRANCH\` already exists."
echo "$SKIP_REASON Exiting..."
echo "skip=true" >> $GITHUB_OUTPUT
echo "skipReason=$SKIP_REASON" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
runner:
name: Runner
runs-on: ubuntu-latest
needs: precheck
if: needs.precheck.outputs.skip != 'true'
env:
NEW_BRANCH: ${{ needs.precheck.outputs.newBranch }}
PR_BRANCH: ${{ needs.precheck.outputs.branch }}
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: Check out repository
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Create new branch
run: git checkout -b $NEW_BRANCH
- name: Linting and fixing
run: npm run fix
- name: Commit changes
run: |
git config --global user.name "livecodes-ci[bot]"
git config --global user.email "186997172+livecodes-ci[bot]@users.noreply.github.com"
git add .
# 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=$(git log -n 1 --format="%H" -- src/livecodes/i18n/locales/en)" >> $GITHUB_ENV
- name: Push changes
run: git push origin $NEW_BRANCH
- name: Push source texts to Lokalise
run: npm run i18n-update-push -- $PR_BRANCH
- name: Create comment and reaction on PR
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const repoURL = context.payload.repository.html_url;
const branchURL = `${repoURL}/tree/${process.env.NEW_BRANCH}`;
const commentBody = `## i18n Actions: \`.i18n-update-push\`
Localization updated and pushed to [Lokalise](https://app.lokalise.com/project/${process.env.LOKALISE_PROJECT_ID}/?branch=${process.env.PR_BRANCH}).
| Name | Description |
| --- | --- |
| **New Branch for i18n** | [\`${process.env.NEW_BRANCH}\`](${branchURL}) |
| **Last Commit SHA** | ${process.env.LAST_COMMIT_SHA} |
Maintainers can comment \`.i18n-update-pull\` after translation is done to trigger the i18n pull workflow and pull the changes back to Github.
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ github.event.comment.id }},
content: 'rocket'
});
exception:
name: Exception
runs-on: ubuntu-latest
needs: precheck
if: needs.precheck.outputs.skip == 'true'
env:
SKIP_REASON: ${{ needs.precheck.outputs.skipReason }}
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: Create comment and reaction on PR
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const runURL = `${context.payload.repository.html_url}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const commentBody = `## i18n Actions: \`.i18n-update-push\`
Failed to perform action due to following reason: **${process.env.SKIP_REASON}**
Please check [action logs](${runURL}) for more details.
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ github.event.comment.id }},
content: 'confused'
});

View File

@@ -0,0 +1,179 @@
name: i18n-update-scheduled
# Triggered weekly to update source texts and push them to Lokalise, then pull the translations back to Github.
# Work on i18n/develop branch.
on:
schedule:
- cron: '0 0 * * 0'
push:
branches:
- develop
workflow_dispatch:
env:
LOKALISE_PROJECT_ID: ${{ vars.LOKALISE_PROJECT_ID }}
LOKALISE_API_TOKEN: ${{ secrets.LOKALISE_API_TOKEN }}
BRANCH: i18n/develop
LOKALISE_BRANCH: master
NODE_VERSION: 18.x
CI: true
jobs:
update:
name: Push and Pull
runs-on: ubuntu-latest
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: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.generate-token.outputs.token }}
- name: Switch to i18n branch
run: |
git config --global user.name "livecodes-ci[bot]"
git config --global user.email "186997172+livecodes-ci[bot]@users.noreply.github.com"
if [[ $(git ls-remote --heads origin $BRANCH) ]]; then
git config pull.rebase false
git fetch origin $BRANCH:$BRANCH
git checkout $BRANCH
else
git checkout -b $BRANCH
fi
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install dependencies
run: npm ci
# - name: Linting and fixing
# run: npm run fix
# - name: Commit changes
# run: |
# git add .
# # 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
# - name: Push changes
# run: git push origin $BRANCH
# - name: Push source texts to Lokalise
# run: npm run i18n-update-push -- $LOKALISE_BRANCH
- name: Import from Lokalise
run: |
mkdir -p $LOKALISE_TEMP && touch $LOKALISE_TEMP/locales.zip && npm run i18n-update-pull -- $LOKALISE_BRANCH && rm -rf $LOKALISE_TEMP
env:
LOKALISE_TEMP: lokalise_tmp
- name: Linting and fixing
run: npm run fix
- name: Commit changes
run: |
git add .
# Only commit if there are changes
git diff-index --quiet HEAD || git commit -m "i18n: pull translation from Lokalise"
# Save SHA of the latest commit to locale
echo "LAST_COMMIT_SHA_PULL=$(git log -n 1 --format="%H" -- src/livecodes/i18n/locales)" >> $GITHUB_ENV
- name: Push changes
run: |
git pull origin ${{ github.event.repository.default_branch }} || {
echo "Failed to pull from ${{ github.event.repository.default_branch }}."
echo "Please manually pull the changes, solve potential conflicts, and re-run the workflow."
echo "::error title=Pull failed::Failed to pull from ${{ github.event.repository.default_branch }}."
exit 1
}
git push origin $BRANCH
- name: Check if has differences between ${{ env.BRANCH }} and ${{ github.event.repository.default_branch }}
id: check-diff
run: |
DIFF=$(git diff --name-only $BRANCH origin/${{ github.event.repository.default_branch }})
if [[ -z $DIFF ]]; then
echo "No difference between $BRANCH and ${{ github.event.repository.default_branch }}."
echo "SKIP=true" >> $GITHUB_OUTPUT
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'
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const prInfo = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: process.env.BRANCH
});
if (prInfo.data.length > 0) {
return;
}
console.log(`Creating a new i18n PR from ${process.env.BRANCH}...`);
const repoURL = context.payload.repository.html_url;
const branchURL = `${repoURL}/tree/${process.env.BRANCH}`;
const prTitle = `i18n: scheduled update from ${process.env.BRANCH}`;
const prBody = `## What type of PR is this? (check all applicable)
- [ ] ✨ Feature
- [ ] 🐛 Bug Fix
- [ ] 📝 Documentation Update
- [ ] 🎨 Style
- [ ] ♻️ Code Refactor
- [ ] 🔥 Performance Improvements
- [ ] ✅ Test
- [ ] 🤖 Build
- [ ] 🔁 CI
- [ ] 📦 Chore (Release)
- [ ] ⏩ Revert
- [x] 🌐 Internationalization / Translation
## Description
### i18n Actions: \`.i18n-update-scheduled\`
Scheduled update of source texts and translations.
| Name | Description |
| --- | --- |
| **Last Commit SHA (Push)** | ${process.env.LAST_COMMIT_SHA_PUSH} |
| **Last Commit SHA (Pull)** | ${process.env.LAST_COMMIT_SHA_PULL} |
`;
github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: prTitle,
body: prBody,
head: process.env.BRANCH,
base: '${{ github.event.repository.default_branch }}'
});

29
.github/workflows/release-pr.yml vendored Normal file
View File

@@ -0,0 +1,29 @@
name: Release PR
# on creating a release branch (releases/**) create a PR to develop
on: create
jobs:
release:
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: ${{ steps.generate-token.outputs.token }}
- name: Get version
id: vars
run: echo ::set-output name=version::$(echo ${{github.ref_name}} | sed 's/^releases\///')
- 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: ${{ steps.generate-token.outputs.token }}

104
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,104 @@
name: Release
on:
pull_request:
branches:
- develop
types: [closed]
env:
NODE_VERSION: 18.x
jobs:
release:
runs-on: ubuntu-latest
if: github.event.pull_request.merged && startsWith(github.head_ref, 'releases/')
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: ${{ steps.generate-token.outputs.token }}
- name: Get version
id: vars
run: echo ::set-output name=version::$(echo ${{github.head_ref}} | sed 's/^releases\///')
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
env:
BUILD_INCLUDE_LOCALES: true
- name: Release notes
run: node ./scripts/release-notes.js
- name: Create tag
run: git tag ${{steps.vars.outputs.version}} && git push origin --tags
- name: Compress build directory (tar)
run: tar -czf livecodes-${{steps.vars.outputs.version}}.tar.gz build
- name: Compress build directory (zip)
uses: vimtor/action-zip@v1
with:
files: build/
dest: livecodes-${{steps.vars.outputs.version}}.zip
- name: Create release
uses: softprops/action-gh-release@v1
with:
name: ${{steps.vars.outputs.version}}
tag_name: ${{steps.vars.outputs.version}}
body_path: CHANGELOG.tmp.md
files: |
livecodes-${{steps.vars.outputs.version}}.tar.gz
livecodes-${{steps.vars.outputs.version}}.zip
token: ${{ steps.generate-token.outputs.token }}
- name: Create permanent URL
if: startsWith(github.head_ref, 'releases/v')
run: node ./scripts/create-permanent-url.js
env:
APP_VERSION: ${{steps.vars.outputs.version}}
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
CF_ZONE: ${{ secrets.CF_ZONE }}
CF_TOKEN: ${{ secrets.CF_TOKEN }}
- name: Publish SDK to NPM
if: startsWith(github.head_ref, 'releases/sdk-v')
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
npm publish --access=public
working-directory: ./build/sdk
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Create pull request to main (App)
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: ${{ 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: ${{ steps.generate-token.outputs.token }}