Encapsulate common build steps in a composite action

Closes gh-40353
This commit is contained in:
Andy Wilkinson
2024-04-15 15:36:36 +01:00
parent 590b1bded8
commit e4802b880d
3 changed files with 101 additions and 67 deletions

86
.github/actions/build/action.yml vendored Normal file
View File

@@ -0,0 +1,86 @@
name: 'Build'
inputs:
java-version:
required: false
type: string
default: '17'
description: 'The Java version to compile and test with'
java-toolchain:
required: false
type: boolean
default: false
description: 'Whether a Java toolchain should be used'
publish:
required: false
type: boolean
default: false
description: 'Whether to publish artifacts ready for deployment to Artifactory'
gradle-enterprise-secret-access-key:
required: false
type: string
description: 'The secret access key for authentication with ge.spring.io'
gradle-enterprise-cache-user:
required: false
type: string
description: 'The username for authentication with the remote build cache'
gradle-enterprise-cache-password:
required: false
type: string
description: 'The password for authentication with the remote build cache'
outputs:
build-scan-url:
value: ${{ steps.build.outputs.build-scan-url }}
version:
value: ${{ steps.read-version.outputs.version }}
runs:
using: composite
steps:
- name: Set Up Java
uses: actions/setup-java@v4
with:
distribution: 'liberica'
java-version: |
${{ inputs.java-version }}
${{ inputs.java-toolchain && '17' || '' }}
- name: Set Up Gradle
uses: gradle/actions/setup-gradle@1168cd3d07c1876a65e1724114de42ccbdfa7b78 # v3.2.1
with:
cache-read-only: false
- name: Configure Gradle Properties
shell: bash
run: |
mkdir -p $HOME/.gradle
echo 'systemProp.user.name=spring-builds+github' >> $HOME/.gradle/gradle.properties
echo 'systemProp.org.gradle.internal.launcher.welcomeMessageEnabled=false' >> $HOME/.gradle/gradle.properties
echo 'org.gradle.daemon=false' >> $HOME/.gradle/gradle.properties
- name: Configure Toolchain Properties
if: ${{ inputs.java-toolchain }}
shell: bash
run: |
echo toolchainVersion=${{ inputs.java-version }} >> $HOME/.gradle/gradle.properties
echo systemProp.org.gradle.java.installations.auto-detect=false >> $HOME/.gradle/gradle.properties
echo systemProp.org.gradle.java.installations.auto-download=false >> $HOME/.gradle/gradle.properties
echo systemProp.org.gradle.java.installations.paths=${{ format('$JAVA_HOME_{0}_X64', inputs.java-version) }} >> $HOME/.gradle/gradle.properties
- name: Build
if: ${{ !inputs.publish }}
env:
GRADLE_ENTERPRISE_URL: 'https://ge.spring.io'
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ inputs.gradle-enterprise-secret-access-key }}
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ inputs.gradle-enterprise-cache-user }}
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ inputs.gradle-enterprise-cache-password }}
run: ./gradlew build
- name: Build and Publish
if: ${{ inputs.publish }}
env:
GRADLE_ENTERPRISE_URL: 'https://ge.spring.io'
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ inputs.gradle-enterprise-secret-access-key }}
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ inputs.gradle-enterprise-cache-user }}
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ inputs.gradle-enterprise-cache-password }}
run: ./gradlew -PdeploymentRepository=$(pwd)/deployment-repository build publishAllPublicationsToDeploymentRepository
- name: Read Version From gradle.properties
id: read-version
shell: bash
run: |
version=$(sed -n 's/version=\(.*\)/\1/p' gradle.properties)
echo "Version is $version"
echo "version=$version" >> $GITHUB_OUTPUT