From 7db0a6db150359391b33ee5372607f3b41286a2b Mon Sep 17 00:00:00 2001 From: Stefan Ranoszek Date: Fri, 13 Sep 2024 12:16:42 +0100 Subject: [PATCH 1/3] feat: maven cache --- .github/workflows/docker.yaml | 25 ++++++---------- .github/workflows/maven.yaml | 54 +++++++++++++++++++++++++++-------- run.sh | 12 -------- 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 2d2e5af7d..6f416770a 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -33,7 +33,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: hadolint/hadolint-action@v3.1.0 with: dockerfile: ${{ env.WORKING_DIR }}/Dockerfile @@ -45,30 +44,23 @@ jobs: - uses: actions/checkout@v4 - name: Cache Maven Dependencies - uses : actions/cache@v3 + uses: actions/cache@v3 with: path: ~/.m2 - key: ${{ runner.os }}-maven${{ hashFiles('**/pom.xml') }} + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | - ${{ runner.os }}-maven- + ${{ runner.os }}-maven- - - uses: whelk-io/maven-settings-xml-action@v22 - name: generate settings xml + - name: Download JAR artifact + uses: actions/download-artifact@v3 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 - run: cat ./settings.xml + name: test-jar - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Extract Docker metadata id: meta - uses: docker/metadata-action@v5 with: images: | @@ -104,12 +96,12 @@ 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 }} @@ -117,7 +109,6 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max - - name: Setup Notation CLI if: ${{ inputs.push }} diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml index 0bc7dc33d..af353b741 100644 --- a/.github/workflows/maven.yaml +++ b/.github/workflows/maven.yaml @@ -1,4 +1,4 @@ -name: Maven +name: Maven Build on: workflow_call: @@ -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}} - \ No newline at end of file + + - 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 \ No newline at end of file diff --git a/run.sh b/run.sh index 5fe37a7c1..227f4c3c4 100644 --- a/run.sh +++ b/run.sh @@ -21,7 +21,6 @@ # - noProxyJava # - mavenOptions -REBUILD_DEPENDENCIES=${REBUILD_DEPENDENCIES:-false} # check if all the environment variables are set check_environment_variables() { @@ -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} ] .." From 7b426b76bba8bfbbe5f4a5af2dcf2d1fe05e451e Mon Sep 17 00:00:00 2001 From: Stefan Ranoszek Date: Fri, 13 Sep 2024 12:31:46 +0100 Subject: [PATCH 2/3] chore: reintroduce welk --- .github/workflows/docker.yaml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 6f416770a..021882e98 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -43,19 +43,26 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Cache Maven Dependencies - uses: actions/cache@v3 - with: - path: ~/.m2 - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - name: Download JAR artifact uses: actions/download-artifact@v3 with: name: test-jar + - uses: whelk-io/maven-settings-xml-action@v22 + 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 + run: cat ./settings.xml + + + - name: Copy settings.xml for Docker build + run: cp ./settings.xml ${GITHUB_WORKSPACE}/${env.WORKING_DIR} + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -97,6 +104,7 @@ jobs: 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 From 1a40873d1e28b9a2f3ea1fef5b27b96cb6a2cd53 Mon Sep 17 00:00:00 2001 From: Stefan Ranoszek Date: Fri, 13 Sep 2024 12:36:05 +0100 Subject: [PATCH 3/3] chore: copy settings --- .github/workflows/docker.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 021882e98..1065690d6 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -59,9 +59,8 @@ jobs: - name: View settings.xml run: cat ./settings.xml - - - name: Copy settings.xml for Docker build - run: cp ./settings.xml ${GITHUB_WORKSPACE}/${env.WORKING_DIR} + - name: Copy settings.xml + run: cp ./settings.xml $GITHUB_WORKSPACE/$WORKING_DIR - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3