Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: maven cache #785

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: hadolint/[email protected]
with:
dockerfile: ${{ env.WORKING_DIR }}/Dockerfile
Expand All @@ -44,31 +43,30 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Cache Maven Dependencies
uses : actions/cache@v3
- name: Download JAR artifact
uses: actions/download-artifact@v3
with:
path: ~/.m2
key: ${{ runner.os }}-maven${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
name: test-jar

- uses: whelk-io/maven-settings-xml-action@v22
name: generate settings xml
name: Generate settings.xml
with:
servers: ${{ inputs.push && env.BATCH_SETTINGS || env.RUNNER_SETTINGS }}
proxies: '[{ "id":"dvsa-ci-proxy", "active": "true", "protocol": "http", "host": "${{vars.CI_PROXY}}", "port": "${{vars.CI_PROXYPORT}}" }]'
repositories: '[ { "id":"dvsa-github-packages", "name":"dvsa-github-packages", "url":"https://maven.pkg.github.com/dvsa/*", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]'
output_file: ./settings.xml
- name: view settings.xml

- name: View settings.xml
run: cat ./settings.xml

- name: Copy settings.xml
run: cp ./settings.xml $GITHUB_WORKSPACE/$WORKING_DIR

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract Docker metadata
id: meta

uses: docker/metadata-action@v5
with:
images: |
Expand Down Expand Up @@ -104,20 +102,20 @@ jobs:
if: ${{ inputs.push }}
run: |
aws ecr batch-delete-image --repository-name vol-qa/vft --image-ids imageTag=latest



- name: Build ${{ inputs.push && 'and push ' || '' }}Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
context: .
file: infra/docker/batch/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ inputs.push }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max


- name: Setup Notation CLI
if: ${{ inputs.push }}
Expand Down
54 changes: 42 additions & 12 deletions .github/workflows/maven.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Maven
name: Maven Build

on:
workflow_call:
Expand All @@ -8,20 +8,50 @@ on:
required: true
default: 'package'
type: string

permissions:
contents: read
packages: write

jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: whelk-io/maven-settings-xml-action@v22
with:
build:
name: Maven Build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'

- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Generate Maven settings.xml
uses: whelk-io/maven-settings-xml-action@v22
with:
servers: '[{ "id":"dvsa-github-packages", "configuration": { "httpHeaders": { "property": { "name":"Authorization", "value":"Bearer ${{ secrets.GITHUB_TOKEN }}"} } } },{ "id":"github-publish", "configuration": { "httpHeaders": { "property": { "name":"Authorization", "value":"Bearer ${{ secrets.GITHUB_TOKEN }}"} } } } ]'

- run: mvn -B -P github ${{ inputs.maven-goal}}


- name: Build with Maven
run: mvn -B -P github ${{ inputs.maven-goal }}

- name: Cache built JAR
uses: actions/cache@v3
with:
path: target/*.jar
key: ${{ runner.os }}-artifact-${{ hashFiles('**/pom.xml') }}

- name: Upload JAR Artifact
uses: actions/upload-artifact@v3
with:
name: test-jar
path: target/*.jar
12 changes: 0 additions & 12 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# - noProxyJava
# - mavenOptions

REBUILD_DEPENDENCIES=${REBUILD_DEPENDENCIES:-false}

# check if all the environment variables are set
check_environment_variables() {
Expand Down Expand Up @@ -54,17 +53,6 @@ check_environment_variables() {

check_environment_variables || exit 1

if [ "$REBUILD_DEPENDENCIES" = "true" ]; then
echo "Rebuilding Maven dependencies as requested."
mvn --batch-mode clean install -U
else
if [ -d ~/.m2/repository ]; then
echo "Using maven cached dependencies"
else
echo "No cache found, downloading dependencies"
mvn --batch-mode dependency:go-offline
fi
fi

# Echo the command to be captured in logs
echo "Now running [ mvn --batch-mode clean verify $mavenOptions -U -Dwdm.proxy=${proxyHost}:${proxyPort} -Dhttps.proxyHost=${proxyHost} -Dhttps.proxyPort=${proxyPort} -Dhttp.proxyHost=${proxyHost} -Dhttp.proxyPort=${proxyPort} -Dhttp.nonProxyHosts=${noProxyJava} -Denv=${platformEnv} -Dbrowser=${browserName} -DbrowserVersion=${browserVersion} -Dplatform=${platform} -DgridURL=_hidden_ -Dtag.name=\"(not ${exclude_tags})\" -Dcucumber.filter.tags=${cucumberTags} ] .."
Expand Down
Loading