55 branches : [ main, develop ]
66 pull_request :
77 branches : [ main ]
8- schedule :
9- - cron : ' 0 2 * * *' # 每天凌晨2点运行
8+ workflow_dispatch : # 允许手动触发
109
1110jobs :
1211 build-and-test :
1312 runs-on : ubuntu-latest
13+ timeout-minutes : 10
1414
1515 steps :
1616 - name : Checkout code
2121 with :
2222 java-version : ' 11'
2323 distribution : ' temurin'
24- cache : maven
24+ cache : ' maven'
2525
2626 - name : Cache Maven dependencies
2727 uses : actions/cache@v3
@@ -31,60 +31,35 @@ jobs:
3131 restore-keys : |
3232 ${{ runner.os }}-maven-
3333
34+ - name : Validate Maven wrapper
35+ run : |
36+ echo "检查Maven Wrapper..."
37+ ls -la mvnw
38+ chmod +x mvnw
39+
3440 - name : Build with Maven
3541 run : ./mvnw clean compile -DskipTests
3642
3743 - name : Run tests
38- run : ./mvnw test
44+ run : ./mvnw test -DskipTests=false
3945 env :
40- OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
46+ OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY || 'dummy-key-for-ci' }}
4147
42- - name : Run integration tests
43- run : ./mvnw verify -DskipITs=false
44- if : github.event_name == 'push' && github.ref == 'refs/heads/main'
45- continue-on-error : true
46-
47- - name : Code coverage
48- uses : codecov/codecov-action@v3
49- with :
50- file : ./target/site/jacoco/jacoco.xml
51- fail_ci_if_error : false
52- continue-on-error : true
48+ - name : Package application
49+ run : ./mvnw clean package -DskipTests
5350
5451 - name : Upload build artifacts
5552 uses : actions/upload-artifact@v3
5653 with :
57- name : java-artifacts
54+ name : java-ai-starter-jar
5855 path : target/*.jar
59- if : github.event_name == 'push' && github.ref == 'refs/heads/main'
56+ if : success()
6057
58+ # 简化的质量检查(可选)
6159 quality-check :
6260 runs-on : ubuntu-latest
6361 needs : build-and-test
64-
65- steps :
66- - name : Checkout code
67- uses : actions/checkout@v3
68-
69- - name : SonarCloud Scan
70- uses : SonarSource/sonarcloud-github-action@master
71- env :
72- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
73- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
74-
75- - name : Checkstyle
76- run : ./mvnw checkstyle:check
77-
78- - name : PMD analysis
79- run : ./mvnw pmd:check
80-
81- - name : SpotBugs analysis
82- run : ./mvnw spotbugs:check
83-
84- deploy :
85- runs-on : ubuntu-latest
86- needs : [build-and-test, quality-check]
87- if : github.event_name == 'push' && github.ref == 'refs/heads/main'
62+ if : always()
8863
8964 steps :
9065 - name : Checkout code
@@ -96,61 +71,12 @@ jobs:
9671 java-version : ' 11'
9772 distribution : ' temurin'
9873
99- - name : Build package
100- run : ./mvnw clean package -DskipTests
101-
102- - name : Login to DockerHub
103- uses : docker/login-action@v2
104- with :
105- username : ${{ secrets.DOCKER_USERNAME }}
106- password : ${{ secrets.DOCKER_PASSWORD }}
107-
108- - name : Build and push Docker image
109- uses : docker/build-push-action@v4
110- with :
111- context : .
112- push : true
113- tags : |
114- intellidev/java-ai-starter:latest
115- intellidev/java-ai-starter:${{ github.sha }}
116-
117- - name : Deploy to staging
74+ - name : Check code style
11875 run : |
119- echo "Deploying to staging environment..."
120- # 这里添加你的部署脚本
121- # 例如:kubectl apply -f k8s/
122- env :
123- KUBECONFIG : ${{ secrets.KUBECONFIG_STAGING }}
76+ echo "代码风格检查(占位符)"
77+ echo "可以通过添加Checkstyle或Spotless插件来增强"
12478
125- - name : Run smoke tests
79+ - name : Dependency check
12680 run : |
127- echo "Running smoke tests..."
128- # 这里添加冒烟测试脚本
129-
130- - name : Deploy to production
131- if : success()
132- run : |
133- echo "Deploying to production..."
134- # 这里添加生产环境部署脚本
135- env :
136- KUBECONFIG : ${{ secrets.KUBECONFIG_PRODUCTION }}
137-
138- documentation :
139- runs-on : ubuntu-latest
140-
141- steps :
142- - name : Checkout code
143- uses : actions/checkout@v3
144-
145- - name : Generate API documentation
146- run : ./mvnw javadoc:javadoc
147- continue-on-error : true
148-
149- - name : Deploy to GitHub Pages
150- uses : peaceiris/actions-gh-pages@v3
151- with :
152- github_token : ${{ secrets.GITHUB_TOKEN }}
153- publish_dir : ./target/site/apidocs
154- destination_dir : ./docs/api
155- if : github.event_name == 'push' && github.ref == 'refs/heads/main'
156- continue-on-error : true
81+ echo "依赖检查(占位符)"
82+ echo "可以添加OWASP Dependency-Check"
0 commit comments