Skip to content

Commit 99e9928

Browse files
committed
Add cache to CI
1 parent b91b4ef commit 99e9928

File tree

3 files changed

+130
-134
lines changed

3 files changed

+130
-134
lines changed

.github/workflows/maven.yml

Lines changed: 129 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,63 +17,106 @@
1717

1818
name: Java CI
1919

20-
on: [push, pull_request, workflow_dispatch]
20+
on:
21+
push:
22+
branches: [ master ]
23+
pull_request:
24+
branches: [ master ]
2125

2226
# clear all permissions for GITHUB_TOKEN
2327
permissions: {}
2428

2529
jobs:
26-
build:
27-
28-
# execute on any push, workflow_dispatch or pull request from forked repo
29-
if: >
30-
github.event_name == 'push' ||
31-
github.event_name == 'workflow_dispatch' ||
32-
( github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork )
33-
34-
strategy:
35-
matrix:
36-
os: [ubuntu-latest, windows-latest, macOS-latest]
37-
fail-fast: false
38-
39-
runs-on: ${{ matrix.os }}
40-
30+
initial-build:
31+
runs-on: ubuntu-latest
4132
steps:
42-
- uses: actions/checkout@v4
33+
- name: Set up JDK
34+
uses: actions/setup-java@v4
4335
with:
36+
java-version: 17
37+
distribution: 'temurin'
38+
39+
- name: Checkout maven
40+
uses: actions/checkout@v4
41+
with:
42+
path: maven/
4443
persist-credentials: false
4544

46-
- uses: actions/setup-java@v4
45+
- name: Cache Maven packages
46+
uses: actions/cache@v4
4747
with:
48-
java-version: 17
49-
distribution: 'temurin'
50-
cache: 'maven'
48+
path: ~/.m2/repository/cached
49+
key: maven-${{ hashFiles('**/pom.xml') }}
50+
restore-keys: maven-
51+
enableCrossOsArchive: true
5152

5253
- name: Set up Maven
53-
run:
54-
mvn --errors --batch-mode --show-version org.apache.maven.plugins:maven-wrapper-plugin:3.3.2:wrapper "-Dmaven=3.9.7"
54+
shell: bash
55+
working-directory: maven
56+
run: mvn --errors --batch-mode --show-version org.apache.maven.plugins:maven-wrapper-plugin:3.3.2:wrapper "-Dmaven=4.0.0-beta-4"
5557

5658
- name: Build with Maven
59+
shell: bash
60+
working-directory: maven
5761
run: ./mvnw verify -e -B -V -DdistributionFileName=apache-maven
5862

5963
- name: Upload built Maven
6064
uses: actions/upload-artifact@v4
61-
if: ${{ matrix.os == 'ubuntu-latest' }}
6265
with:
6366
name: built-maven
64-
path: apache-maven/target/
67+
path: maven/apache-maven/target/
68+
69+
- name: Extract tarball
70+
shell: bash
71+
working-directory: maven
72+
run: |
73+
set +e
74+
if [ -f ${{ env.TAR_BALL }} ]; then
75+
temp_dir=$(mktemp -d)
76+
tar -xzf ${{ env.TAR_BALL }} -C "$temp_dir" --strip 1
77+
maven_bin_dir=$temp_dir/bin
78+
if [ -d $maven_bin_dir ]; then
79+
echo "tar.gz file \"${{ env.TAR_BALL }}\" successfully extracted in temporarily directory \"$temp_dir.\""
80+
echo "TEMP_MAVEN_BIN_DIR=$maven_bin_dir" >> $GITHUB_ENV
81+
else
82+
echo "$maven_bin_dir does not exist."
83+
exit 1;
84+
fi
85+
else
86+
echo "${{ env.TAR_BALL }} does not exist."
87+
exit 1;
88+
fi
89+
env:
90+
TAR_BALL: apache-maven/target/apache-maven-bin.tar.gz
91+
92+
- name: Build again with Maven SNAPSHOT
93+
shell: bash
94+
working-directory: maven
95+
run: |
96+
export PATH=${{ env.TEMP_MAVEN_BIN_DIR }}:$PATH
97+
mvn clean verify site -e -B -V -DdistributionFileName=apache-maven -Preporting
98+
6599
66-
integration-test:
67-
needs: build
100+
matrix-build:
101+
needs: initial-build
102+
runs-on: ${{ matrix.os }}
68103
strategy:
69104
matrix:
70-
os: [ubuntu-latest, windows-latest, macOS-latest]
71-
java: [17, 21]
105+
os: [ubuntu-latest, macos-latest, windows-latest]
106+
java: ['17', '21']
107+
steps:
108+
- name: Set up JDK ${{ matrix.java }}
109+
uses: actions/setup-java@v4
110+
with:
111+
java-version: ${{ matrix.java }}
112+
distribution: 'temurin'
72113

