-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-update-project-versions.yml
More file actions
161 lines (142 loc) · 6.11 KB
/
test-update-project-versions.yml
File metadata and controls
161 lines (142 loc) · 6.11 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
159
160
161
name: Test - Update Project Versions
on:
push:
paths:
- '.github/actions/update-project-versions/**'
- '.github/workflows/test-update-project-versions.yml'
pull_request:
paths:
- '.github/actions/update-project-versions/**'
- '.github/workflows/test-update-project-versions.yml'
jobs:
# ── Unit tests ─────────────────────────────────────────────────────────────
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: .github/actions/update-project-versions
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: .github/actions/update-project-versions/package.json
- name: Install dependencies
run: npm install
- name: Run unit tests
run: npm test
# ── Integration test ────────────────────────────────────────────────────────
# Creates a small Maven project in a temp directory and verifies the action
# updates pom.xml versions as expected.
integration-test:
name: Integration Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create test Maven project
run: |
mkdir -p /tmp/test-project/child-module
# Root pom.xml
cat > /tmp/test-project/pom.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config</artifactId>
<version>4.1.0</version>
<packaging>pom</packaging>
<modules>
<module>child-module</module>
</modules>
<properties>
<spring-boot.version>3.2.2</spring-boot.version>
<spring-cloud-commons.version>4.1.0</spring-cloud-commons.version>
</properties>
</project>
EOF
# Child module pom.xml
cat > /tmp/test-project/child-module/pom.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config</artifactId>
<version>4.1.0</version>
</parent>
<artifactId>spring-cloud-config-server</artifactId>
</project>
EOF
- name: Run update-project-versions action
uses: ./.github/actions/update-project-versions
with:
versions: '{"spring-boot":"3.2.3","spring-cloud-commons":"4.1.1"}'
project-version: '4.1.2'
directory: '/tmp/test-project'
- name: Verify root pom project version was updated
run: |
VERSION=$(grep -o '<version>[^<]*</version>' /tmp/test-project/pom.xml | head -1 | sed 's/<[^>]*>//g')
echo "Root pom version: $VERSION"
if [[ "$VERSION" != "4.1.2" ]]; then
echo "❌ Expected root pom version 4.1.2, got: $VERSION"
exit 1
fi
echo "✅ Root pom version updated to 4.1.2"
- name: Verify spring-boot.version property was updated
run: |
VALUE=$(grep -o '<spring-boot.version>[^<]*</spring-boot.version>' /tmp/test-project/pom.xml | sed 's/<[^>]*>//g')
echo "spring-boot.version: $VALUE"
if [[ "$VALUE" != "3.2.3" ]]; then
echo "❌ Expected spring-boot.version 3.2.3, got: $VALUE"
exit 1
fi
echo "✅ spring-boot.version updated to 3.2.3"
- name: Verify spring-cloud-commons.version property was updated
run: |
VALUE=$(grep -o '<spring-cloud-commons.version>[^<]*</spring-cloud-commons.version>' /tmp/test-project/pom.xml | sed 's/<[^>]*>//g')
echo "spring-cloud-commons.version: $VALUE"
if [[ "$VALUE" != "4.1.1" ]]; then
echo "❌ Expected spring-cloud-commons.version 4.1.1, got: $VALUE"
exit 1
fi
echo "✅ spring-cloud-commons.version updated to 4.1.1"
- name: Verify child module parent version was updated
run: |
PARENT_VERSION=$(grep -A5 '<parent>' /tmp/test-project/child-module/pom.xml | grep -o '<version>[^<]*</version>' | sed 's/<[^>]*>//g')
echo "Child module parent version: $PARENT_VERSION"
if [[ "$PARENT_VERSION" != "4.1.2" ]]; then
echo "❌ Expected child module parent version 4.1.2, got: $PARENT_VERSION"
exit 1
fi
echo "✅ Child module parent version updated to 4.1.2"
# ── Dist is up to date ──────────────────────────────────────────────────────
# Ensures dist/index.js reflects the current source so nobody forgets to
# run `npm run build` before committing.
dist-up-to-date:
name: Verify dist is up to date
runs-on: ubuntu-latest
defaults:
run:
working-directory: .github/actions/update-project-versions
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: .github/actions/update-project-versions/package.json
- name: Install dependencies
run: npm install
- name: Rebuild dist
run: npm run build
- name: Fail if dist/index.js has uncommitted changes
run: |
if git diff --quiet dist/index.js; then
echo "✅ dist/index.js is up to date"
else
echo "❌ dist/index.js is out of date — run 'npm run build' and commit the result"
git diff dist/index.js
exit 1
fi