forked from spring-projects/spring-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (144 loc) Β· 6.52 KB
/
main-push-fast.yml
File metadata and controls
158 lines (144 loc) Β· 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Main Push - Fast
run-name: ${{ github.event.inputs.commit_sha && format('Manual Test - {0}', github.event.inputs.commit_sha) || format('Fast Build - {0}', github.sha) }}
on:
push:
branches: ['main']
paths-ignore:
- 'spring-ai-docs/**'
- '*.md'
- 'docs/**'
- '.github/**'
workflow_dispatch:
inputs:
commit_sha:
description: 'Specific commit SHA to test (optional - defaults to latest)'
required: false
type: string
jobs:
fast-impacted:
name: Fast Build - Affected Modules
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'spring-projects' }}
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Always use full history for manual runs to find any commit
- name: Checkout specific commit
if: github.event.inputs.commit_sha
run: |
echo "Checking out specific commit: ${{ github.event.inputs.commit_sha }}"
# Save the latest main reference
LATEST_MAIN=$(git rev-parse origin/main)
# Checkout the target commit
git checkout ${{ github.event.inputs.commit_sha }}
# Preserve all latest GitHub Actions scripts from main
echo "Using latest GitHub Actions scripts from main..."
# Copy all scripts from main's .github/scripts directory (excluding __pycache__)
for script in $(git ls-tree -r --name-only ${LATEST_MAIN} .github/scripts/ | grep -v __pycache__); do
echo " Updating ${script}"
mkdir -p $(dirname ${script})
git show ${LATEST_MAIN}:${script} > ${script}
done
# Note: The workflow itself is already from main (since that's what's running)
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# cache: 'maven' # Disabled for fast workflow - reduces post-job noise
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Configure Testcontainers
run: |
echo "testcontainers.reuse.enable=true" > $HOME/.testcontainers.properties
- name: Show commit range
run: |
if [ -n "${{ github.event.inputs.commit_sha }}" ]; then
echo "π§ͺ MANUAL TEST RUN"
echo "Testing specific commit: ${{ github.event.inputs.commit_sha }}"
echo ""
echo "π Commit Details:"
git log --format=" Author: %an <%ae>%n Date: %ad%n Message: %s" -1 HEAD
echo ""
echo "π Changed Files:"
git diff --name-only HEAD~1..HEAD | head -10
if [ $(git diff --name-only HEAD~1..HEAD | wc -l) -gt 10 ]; then
echo " ... and $(( $(git diff --name-only HEAD~1..HEAD | wc -l) - 10 )) more files"
fi
else
echo "π AUTOMATIC BUILD"
echo "Testing latest commit on main branch"
echo ""
echo "π Commit Details:"
git log --format=" Author: %an <%ae>%n Date: %ad%n Message: %s" -1 HEAD
fi
- name: Compute impacted modules
id: mods
run: |
echo "=== Detecting affected modules ==="
echo "=== DEBUG: Changed files ==="
git diff --name-only HEAD~1..HEAD
echo "=== DEBUG: Running test discovery with full output ==="
MODULE_LIST=$(python3 .github/scripts/test_discovery.py modules-from-diff --verbose)
echo "=== DEBUG: Raw module list: '$MODULE_LIST' ==="
echo "modules=$MODULE_LIST" >> "$GITHUB_OUTPUT"
if [ -n "$MODULE_LIST" ]; then
echo "Affected modules detected: $MODULE_LIST"
# Only start Ollama if we're testing Ollama-specific modules
if echo "$MODULE_LIST" | grep -q "ollama"; then
echo "Ollama-related modules detected - Ollama service needed"
echo "needs_ollama=true" >> "$GITHUB_OUTPUT"
else
echo "Non-Ollama modules detected - Ollama service not needed"
echo "needs_ollama=false" >> "$GITHUB_OUTPUT"
fi
else
echo "No affected modules detected - only workflow/docs changes"
echo "needs_ollama=false" >> "$GITHUB_OUTPUT"
fi
- name: Start Ollama service for integration tests
if: steps.mods.outputs.needs_ollama == 'true'
run: |
echo "Starting Ollama for integration tests..."
docker run -d --name ollama-test -p 11434:11434 ollama/ollama:latest
echo "Ollama container started"
- name: Test affected modules with integration tests
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
SPRING_AI_OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
OLLAMA_AUTOCONF_TESTS_ENABLED: "true"
OLLAMA_WITH_REUSE: true
run: |
MODS="${{ steps.mods.outputs.modules }}"
if [ -z "$MODS" ]; then
echo "INFO: No affected modules detected - skipping build"
echo "Only workflow, documentation, or non-build files were changed"
echo "Fast workflow optimization: no compilation needed"
exit 0
else
echo "INFO: Running tests for affected modules: $MODS"
# Build dependencies without tests, then test only the affected modules
echo "INFO: Phase 1 - Building dependencies (this may take a few minutes)..."
./mvnw -B -q -T 1C -DskipTests -pl "$MODS" -am install
echo "INFO: Phase 2 - Running tests for affected modules..."
./mvnw -B -q -T 1C -Pci-fast-integration-tests -DfailIfNoTests=false -pl "$MODS" verify
echo "INFO: Testing complete"
fi
- name: Deploy to Artifactory (affected modules only)
if: steps.mods.outputs.modules != ''
env:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
run: |
MODS="${{ steps.mods.outputs.modules }}"
echo "INFO: Deploying affected modules to Artifactory: $MODS"
# Skip tests during deploy since we already ran them
./mvnw -B -q -s settings.xml -DskipTests -pl "$MODS" deploy