Skip to content

Commit

Permalink
♻️ [CI] Added a common action to perform maven cache setup
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <[email protected]>
  • Loading branch information
Coduz committed Jan 23, 2025
1 parent 3deba26 commit 944202b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 48 deletions.
18 changes: 2 additions & 16 deletions .github/actions/runTestsTaggedAs/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,8 @@ runs:
- name: Set up runner
uses: ./.github/actions/setUpRunner

- name: Cache Maven repository - External dependencies # Cache of external Maven dependencies built from 'build' job
uses: actions/cache@v4
with:
path: ~/.m2/repository/
key: ${{ runner.os }}-maven-develop-dependencies

- name: Cache Maven repository - Kapua artifacts # Cache of Kapua artifacts built from 'build' job
uses: actions/cache@v4
with:
path: ~/.m2/kapua-repository/org/eclipse/kapua
key: ${{ runner.os }}-maven-${{ github.run_number }}-kapua-artifacts
fail-on-cache-miss: true

- name: Build full cached Maven repository # This adds the built Kapua artifact of this run to the cached repository of external dependencies
run: mv ~/.m2/kapua-repository/org/eclipse/kapua ~/.m2/repository/org/eclipse/kapua
shell: bash
- name: Set up Maven caches
uses: ./.github/actions/setUpMavenCaches

- name: Docker images creation
if: ${{ inputs.needs-docker-images == 'true' }}
Expand Down
29 changes: 29 additions & 0 deletions .github/actions/setUpMavenCaches/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Set Up Maven caches'
description: |
Set up maven caches to speedup build time and reuse built artifacts
inputs:
kapua-artifact-cache-enabled:
description: Whether to enable Kapua artifacts cache or not. If not enable you'll be required to build Kapua Artifacts on the runner
default: 'true'
runs:
using: "composite"
steps:
- name: Cache Maven repository - External dependencies # Cache of external Maven dependencies to speed up build time
id: cache-maven-external-deps
uses: actions/cache@v4
with:
path: ~/.m2/repository/
key: ${{ runner.os }}-maven-develop-dependencies

- name: Cache Maven repository - Kapua artifacts # Cache of built Kapua artifacts be reused in other jobs
if: ${{ inputs.kapua-artifact-cache-enabled == 'true' }}
id: cache-maven-kapua-artifacts
uses: actions/cache@v4
with:
path: ~/.m2/kapua-repository/org/eclipse/kapua
key: ${{ runner.os }}-maven-${{ github.run_number }}-kapua-artifacts

- name: Build full cached Maven repository # This adds the built Kapua artifact of this run to the cached repository of external dependencies. Used when re-running a job
if: ${{ inputs.kapua-artifact-cache-enabled == 'true' && steps.cache-maven-kapua-artifacts.outputs.cache-hit == 'true' }}
run: mv ~/.m2/kapua-repository/org/eclipse/kapua ~/.m2/repository/org/eclipse/kapua
shell: bash
28 changes: 6 additions & 22 deletions .github/workflows/kapua-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,8 @@ jobs:
- name: Set up runner
uses: ./.github/actions/setUpRunner

- name: Cache Maven repository - External dependencies # Cache of external Maven dependencies to speed up build time
id: cache-maven-external-deps
uses: actions/cache@v4
with:
path: ~/.m2/repository/
key: ${{ runner.os }}-maven-develop-dependencies

- name: Cache Maven repository - Kapua artifacts # Cache of Kapua artifacts be reused in following jobs
id: cache-maven-kapua-artifacts
uses: actions/cache@v4
with:
path: ~/.m2/kapua-repository/org/eclipse/kapua
key: ${{ runner.os }}-maven-${{ github.run_number }}-kapua-artifacts

- name: Build full cached Maven repository # This adds the built Kapua artifact of this run to the cached repository of external dependencies. Used when re-running a job
if: steps.cache-maven-kapua-artifacts.outputs.cache-hit == 'true'
run: mv ~/.m2/kapua-repository/org/eclipse/kapua ~/.m2/repository/org/eclipse/kapua
- name: Set up Maven caches
uses: ./.github/actions/setUpMavenCaches

- name: Maven version
run: mvn --version
Expand Down Expand Up @@ -361,15 +346,14 @@ jobs:
steps:
- name: Checkout repository # Checks out a copy of the repository on the runner
uses: actions/checkout@v4

- name: Set up runner
uses: ./.github/actions/setUpRunner

- name: Cache Maven repository - External dependencies # Cache of external Maven dependencies to speed up build time
id: cache-maven-external-deps
uses: actions/cache@v4
- name: Set up Maven caches
uses: ./.github/actions/setUpMavenCaches
with:
path: ~/.m2/repository/
key: ${{ runner.os }}-maven-develop-dependencies
kapua-artifact-cache-enabled: 'false'

- name: Build Kapua Javadoc
run: mvn -B -DskipTests install javadoc:jar
8 changes: 3 additions & 5 deletions .github/workflows/security-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ jobs:
- name: Set up runner
uses: ./.github/actions/setUpRunner

- name: Cache Maven repository - External dependencies # Cache of external Maven dependencies to speed up build time
id: cache-maven-external-deps
uses: actions/cache@v4
- name: Set up Maven caches
uses: ./.github/actions/setUpMavenCaches
with:
path: ~/.m2/repository/
key: ${{ runner.os }}-maven-develop-dependencies
kapua-artifact-cache-enabled: 'false'

- name: Run Owasp Security Scan
run: mvn -B ${BUILD_OPTS} -DskipTests -Psecurity-scan verify
8 changes: 3 additions & 5 deletions .github/workflows/sonarCloud-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ jobs:
- name: Set up runner
uses: ./.github/actions/setUpRunner

- name: Cache Maven repository - External dependencies # Cache of external Maven dependencies to speed up build time
id: cache-maven-external-deps
uses: actions/cache@v4
- name: Set up Maven caches
uses: ./.github/actions/setUpMavenCaches
with:
path: ~/.m2/repository/
key: ${{ runner.os }}-maven-develop-dependencies
kapua-artifact-cache-enabled: 'false'

- name: Cache SonarQube packages
uses: actions/cache@v4
Expand Down

0 comments on commit 944202b

Please sign in to comment.