73-
fail-fast: false
74-
runs-on: ${{ matrix.os }}
114+
- name: Checkout maven
115+
uses: actions/checkout@v4
116+
with:
117+
path: maven/
118+
persist-credentials: false
75119

76-
steps:
77120
- name: Collect environment context variables
78121
shell: bash
79122
env:
@@ -113,32 +156,71 @@ jobs:
113156
ref: ${{ env.REPO_BRANCH }}
114157
persist-credentials: false
115158

116-
- name: Set up JDK
117-
uses: actions/setup-java@v4
159+
- name: Cache Maven packages
160+
uses: actions/cache@v4
118161
with:
119-
java-version: ${{ matrix.java }}
120-
distribution: 'temurin'
121-
# cache: 'maven' - don't use cache for integration tests
162+
path: ~/.m2/repository/cached
163+
key: maven-${{ hashFiles('**/pom.xml') }}
164+
restore-keys: maven-
165+
enableCrossOsArchive: true
166+
167+
- name: Set up Maven
168+
shell: bash
169+
working-directory: maven
170+
run: mvn --errors --batch-mode --show-version org.apache.maven.plugins:maven-wrapper-plugin:3.3.2:wrapper "-Dmaven=4.0.0-beta-4"
171+
172+
- name: Build with Maven
173+
shell: bash
174+
working-directory: maven
175+
run: ./mvnw verify -e -B -V -DdistributionFileName=apache-maven
122176

123-
- uses: actions/checkout@v4
177+
- name: Upload built Maven
178+
uses: actions/upload-artifact@v4
179+
if: ${{ inputs.upload-distribution }}
124180
with:
125-
path: maven/
126-
persist-credentials: false
181+
name: built-maven
182+
path: maven/apache-maven/target/
127183

128-
- name: Set up Maven
129-
run:
130-
mvn --errors --batch-mode --show-version org.apache.maven.plugins:maven-wrapper-plugin:3.3.2:wrapper "-Dmaven=3.9.7"
184+
- name: Extract tarball
185+
shell: bash
186+
working-directory: maven
187+
run: |
188+
set +e
189+
if [ -f ${{ env.TAR_BALL }} ]; then
190+
temp_dir=$(mktemp -d)
191+
tar -xzf ${{ env.TAR_BALL }} -C "$temp_dir" --strip 1
192+
maven_bin_dir=$temp_dir/bin
193+
if [ -d $maven_bin_dir ]; then
194+
echo "tar.gz file \"${{ env.TAR_BALL }}\" successfully extracted in temporarily directory \"$temp_dir.\""
195+
echo "TEMP_MAVEN_BIN_DIR=$maven_bin_dir" >> $GITHUB_ENV
196+
else
197+
echo "$maven_bin_dir does not exist."
198+
exit 1;
199+
fi
200+
else
201+
echo "${{ env.TAR_BALL }} does not exist."
202+
exit 1;
203+
fi
204+
env:
205+
TAR_BALL: apache-maven/target/apache-maven-bin.tar.gz
131206

132-
- name: Build Maven
133-
run: ./mvnw install -e -B -V -DdistributionFileName=apache-maven -DskipTests -f maven/pom.xml
207+
- name: Build again with Maven SNAPSHOT
208+
shell: bash
209+
working-directory: maven
210+
run: |
211+
export PATH=${{ env.TEMP_MAVEN_BIN_DIR }}:$PATH
212+
mvn clean verify site -e -B -V -DdistributionFileName=apache-maven -Preporting
134213
135214
- name: Running integration tests
136215
shell: bash
137-
run: ./mvnw install -e -B -V -Prun-its,embedded -DmavenDistro="$GITHUB_WORKSPACE/maven/apache-maven/target/apache-maven-bin.zip" -f maven-integration-testing/pom.xml
216+
working-directory: maven-integration-testing
217+
run: |
218+
export PATH=${{ env.TEMP_MAVEN_BIN_DIR }}:$PATH
219+
mvn install -e -B -V -Prun-its,embedded
138220
139221
- name: Upload artifact on integration testing
140222
uses: actions/upload-artifact@v4
141223
if: failure() && matrix.os != 'windows-latest'
142224
with:
143-
name: ${{ github.run_number }}-integration-test-artifact-${{ matrix.os }}-${{ matrix.java }}
225+
name: ${{ github.run_number }}-integration-test-artifact-${{ runner.os }}-${{ matrix.java }}
144226
path: ./maven-integration-testing/core-it-suite/target/test-classes/

.github/workflows/maven_build_itself.yml

Lines changed: 0 additions & 87 deletions
This file was deleted.

.mvn/maven.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aether.lrm.enhanced.split = true

0 commit comments

Comments
 (0)