Skip to content

Commit b441c78

Browse files
authored
Merge pull request #486 from Marcono1234/github-workflow
Simplify GitHub workflow, cache local Maven repository
2 parents 37777cd + 238c690 commit b441c78

File tree

1 file changed

+52
-29
lines changed

1 file changed

+52
-29
lines changed

.github/workflows/default-tests.yml

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@ on: [push, pull_request]
44

55
jobs:
66
checkstyle:
7-
name: Run checkstyle with java ${{ matrix.java_version }}
7+
name: Run checkstyle
88
runs-on: ubuntu-latest
99
if: github.event_name == 'pull_request'
10-
strategy:
11-
matrix:
12-
java_version: ['8']
1310
steps:
1411
- uses: actions/checkout@v1
15-
- name: Set up JDK ${{ matrix.java_version }}
12+
- name: Set up JDK 8
1613
uses: actions/setup-java@v1
1714
with:
18-
java-version: ${{ matrix.java_version }}
15+
java-version: 8
16+
- name: Cache local Maven repository
17+
uses: actions/cache@v1
18+
with:
19+
path: ~/.m2
20+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
21+
restore-keys: ${{ runner.os }}-m2
1922
- name: Run checkstyle with Maven
20-
run: mvn --file pom.xml clean verify -Pcheckstyle -Dmaven.test.skip=true -B
23+
run: mvn clean verify -B -Pcheckstyle -Dmaven.test.skip=true
2124

2225
test:
23-
name: Run basic test with java ${{ matrix.java_version }}
26+
name: Run basic test with Java ${{ matrix.java_version }}
2427
runs-on: ubuntu-latest
2528
needs: checkstyle
2629
if: github.event_name == 'pull_request'
@@ -34,11 +37,17 @@ jobs:
3437
uses: actions/setup-java@v1
3538
with:
3639
java-version: ${{ matrix.java_version }}
40+
- name: Cache local Maven repository
41+
uses: actions/cache@v1
42+
with:
43+
path: ~/.m2
44+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
45+
restore-keys: ${{ runner.os }}-m2
3746
- name: Build with Maven
38-
run: mvn -B package --file pom.xml
47+
run: mvn clean verify -B
3948

4049
integration-test:
41-
name: Run integration test with java ${{ matrix.java_version }} and Maven ${{ matrix.maven_version }}
50+
name: Run integration test with Java ${{ matrix.java_version }} and Maven ${{ matrix.maven_version }}
4251
runs-on: ubuntu-latest
4352
needs: checkstyle
4453
if: github.event_name == 'pull_request'
@@ -55,7 +64,7 @@ jobs:
5564
java-version: ${{ matrix.java_version }}
5665
- name: Setup Maven ${{ matrix.maven_version }}
5766
run: /bin/bash -c 'if [[ -n "${{ matrix.maven_version }}" ]]; then \
58-
echo "Download Maven ${{ matrix.maven_version }}....";
67+
echo "Downloading Maven ${{ matrix.maven_version }}....";
5968
if [[ "${{ matrix.maven_version }}" == "3.0" ]]; then
6069
wget https://archive.apache.org/dist/maven/binaries/apache-maven-3.0-bin.zip || terminate 1;
6170
else
@@ -66,12 +75,19 @@ jobs:
6675
export PATH=$M2_HOME/bin:$PATH;
6776
mvn -version;
6877
fi'
69-
- name: Package with Maven
70-
run: mvn clean package -B
78+
- name: Cache local Maven repository
79+
uses: actions/cache@v1
80+
with:
81+
path: ~/.m2
82+
# Include Maven version in key to not use cache from other Maven versions
83+
# in case they corrupt the local repository
84+
# Include it before `-m2-` to prevent other cache actions' restore-keys matching it
85+
key: ${{ runner.os }}-maven-${{ matrix.maven_version }}-m2-${{ hashFiles('**/pom.xml') }}
86+
restore-keys: ${{ runner.os }}-maven-${{ matrix.maven_version }}-m2
7187
- name: Install a test version with Maven
72-
run: mvn clean test install -B
88+
run: mvn clean install -B
7389
- name: Run the local testversion with Maven
74-
run: mvn clean initialize -Pdemo -Dmaven.test.skip=true -B
90+
run: mvn clean initialize -B -Pdemo -Dmaven.test.skip=true
7591
- name: Validate if the testversion has produced the desired output
7692
run: /bin/bash -c '[[ -f maven/target/testing.properties ]] && cat maven/target/testing.properties || exit 1;'
7793

@@ -88,29 +104,36 @@ jobs:
88104
steps:
89105
- uses: actions/checkout@v1
90106
- run: git checkout "${GITHUB_REF:11}"
91-
- name: Set up JDK ${{ matrix.java_version }}
107+
- name: Set up JDK 8
92108
uses: actions/setup-java@v1
93109
with:
94-
java-version: ${{ matrix.java_version }}
95-
- name: Run Coveralls with maven
96-
run: mvn clean test jacoco:report coveralls:report -Pcoveralls -DrepoToken=${{ secrets.CoverallsRepoTokenSecret }} -B
110+
java-version: 8
111+
- name: Cache local Maven repository
112+
uses: actions/cache@v1
113+
with:
114+
path: ~/.m2
115+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
116+
restore-keys: ${{ runner.os }}-m2
117+
- name: Run Coveralls with Maven
118+
run: mvn clean test jacoco:report coveralls:report -B -Pcoveralls -DrepoToken=${{ secrets.CoverallsRepoTokenSecret }}
97119

98120
deploy-snapshot:
99-
name: Run coveralls with java ${{ matrix.java_version }}
121+
name: Deploy snapshot
100122
runs-on: ubuntu-latest
101123
needs: integration-test
102124
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master')
103125

104-
strategy:
105-
matrix:
106-
java_version: ['8']
107-
108126
steps:
109127
- uses: actions/checkout@v1
110-
- name: Set up JDK ${{ matrix.java_version }}
128+
- name: Set up JDK 8
111129
uses: actions/setup-java@v1
112130
with:
113-
java-version: ${{ matrix.java_version }}
114-
- name: Deploy snapshot with maven
115-
run: mvn clean deploy --settings=./.buildscript/settings.xml
116-
131+
java-version: 8
132+
- name: Cache local Maven repository
133+
uses: actions/cache@v1
134+
with:
135+
path: ~/.m2
136+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
137+
restore-keys: ${{ runner.os }}-m2
138+
- name: Deploy snapshot with Maven
139+
run: mvn clean deploy -B --settings=./.buildscript/settings.xml

0 commit comments

Comments
 (0)