Skip to content

Fix/ts type imports #1158

Fix/ts type imports

Fix/ts type imports #1158

name: pull_request test
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
branches: [master]
# 用 paths 正选 + ! 排除:paths-ignore 下只要 PR 里存在任一「未忽略」文件就会跑 CI(易误以为只改了 version)。
# 此处先 ** 再 !,使「仅清单/锁/文档/.github 等」的 PR 不触发;vendor 等其它 package.json 仍会触发。
paths:
- '**'
- '!package.json'
- '!yarn.lock'
- '!app/renderer/src/main/package.json'
- '!app/renderer/src/main/yarn.lock'
- '!app/renderer/engine-link-startup/package.json'
- '!app/renderer/engine-link-startup/yarn.lock'
- '!README.md'
- '!README-EN.md'
- '!README_LEGACY.md'
- '!LICENSE.md'
- '!docs/**'
# - '!.github/**'
- '!**/*.md'
- '!**/*.txt'
- '!.vscode/**'
env:
HUSKY: '0'
jobs:
prepare:
name: prepare(变更列表 · Vitest 选择)
runs-on: ubuntu-latest
outputs:
vitest_tests: ${{ steps.vitest_select.outputs.tests }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 22.22.1
- name: Get PR changed files
id: changed_files
uses: tj-actions/changed-files@v47
with:
base_sha: ${{ github.event.pull_request.base.sha }}
safe_output: false
quotepath: 'false'
separator: "\n"
- name: Print PR changed files
shell: bash
env:
ALL_CHANGED_FILES: ${{ steps.changed_files.outputs.all_changed_files }}
run: |
echo 'Changed files from tj-actions/changed-files:'
if [ -z "${ALL_CHANGED_FILES:-}" ]; then
echo '(none)'
else
printf '%s\n' "$ALL_CHANGED_FILES"
fi
- name: Write PR changed paths (UTF-8, one path per line, for Prettier/media)
env:
ALL_CHANGED_FILES: ${{ steps.changed_files.outputs.all_changed_files }}
shell: bash
run: |
set -euo pipefail
printf '%s' "${ALL_CHANGED_FILES:-}" > pr-ci-changed-files-list.txt
echo "Changed path lines: $(wc -l < pr-ci-changed-files-list.txt | tr -d ' \t')"
echo '---- sample paths (debug) ----'
head -5 pr-ci-changed-files-list.txt || true
echo '-------------------------------'
- name: Select Vitest targets
id: vitest_select
shell: bash
env:
CHANGED_FILES_PATH: ${{ github.workspace }}/pr-ci-changed-files-list.txt
CI_DEBUG_VITEST_SELECT: '0'
run: node scripts/ci-select-vitest-tests.js
- uses: actions/upload-artifact@v4
name: Upload changed paths
with:
name: ci-changed-files-list
path: pr-ci-changed-files-list.txt
if-no-files-found: error
ci-i18n:
name: i18n(renderer zh/zh-TW/en)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 22.22.1
- name: Check i18n parity (renderer zh/zh-TW/en)
shell: bash
run: |
set -o pipefail
node scripts/locale-parity.js 2>&1 | tee i18n-output.log
- uses: actions/upload-artifact@v4
if: always()
with:
name: ci-log-i18n
path: i18n-output.log
if-no-files-found: warn
ci-i18n-engine-link:
name: i18n(engine-link zh/zh-TW/en)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 22.22.1
- name: Check i18n parity (engine-link zh/zh-TW/en)
shell: bash
run: |
set -o pipefail
(cd app/renderer/engine-link-startup && node scripts/locale-parity.cjs) 2>&1 | tee i18n-engine-link-output.log
- uses: actions/upload-artifact@v4
if: always()
with:
name: ci-log-i18n-engine-link
path: i18n-engine-link-output.log
if-no-files-found: warn
ci-eslint-renderer:
name: ESLint(renderer src/main)
uses: ./.github/workflows/pr-ci-yarn-check.yml
secrets: inherit
with:
pr_repository: ${{ github.event.pull_request.head.repo.full_name }}
pr_ref: ${{ github.event.pull_request.head.ref }}
workdir: app/renderer/src/main
run_command: npx eslint src --ext .js,.jsx,.ts,.tsx
log_filename: eslint-output.log
artifact_name: ci-log-eslint-renderer
ci-tsc-renderer:
name: TypeScript(renderer src/main)
uses: ./.github/workflows/pr-ci-yarn-check.yml
secrets: inherit
with:
pr_repository: ${{ github.event.pull_request.head.repo.full_name }}
pr_ref: ${{ github.event.pull_request.head.ref }}
workdir: app/renderer/src/main
run_command: npx tsc -p tsconfig.json --noEmit
log_filename: tsc-output.log
artifact_name: ci-log-tsc-renderer
ci-eslint-engine-link:
name: ESLint(engine-link-startup)
uses: ./.github/workflows/pr-ci-yarn-check.yml
secrets: inherit
with:
pr_repository: ${{ github.event.pull_request.head.repo.full_name }}
pr_ref: ${{ github.event.pull_request.head.ref }}
workdir: app/renderer/engine-link-startup
run_command: npx eslint src --ext .js,.jsx,.ts,.tsx
log_filename: eslint-engine-link-output.log
artifact_name: ci-log-eslint-engine-link
ci-tsc-engine-link:
name: TypeScript(engine-link-startup)
uses: ./.github/workflows/pr-ci-yarn-check.yml
secrets: inherit
with:
pr_repository: ${{ github.event.pull_request.head.repo.full_name }}
pr_ref: ${{ github.event.pull_request.head.ref }}
workdir: app/renderer/engine-link-startup
run_command: npx tsc -p tsconfig.json --noEmit
log_filename: tsc-engine-link-output.log
artifact_name: ci-log-tsc-engine-link
ci-media:
name: 图片/视频体积
runs-on: ubuntu-latest
needs: [prepare]
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 22.22.1
- uses: actions/download-artifact@v4
with:
name: ci-changed-files-list
path: .
- name: Media size check (changed images/videos)
shell: bash
env:
CHANGED_FILES_PATH: ${{ github.workspace }}/pr-ci-changed-files-list.txt
run: |
set -o pipefail
node scripts/check-media-size.js 2>&1 | tee media-output.log
- uses: actions/upload-artifact@v4
if: always()
with:
name: ci-log-media
path: media-output.log
if-no-files-found: warn
ci-vitest:
name: Vitest(选中用例)
runs-on: ubuntu-latest
needs: [prepare]
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: ./.github/actions/pr-ci-setup-node-yarn
- name: Run Vitest (changed-area tests)
shell: bash
env:
CI: 'true'
CI_VITEST_TESTS: ${{ needs.prepare.outputs.vitest_tests }}
run: |
set -o pipefail
root="$(git rev-parse --show-toplevel)"
cd "$root"
TESTS="$CI_VITEST_TESTS"
if [ -z "$TESTS" ] || [ "$TESTS" = "none" ]; then
echo "No vitest targets (prepare 输出 tests=none 或空),跳过" | tee "$root/vitest-output.log"
exit 0
fi
echo "Running vitest for: $TESTS"
shopt -s globstar nullglob
EXPANDED_TESTS=$(eval echo $TESTS)
echo "Expanded: $EXPANDED_TESTS"
yarn test:vitest $EXPANDED_TESTS --run --reporter verbose 2>&1 | tee "$root/vitest-output.log"
- uses: actions/upload-artifact@v4
if: always()
with:
name: ci-log-vitest
path: vitest-output.log
if-no-files-found: warn
ci-prettier:
name: Prettier(变更文件 · 同仓库可写回)
runs-on: ubuntu-latest
needs: [prepare]
permissions:
contents: write
pull-requests: read
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: ./.github/actions/pr-ci-setup-node-yarn
- uses: actions/download-artifact@v4
with:
name: ci-changed-files-list
path: .
- name: Format or check PR changed files with prettier
id: format_step
shell: bash
env:
IS_FORK_PR: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
run: |
set -o pipefail
{
format_targets=()
if [ -f pr-ci-changed-files-list.txt ]; then
while IFS= read -r file || [ -n "$file" ]; do
[ -z "$file" ] && continue
if [ -f "$file" ]; then
format_targets+=("$file")
fi
done < pr-ci-changed-files-list.txt
fi
if [ "${#format_targets[@]}" -eq 0 ]; then
echo "No valid files to format."
exit 0
fi
if [ "$IS_FORK_PR" = 'true' ]; then
echo "Fork PR detected. Checking ${#format_targets[@]} file(s)..."
npx prettier@3.8.1 --config .prettierrc.js --ignore-path .prettierignore --check --ignore-unknown "${format_targets[@]}"
else
echo "Same-repo PR detected. Formatting ${#format_targets[@]} file(s)..."
npx prettier@3.8.1 --config .prettierrc.js --ignore-path .prettierignore --write --ignore-unknown "${format_targets[@]}"
fi
} 2>&1 | tee format-output.log
- uses: actions/upload-artifact@v4
if: always()
with:
name: ci-log-prettier
path: format-output.log
if-no-files-found: warn
- name: Commit formatted files
if: success() && github.event.pull_request.head.repo.full_name == github.repository
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git reset -- .github/workflows || true
if git diff-index --quiet HEAD; then
echo "No formatting changes, nothing to commit"
else
git commit -m "style: apply prettier formatting [skip ci]"
git push
fi
ci-pr-summary:
name: PR 汇总评论
runs-on: ubuntu-latest
needs:
- prepare
- ci-i18n
- ci-i18n-engine-link
- ci-eslint-renderer
- ci-tsc-renderer
- ci-eslint-engine-link
- ci-tsc-engine-link
- ci-media
- ci-vitest
- ci-prettier
if: always() && github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: actions/download-artifact@v4
continue-on-error: true
with:
pattern: ci-log-*
merge-multiple: true
path: .
- name: Map Vitest outcome(无选中用例 ⇒ skipped,与原先 step 被 skip 一致)
id: map_vitest
shell: bash
run: |
vt='${{ needs.prepare.outputs.vitest_tests }}'
r='${{ needs.ci-vitest.result }}'
if [ -z "$vt" ] || [ "$vt" = "none" ]; then
echo "outcome=skipped" >> "$GITHUB_OUTPUT"
else
echo "outcome=$r" >> "$GITHUB_OUTPUT"
fi
- name: Render PR CI summary (body for maintain-one-comment)
id: pr_comment
env:
OUTCOME_I18N: ${{ needs.ci-i18n.result }}
OUTCOME_I18N_ENGINE_LINK: ${{ needs.ci-i18n-engine-link.result }}
OUTCOME_ESLINT: ${{ needs.ci-eslint-renderer.result }}
OUTCOME_TSC: ${{ needs.ci-tsc-renderer.result }}
OUTCOME_ESLINT_ENGINE_LINK: ${{ needs.ci-eslint-engine-link.result }}
OUTCOME_TSC_ENGINE_LINK: ${{ needs.ci-tsc-engine-link.result }}
OUTCOME_MEDIA: ${{ needs.ci-media.result }}
OUTCOME_VITEST: ${{ steps.map_vitest.outputs.outcome }}
OUTCOME_FORMAT: ${{ needs.ci-prettier.result }}
run: node scripts/ci-render-pr-summary.js
# actions-cool/maintain-one-comment 仓库已被 GitHub 官方禁用(terms of service 违规)。
# 此处用 gh CLI 内联模拟其「按标记找已有评论:有则更新 / 没有则新建」的行为,零外部 action 依赖。
# 评论 body 直接读 scripts/ci-render-pr-summary.js 已写入的 pr-comment.md(含 marker)。
- name: Maintain one PR comment
if: steps.pr_comment.outcome == 'success'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
MARKER: '<!-- pr-ci-one-comment -->'
shell: bash
run: |
set -euo pipefail
if [ ! -s pr-comment.md ]; then
echo 'pr-comment.md missing or empty; skip commenting.'
exit 0
fi
existing_id=$(
gh api --paginate \
"repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
--jq '.[] | select(.body | contains(env.MARKER)) | .id' \
| head -n1
)
if [ -n "${existing_id}" ]; then
echo "Updating existing PR comment #${existing_id}"
gh api --method PATCH \
"repos/${GITHUB_REPOSITORY}/issues/comments/${existing_id}" \
-F body=@pr-comment.md >/dev/null
else
echo "Creating new PR comment on PR #${PR_NUMBER}"
gh api --method POST \
"repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
-F body=@pr-comment.md >/dev/null
fi