Skip to content

Fix/Add/Delete: recomputer R1100 According to technical support feedb… #1

Fix/Add/Delete: recomputer R1100 According to technical support feedb…

Fix/Add/Delete: recomputer R1100 According to technical support feedb… #1

name: Test deployment
on:
pull_request:
paths-ignore:
- "ISSUE_TEMPLATE/**"
- ".github/**.md"
- ".gitignore"
- "demo/**"
- "docker/**"
- "HOW_TO.md"
- "TASK.md"
- "SECURITY.md"
- "README.md"
- "README_zh-CN.md"
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
# 添加push事件,确保翻译后的提交也会触发检查
push:
# 只在PR分支上触发,避免在主分支上重复运行
branches-ignore:
- main
- master
- docusaurus-version
paths-ignore:
- "ISSUE_TEMPLATE/**"
- ".github/**.md"
- ".gitignore"
- "demo/**"
- "docker/**"
- "HOW_TO.md"
- "TASK.md"
- "SECURITY.md"
- "README.md"
- "README_zh-CN.md"
# 添加workflow_dispatch,允许从其他工作流触发
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to test'
required: true
type: string
ref:
description: 'Branch or commit to test'
required: true
type: string
trigger_source:
description: 'What triggered this test'
required: false
type: string
default: 'manual'
env:
NODE_OPTIONS: --max_old_space_size=20480
jobs:
test-deploy:
name: Test deployment
runs-on: ubuntu-latest
steps:
- name: Get PR info (for workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
id: pr-info
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const pr_number = '${{ inputs.pr_number }}';
try {
const { data: pr } = await github.rest.pulls.get({
owner,
repo,
pull_number: parseInt(pr_number)
});
core.setOutput('sha', pr.head.sha);
core.setOutput('ref', pr.head.ref);
console.log(`PR #${pr_number}: branch=${pr.head.ref}, sha=${pr.head.sha}`);
} catch (error) {
console.error('Failed to get PR info:', error);
core.setOutput('sha', '${{ inputs.ref }}');
core.setOutput('ref', '${{ inputs.ref }}');
}
- uses: actions/checkout@v3
with:
ref: ${{ steps.pr-info.outputs.ref || github.ref }}
- uses: actions/setup-node@v3
with:
node-version: 20
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Test build website
run: yarn docusaurus build
# 报告状态到PR(不添加评论)
- name: Report status to PR
if: always()
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const success = '${{ job.status }}' === 'success';
// 获取正确的SHA和context
let sha, statusContext;
if ('${{ github.event_name }}' === 'workflow_dispatch') {
sha = '${{ steps.pr-info.outputs.sha }}';
const triggerSource = '${{ inputs.trigger_source }}';
if (triggerSource === 'translation') {
statusContext = 'Test deployment (post-translation)';
} else if (triggerSource === 'rollback') {
statusContext = 'Test deployment (post-rollback)';
} else {
statusContext = 'Test deployment (manual)';
}
} else {
sha = context.sha;
statusContext = 'Test deployment';
}
try {
// 创建commit status(只显示在PR的checks中,不添加评论)
await github.rest.repos.createCommitStatus({
owner,
repo,
sha: sha,
state: success ? 'success' : 'failure',
target_url: `https://github.com/${owner}/${repo}/actions/runs/${{ github.run_id }}`,
description: success ? '✅ Build succeeded' : '❌ Build failed',
context: statusContext
});
console.log(`Status reported: ${statusContext} - ${success ? 'success' : 'failure'}`);
} catch (error) {
console.error('Failed to report status:', error.message);
}