livecode代码开发分支
This commit is contained in:
36
.github/workflows/CI-build.yml
vendored
Normal file
36
.github/workflows/CI-build.yml
vendored
Normal 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
39
.github/workflows/CI-e2e.yml
vendored
Normal 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
28
.github/workflows/CI-type-checking.yml
vendored
Normal 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
16
.github/workflows/CI-typos.yml
vendored
Normal 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
17
.github/workflows/bundle-size.yml
vendored
Normal 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
45
.github/workflows/deploy.yml
vendored
Normal 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 }}
|
||||
38
.github/workflows/i18n-update-notify.yml
vendored
Normal file
38
.github/workflows/i18n-update-notify.yml
vendored
Normal 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
235
.github/workflows/i18n-update-pull.yml
vendored
Normal 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
195
.github/workflows/i18n-update-push.yml
vendored
Normal 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'
|
||||
});
|
||||
179
.github/workflows/i18n-update-scheduled.yml
vendored
Normal file
179
.github/workflows/i18n-update-scheduled.yml
vendored
Normal 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
29
.github/workflows/release-pr.yml
vendored
Normal 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
104
.github/workflows/release.yml
vendored
Normal 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 }}
|
||||
Reference in New Issue
Block a user