83 lines
2.9 KiB
YAML
83 lines
2.9 KiB
YAML
name: DevStar E2E Test
|
||
on:
|
||
pull_request:
|
||
types: [opened, synchronize]
|
||
permissions:
|
||
contents: read
|
||
pull-requests: write
|
||
jobs:
|
||
e2e-test:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Check out repository code
|
||
uses: actions/checkout@v4
|
||
- name: build Devstar Image
|
||
run: |
|
||
make devstar
|
||
- name: Install Network Tools
|
||
run: |
|
||
echo "正在安装 ip 命令..."
|
||
sudo apt-get update && sudo apt-get install -y iproute2
|
||
- name: start DevStar Container
|
||
run: |
|
||
# 启动容器,这里的话需要预先的创建宿主机的对应文件夹
|
||
LOGS=$(public/assets/install.sh start \
|
||
--port=8082 \
|
||
--ssh-port=2224 \
|
||
--data-dir=/tmp/devstar_ci \
|
||
--image=devstar-studio:latest 2>&1)
|
||
echo "$LOGS"
|
||
TARGET_URL=$(echo "$LOGS" | grep -o 'http://[^ ]*' | tail -1 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g")
|
||
echo "TARGET_URL=$TARGET_URL" >> $GITHUB_ENV
|
||
- name: Run E2E Tests
|
||
run: |
|
||
make e2e-test TARGET_URL="$TARGET_URL"
|
||
env:
|
||
GITEA_I_AM_BEING_UNSAFE_RUNNING_AS_ROOT: "true"
|
||
- name: Upload E2E Test Report
|
||
if: always()
|
||
uses: actions/upload-artifact@v3
|
||
with:
|
||
name: e2e-test-report
|
||
path: tests/e2e/reports/
|
||
- name: Post Test Results
|
||
if: always() && github.event_name == 'pull_request'
|
||
uses: actions/github-script@v6
|
||
env:
|
||
# 传入任务状态,success 或 failure
|
||
TEST_RESULT: ${{ job.status }}
|
||
with:
|
||
script: |
|
||
const testResult = process.env.TEST_RESULT || '未知';
|
||
const isSuccess = testResult === 'success';
|
||
|
||
// 动态生成构建链接
|
||
const runUrl = `${context.payload.repository.html_url}/actions/runs/${context.runId}`;
|
||
|
||
const comment = `
|
||
## 📋 E2E 测试结果报告
|
||
|
||
### 测试状态
|
||
${isSuccess ? '✅ **通过 (Passed)**' : '❌ **失败 (Failed)**'}
|
||
|
||
### 🔍 详细报告
|
||
HTML 报告已上传至 Artifacts,请点击下方链接查看。
|
||
👉 [查看运行日志与下载报告](${runUrl})
|
||
|
||
### 🏗️ 构建信息
|
||
- **工作流**: ${context.workflow}
|
||
- **提交**: ${context.payload.pull_request.head.sha.slice(0, 7)}
|
||
- **触发者**: @${context.actor}
|
||
|
||
---
|
||
> *此评论由 DevStar Actions 自动生成,用于 PR 质量检查。*
|
||
`;
|
||
|
||
// 发送评论
|
||
github.rest.issues.createComment({
|
||
issue_number: context.issue.number,
|
||
owner: context.repo.owner,
|
||
repo: context.repo.repo,
|
||
body: comment
|
||
});
|