From d2def5c5de5a0bc907e0a63848264229073bd4b2 Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Thu, 7 Nov 2024 12:20:15 +0000 Subject: [PATCH] PI-2624 Prevent version from invalidating config cache --- .github/actions/analyse/action.yml | 2 +- .github/actions/get-build-info/action.yml | 4 +++- .github/actions/setup-gradle/action.yml | 12 ++++++++++++ .github/dependabot.yml | 5 +++++ .github/workflows/build.yml | 5 +++-- .../justice/digital/hmpps/plugins/JibConfigPlugin.kt | 4 ++-- 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.github/actions/analyse/action.yml b/.github/actions/analyse/action.yml index 8eb821695e..0681d2f29c 100644 --- a/.github/actions/analyse/action.yml +++ b/.github/actions/analyse/action.yml @@ -41,7 +41,7 @@ runs: shell: bash run: | version=$(date '+%Y-%m-%d').${{ github.run_number }}.$(echo ${{ github.sha }} | cut -c1-7) - echo "ORG_GRADLE_PROJECT_version=$version" | tee -a "$GITHUB_ENV" + echo "VERSION=$version" | tee -a "$GITHUB_ENV" echo "version=$version" | tee -a "$GITHUB_OUTPUT" - uses: ./.github/actions/setup-gradle diff --git a/.github/actions/get-build-info/action.yml b/.github/actions/get-build-info/action.yml index 85012c4674..de8bcf5f7f 100644 --- a/.github/actions/get-build-info/action.yml +++ b/.github/actions/get-build-info/action.yml @@ -28,13 +28,15 @@ runs: with: cache-encryption-key: ${{ inputs.gradle-encryption-key }} cache-read-only: true + remove-git-config: false - name: Get build info if: ${{ steps.gradle_file.outputs.files_exists == 'true' }} run: | echo '::group::Generate build info' ./gradlew ${{ inputs.project }}:buildInfo ${{ inputs.project }}:gitInfo + sed -i "s/build.version=.*/build.version=$VERSION/" projects/${{ inputs.project }}/build-info.properties echo '::endgroup::' shell: bash env: - ORG_GRADLE_PROJECT_version: ${{ inputs.version }} + VERSION: ${{ inputs.version }} diff --git a/.github/actions/setup-gradle/action.yml b/.github/actions/setup-gradle/action.yml index a1cad2c105..cc9b2cc188 100644 --- a/.github/actions/setup-gradle/action.yml +++ b/.github/actions/setup-gradle/action.yml @@ -14,6 +14,10 @@ inputs: A suitable key can be generated with `openssl rand -base64 16`. Configuration-cache data will not be saved/restored without an encryption key being provided. required: false + remove-git-config: + description: Whether to remove the git config file to prevent configuration cache invalidation. + required: false + default: 'true' runs: using: "composite" @@ -26,3 +30,11 @@ runs: with: cache-encryption-key: ${{ inputs.cache-encryption-key }} cache-read-only: ${{ inputs.cache-read-only }} + - name: Manually cache buildSrc output # workaround for https://github.com/gradle/actions/issues/21 + uses: actions/cache@v4 + with: + path: buildSrc/build + key: gradle-buildSrc-${{ hashFiles('buildSrc/src/**', 'buildSrc/build.gradle.kts') }} + - if: inputs.remove-git-config == 'true' + run: rm -f .git/config + shell: bash diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9b6ad41072..8829b35877 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -92,6 +92,11 @@ updates: schedule: interval: "weekly" + - package-ecosystem: "github-actions" + directory: "/.github/actions/setup-gradle" + schedule: + interval: "weekly" + - package-ecosystem: "terraform" directory: "/templates" schedule: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6bb37a928c..7afa312374 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -101,7 +101,7 @@ jobs: id: version run: | version=$(date '+%Y-%m-%d').${{ github.run_number }}.$(echo ${{ github.sha }} | cut -c1-7) - echo "ORG_GRADLE_PROJECT_version=$version" | tee -a "$GITHUB_ENV" + echo "VERSION=$version" | tee -a "$GITHUB_ENV" echo "version=$version" | tee -a "$GITHUB_OUTPUT" - name: Build and test @@ -115,7 +115,8 @@ jobs: with: max_attempts: 3 # Pushing lots of new image versions at once can result in GitHub rate-limiting so we retry this step timeout_minutes: 15 - command: ./gradlew ${{ matrix.project }}:jib + # Configuration cache is not yet supported for Jib - see: https://github.com/GoogleContainerTools/jib/issues/3132 + command: ./gradlew ${{ matrix.project }}:jib --no-configuration-cache env: GITHUB_USERNAME: ${{ github.actor }} GITHUB_PASSWORD: ${{ github.token }} diff --git a/buildSrc/src/main/kotlin/uk/gov/justice/digital/hmpps/plugins/JibConfigPlugin.kt b/buildSrc/src/main/kotlin/uk/gov/justice/digital/hmpps/plugins/JibConfigPlugin.kt index 98ca2bcfc7..58182fc444 100644 --- a/buildSrc/src/main/kotlin/uk/gov/justice/digital/hmpps/plugins/JibConfigPlugin.kt +++ b/buildSrc/src/main/kotlin/uk/gov/justice/digital/hmpps/plugins/JibConfigPlugin.kt @@ -51,7 +51,7 @@ class JibConfigPlugin : Plugin { project.tasks.withType().named("jib") { doFirst { jib!!.to { - tags = setOf("${project.version}") + tags = setOf("${System.getenv("VERSION") ?: "dev"}") auth { username = System.getenv("GITHUB_USERNAME") password = System.getenv("GITHUB_PASSWORD") @@ -59,7 +59,7 @@ class JibConfigPlugin : Plugin { } } if (System.getenv("FORCE_DEPLOY") == "true") { - jib!!.to.tags = setOf("${project.version}") + jib!!.to.tags = setOf("${System.getenv("VERSION") ?: "dev"}") } doLast { val dir = File("${project.rootDir}/changed")