Add CI cache (#1914)

* Add cache for all steps
* Pass through the maven.repo.loca.tail property
This commit is contained in:
Guillaume Nodet 2024-11-17 15:50:32 +01:00 committed by GitHub
parent ab7d766c72
commit 12b3dae3ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 60 additions and 8 deletions

View File

@ -45,9 +45,10 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.m2/repository/cached
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: maven-
enableCrossOsArchive: true
key: maven-${{ runner.os }}-initial-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-${{ runner.os }}-initial-
maven-${{ runner.os }}-
- name: Set up Maven
shell: bash
@ -55,7 +56,7 @@ jobs:
- name: Build Maven distributions
shell: bash
run: ./mvnw verify -e -B -V -DdistributionFileName=apache-maven
run: ./mvnw verify -e -B -V -DdistributionFileName=apache-maven -Dmaven.repo.local=$HOME/.m2/repository/cached
- name: List contents of target directory
shell: bash
@ -123,9 +124,18 @@ jobs:
echo "MAVEN_HOME=$PWD/maven-local" >> $GITHUB_ENV
echo "$PWD/maven-local/bin" >> $GITHUB_PATH
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2/repository/cached
key: maven-${{ runner.os }}-full-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-${{ runner.os }}-full-
maven-${{ runner.os }}-
- name: Build site with downloaded Maven
shell: bash
run: mvn verify site -e -B -V -DdistributionFileName=apache-maven -Preporting
run: mvn verify site -e -B -V -Preporting -Dmaven.repo.local=$HOME/.m2/repository/cached
integration-tests:
needs: initial-build
@ -174,9 +184,18 @@ jobs:
echo "MAVEN_HOME=$PWD/maven-local" >> $GITHUB_ENV
echo "$PWD/maven-local/bin" >> $GITHUB_PATH
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2/repository/cached
key: maven-${{ runner.os }}-its-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-${{ runner.os }}-its
maven-${{ runner.os }}-
- name: Run integration tests
shell: bash
run: mvn install -e -B -V -Prun-its,embedded
run: mvn install -e -B -V -Prun-its,embedded -Dmaven.repo.local=$HOME/.m2/repository/local -Dmaven.repo.local.tail=$HOME/.m2/repository/cached
- name: Upload test artifacts
uses: actions/upload-artifact@v4

View File

@ -633,6 +633,28 @@ under the License.
</plugins>
</build>
</profile>
<profile>
<id>maven-repo-local-tail</id>
<activation>
<property>
<name>maven.repo.local.tail</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<!-- Pass this through to the tests (if set!) to have them
pick the right repository -->
<maven.repo.local.tail>${maven.repo.local.tail}</maven.repo.local.tail>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>maven-repo-local-layout</id>
<activation>

View File

@ -48,6 +48,7 @@ public class MavenITmng8181CentralRepoTest extends AbstractMavenIntegrationTestC
verifier.addCliArgument("--install-settings=install-settings.xml");
verifier.addCliArgument("--settings=settings.xml");
verifier.addCliArgument("-Dmaven.repo.local=" + testDir.toPath().resolve("target/local-repo"));
verifier.addCliArgument("-Dmaven.repo.local.tail=target/null");
verifier.addCliArgument("-Dmaven.repo.central=http://repo1.maven.org/");
verifier.addCliArgument("validate");
assertThrows(VerificationException.class, verifier::execute);

View File

@ -29,11 +29,17 @@ import org.apache.maven.shared.verifier.VerificationException;
public class Verifier extends org.apache.maven.shared.verifier.Verifier {
public Verifier(String basedir) throws VerificationException {
super(basedir);
this(basedir, false);
}
public Verifier(String basedir, boolean debug) throws VerificationException {
super(basedir, debug);
super(basedir, null, debug, defaultCliArguments());
}
static String[] defaultCliArguments() {
return new String[] {
"-e", "--batch-mode", "-Dmaven.repo.local.tail=" + System.getProperty("maven.repo.local.tail")
};
}
public String loadLogContent() throws IOException {
@ -95,4 +101,8 @@ public class Verifier extends org.apache.maven.shared.verifier.Verifier {
public static long textOccurencesInLog(List<String> lines, String text) {
return lines.stream().filter(line -> stripAnsi(line).contains(text)).count();
}
public void execute() throws VerificationException {
super.execute();
}
}