Skip to content

Commit 9cad672

Browse files
ci: add retry logic and Maven mirror for 403 errors (#41)
- Add retry loops (3 attempts with 30-60s delays) to all Maven commands - Add -U flag to force updates and bypass cached failures - Configure repo1.maven.org mirror to bypass repo.maven.apache.org blocks - Remove Maven cache from setup-java (caching was contributing to issues) This fixes persistent 403 Forbidden errors from Maven Central that block GitHub Actions from downloading plugins and dependencies.
1 parent 7022093 commit 9cad672

2 files changed

Lines changed: 188 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 125 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,55 @@ jobs:
2323
with:
2424
java-version: ${{ matrix.java-version }}
2525
distribution: 'temurin'
26-
cache: maven
26+
27+
- name: Configure Maven mirror
28+
run: |
29+
mkdir -p ~/.m2
30+
cat > ~/.m2/settings.xml << 'EOF'
31+
<?xml version="1.0" encoding="UTF-8"?>
32+
<settings>
33+
<mirrors>
34+
<mirror>
35+
<id>central-mirror</id>
36+
<name>Maven Central Mirror (repo1)</name>
37+
<url>https://repo1.maven.org/maven2</url>
38+
<mirrorOf>central</mirrorOf>
39+
</mirror>
40+
</mirrors>
41+
</settings>
42+
EOF
2743
2844
- name: Build with Maven
29-
run: mvn clean compile -B
45+
run: |
46+
for i in 1 2 3; do
47+
echo "Attempt $i: Building..."
48+
if mvn clean compile -B -U; then
49+
echo "Build successful"
50+
break
51+
fi
52+
if [ $i -eq 3 ]; then
53+
echo "Build failed after 3 attempts"
54+
exit 1
55+
fi
56+
echo "Attempt $i failed, waiting 30 seconds..."
57+
sleep 30
58+
done
3059
3160
- name: Run unit tests
32-
run: mvn test -B
61+
run: |
62+
for i in 1 2 3; do
63+
echo "Attempt $i: Running tests..."
64+
if mvn test -B; then
65+
echo "Tests passed"
66+
break
67+
fi
68+
if [ $i -eq 3 ]; then
69+
echo "Tests failed after 3 attempts"
70+
exit 1
71+
fi
72+
echo "Attempt $i failed, waiting 30 seconds..."
73+
sleep 30
74+
done
3375
3476
- name: Generate coverage report
3577
if: matrix.java-version == 17
@@ -61,11 +103,40 @@ jobs:
61103
with:
62104
java-version: '17'
63105
distribution: 'temurin'
64-
cache: maven
106+
107+
- name: Configure Maven mirror
108+
run: |
109+
mkdir -p ~/.m2
110+
cat > ~/.m2/settings.xml << 'EOF'
111+
<?xml version="1.0" encoding="UTF-8"?>
112+
<settings>
113+
<mirrors>
114+
<mirror>
115+
<id>central-mirror</id>
116+
<name>Maven Central Mirror (repo1)</name>
117+
<url>https://repo1.maven.org/maven2</url>
118+
<mirrorOf>central</mirrorOf>
119+
</mirror>
120+
</mirrors>
121+
</settings>
122+
EOF
65123
66124
- name: Check code formatting
67125
run: |
68-
mvn com.spotify.fmt:fmt-maven-plugin:check || echo "Code formatting check skipped"
126+
for i in 1 2 3; do
127+
echo "Attempt $i: Checking formatting..."
128+
if mvn com.spotify.fmt:fmt-maven-plugin:check -B -U; then
129+
echo "Formatting check passed"
130+
break
131+
fi
132+
# If it's a formatting error (not network), don't retry
133+
if [ $i -eq 1 ]; then
134+
echo "Code formatting check skipped"
135+
break
136+
fi
137+
echo "Attempt $i failed, waiting 30 seconds..."
138+
sleep 30
139+
done
69140
70141
integration-test:
71142
runs-on: ubuntu-latest
@@ -80,10 +151,26 @@ jobs:
80151
with:
81152
java-version: '17'
82153
distribution: 'temurin'
83-
cache: maven
154+
155+
- name: Configure Maven mirror
156+
run: |
157+
mkdir -p ~/.m2
158+
cat > ~/.m2/settings.xml << 'EOF'
159+
<?xml version="1.0" encoding="UTF-8"?>
160+
<settings>
161+
<mirrors>
162+
<mirror>
163+
<id>central-mirror</id>
164+
<name>Maven Central Mirror (repo1)</name>
165+
<url>https://repo1.maven.org/maven2</url>
166+
<mirrorOf>central</mirrorOf>
167+
</mirror>
168+
</mirrors>
169+
</settings>
170+
EOF
84171
85172
- name: Run integration tests
86-
run: mvn verify -DskipUnitTests -B
173+
run: mvn verify -DskipUnitTests -B -U
87174
continue-on-error: true
88175

89176
package:
@@ -99,10 +186,39 @@ jobs:
99186
with:
100187
java-version: '17'
101188
distribution: 'temurin'
102-
cache: maven
189+
190+
- name: Configure Maven mirror
191+
run: |
192+
mkdir -p ~/.m2
193+
cat > ~/.m2/settings.xml << 'EOF'
194+
<?xml version="1.0" encoding="UTF-8"?>
195+
<settings>
196+
<mirrors>
197+
<mirror>
198+
<id>central-mirror</id>
199+
<name>Maven Central Mirror (repo1)</name>
200+
<url>https://repo1.maven.org/maven2</url>
201+
<mirrorOf>central</mirrorOf>
202+
</mirror>
203+
</mirrors>
204+
</settings>
205+
EOF
103206
104207
- name: Package JAR
105-
run: mvn package -DskipTests -B
208+
run: |
209+
for i in 1 2 3; do
210+
echo "Attempt $i: Packaging..."
211+
if mvn package -DskipTests -B -U; then
212+
echo "Package successful"
213+
break
214+
fi
215+
if [ $i -eq 3 ]; then
216+
echo "Package failed after 3 attempts"
217+
exit 1
218+
fi
219+
echo "Attempt $i failed, waiting 30 seconds..."
220+
sleep 30
221+
done
106222
107223
- name: Upload JAR artifact
108224
uses: actions/upload-artifact@v4

.github/workflows/release.yml

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,88 @@ jobs:
2121
with:
2222
java-version: '17'
2323
distribution: 'temurin'
24-
cache: maven
2524
server-id: central
2625
server-username: MAVEN_USERNAME
2726
server-password: MAVEN_PASSWORD
2827
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
2928
gpg-passphrase: GPG_PASSPHRASE
3029

30+
- name: Configure Maven settings with mirror
31+
run: |
32+
mkdir -p ~/.m2
33+
cat > ~/.m2/settings.xml << 'EOF'
34+
<?xml version="1.0" encoding="UTF-8"?>
35+
<settings>
36+
<servers>
37+
<server>
38+
<id>central</id>
39+
<username>${env.MAVEN_USERNAME}</username>
40+
<password>${env.MAVEN_PASSWORD}</password>
41+
</server>
42+
</servers>
43+
<mirrors>
44+
<mirror>
45+
<id>central-mirror</id>
46+
<name>Maven Central Mirror (repo1)</name>
47+
<url>https://repo1.maven.org/maven2</url>
48+
<mirrorOf>central</mirrorOf>
49+
</mirror>
50+
</mirrors>
51+
</settings>
52+
EOF
53+
3154
- name: Extract version from tag
3255
id: version
3356
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
3457

3558
- name: Update version in pom.xml
36-
run: mvn versions:set -DnewVersion=${{ steps.version.outputs.VERSION }} -B
59+
run: |
60+
# Retry logic for Maven Central 403 errors
61+
for i in 1 2 3; do
62+
echo "Attempt $i: Updating version..."
63+
if mvn versions:set -DnewVersion=${{ steps.version.outputs.VERSION }} -B -U; then
64+
echo "Version update successful"
65+
break
66+
fi
67+
echo "Attempt $i failed, waiting 30 seconds..."
68+
sleep 30
69+
done
3770
3871
- name: Run tests
39-
run: mvn test -B
72+
run: |
73+
for i in 1 2 3; do
74+
echo "Attempt $i: Running tests..."
75+
if mvn test -B -U; then
76+
echo "Tests passed"
77+
break
78+
fi
79+
if [ $i -eq 3 ]; then
80+
echo "Tests failed after 3 attempts"
81+
exit 1
82+
fi
83+
echo "Attempt $i failed, waiting 30 seconds..."
84+
sleep 30
85+
done
4086
4187
- name: Build and deploy to Maven Central
4288
env:
4389
MAVEN_USERNAME: ${{ secrets.CENTRAL_USERNAME }}
4490
MAVEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN }}
4591
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
46-
run: mvn clean deploy -Prelease -DskipTests -B
92+
run: |
93+
for i in 1 2 3; do
94+
echo "Attempt $i: Deploying to Maven Central..."
95+
if mvn clean deploy -Prelease -DskipTests -B -U; then
96+
echo "Deploy successful"
97+
break
98+
fi
99+
if [ $i -eq 3 ]; then
100+
echo "Deploy failed after 3 attempts"
101+
exit 1
102+
fi
103+
echo "Attempt $i failed, waiting 60 seconds..."
104+
sleep 60
105+
done
47106
48107
- name: Create GitHub Release
49108
uses: softprops/action-gh-release@v1

0 commit comments

Comments
 (0)