1
0
forked from jk_yinzy/cicd-test

69 lines
2.0 KiB
YAML
Raw Permalink Normal View History

2025-11-28 19:00:26 +08:00
kind: pipeline
type: docker
name: multi-lang-ci
trigger:
2025-12-05 05:41:57 -05:00
event:
- pull_request
branch:
- main
2025-11-28 19:00:26 +08:00
# 克隆策略:只拉最新 commit加速
clone:
2025-12-05 12:21:23 +08:00
depth: 0
2025-12-05 11:23:48 +08:00
image: drone/git:latest
pull: false
2025-11-28 19:00:26 +08:00
steps:
# 自动检测是否存在 Java (pom.xml)
- name: java-build
2025-12-05 10:31:50 +08:00
image: maven:3.9-eclipse-temurin
2025-12-05 10:58:02 +08:00
pull: false
environment:
MAVEN_OPTS: -Dmaven.repo.local=.m2/repository
2025-11-28 19:00:26 +08:00
commands:
2025-12-05 04:05:57 -05:00
# 先创建 .m2 目录
- mkdir -p ~/.m2
# 动态生成 settings.xml仅用于 CI
- |
cat > ~/.m2/settings.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Aliyun Maven</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
</settings>
EOF
- mvn clean verify
2025-11-28 19:00:26 +08:00
- if [ -f pom.xml ]; then mvn clean compile; fi
when:
event: [ push, pull_request ]
# 自动检测是否存在 Python (requirements.txt)
- name: python-test
2025-12-05 10:31:50 +08:00
image: python:3.12.0-slim
2025-12-05 10:58:02 +08:00
pull: false
2025-11-28 19:00:26 +08:00
commands:
# 临时设置 pip 源(仅本次会话)
- pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
- pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn
2025-11-28 19:00:26 +08:00
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- if [ -f test_example.py ]; then python -m pytest test_example.py -v; fi
when:
event: [ push, pull_request ]
# 最终报告(无论成功失败都运行)
- name: summary
image: alpine
2025-12-05 10:58:02 +08:00
pull: false
2025-11-28 19:00:26 +08:00
commands:
- echo "✅ CI completed at $(date)"
when:
status: [ success, failure ]