Skip to content

Commit

Permalink
PI-2624 Prevent version from invalidating config cache
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl committed Nov 7, 2024
1 parent 07000c8 commit d2def5c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/actions/analyse/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion .github/actions/get-build-info/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
12 changes: 12 additions & 0 deletions .github/actions/setup-gradle/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class JibConfigPlugin : Plugin<Project> {
project.tasks.withType<BuildImageTask>().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")
}
}
}
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")
Expand Down

0 comments on commit d2def5c

Please sign in to comment.