-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (75 loc) · 3.09 KB
/
build_and_test_spring_boot.yml
File metadata and controls
84 lines (75 loc) · 3.09 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
# This workflow builds and tests the Spring Boot Shopping sample
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
name: Spring Boot Shopping sample
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "**" ]
workflow_dispatch: # Allow manual triggering
jobs:
detect-changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.changed.outputs.any_modified }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect changed files
id: changed
uses: tj-actions/changed-files@v46
with:
files: |
ams-spring-boot-shopping/pom.xml
ams-spring-boot-shopping/src/**
.github/workflows/build_and_test_spring_boot.yml
maven:
name: Build and Test${{ matrix.spring_boot_version && format(' (Spring Boot {0})', matrix.spring_boot_version) || '' }}
needs: detect-changes
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.should_run == 'true' }}
runs-on: ubuntu-latest
strategy:
matrix:
include:
- spring_boot_version: ''
- spring_boot_version: '4.0.2'
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
cache-dependency-path: ams-spring-boot-shopping/pom.xml
- name: Patch Spring Boot version in pom.xml
if: matrix.spring_boot_version
run: |
# Replace the parent version in pom.xml
sed -i.bak 's|<version>3\.5\.10</version><!-- spring-boot-starter-parent -->|<version>${{ matrix.spring_boot_version }}</version><!-- spring-boot-starter-parent -->|' pom.xml
# Also replace the spring.boot.version property
sed -i.bak 's|<spring.boot.version>3\.5\.10</spring.boot.version>|<spring.boot.version>${{ matrix.spring_boot_version }}</spring.boot.version>|' pom.xml
echo "Patched pom.xml for Spring Boot ${{ matrix.spring_boot_version }}"
cat pom.xml | head -30
working-directory: ams-spring-boot-shopping
- name: Build and Test
run: mvn clean test
working-directory: ams-spring-boot-shopping
# This job ensures the workflow passes when no relevant changes are detected
# Required for PR status checks to pass when the sample hasn't changed
no-changes:
name: Build and Test${{ matrix.spring_boot_version && format(' (Spring Boot {0})', matrix.spring_boot_version) || '' }}
needs: detect-changes
if: ${{ github.event_name != 'workflow_dispatch' && needs.detect-changes.outputs.should_run != 'true' }}
runs-on: ubuntu-latest
strategy:
matrix:
include:
- spring_boot_version: ''
- spring_boot_version: '4.0.2'
steps:
- name: No relevant changes detected
run: echo "No relevant changes detected for ams-spring-boot-shopping. Skipping build and test."