Skip to content

Commit e4802b8

Browse files
committed
Encapsulate common build steps in a composite action
Closes gh-40353
1 parent 590b1bd commit e4802b8

File tree

3 files changed

+101
-67
lines changed

3 files changed

+101
-67
lines changed

.github/actions/build/action.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: 'Build'
2+
inputs:
3+
java-version:
4+
required: false
5+
type: string
6+
default: '17'
7+
description: 'The Java version to compile and test with'
8+
java-toolchain:
9+
required: false
10+
type: boolean
11+
default: false
12+
description: 'Whether a Java toolchain should be used'
13+
publish:
14+
required: false
15+
type: boolean
16+
default: false
17+
description: 'Whether to publish artifacts ready for deployment to Artifactory'
18+
gradle-enterprise-secret-access-key:
19+
required: false
20+
type: string
21+
description: 'The secret access key for authentication with ge.spring.io'
22+
gradle-enterprise-cache-user:
23+
required: false
24+
type: string
25+
description: 'The username for authentication with the remote build cache'
26+
gradle-enterprise-cache-password:
27+
required: false
28+
type: string
29+
description: 'The password for authentication with the remote build cache'
30+
outputs:
31+
build-scan-url:
32+
value: ${{ steps.build.outputs.build-scan-url }}
33+
version:
34+
value: ${{ steps.read-version.outputs.version }}
35+
runs:
36+
using: composite
37+
steps:
38+
- name: Set Up Java
39+
uses: actions/setup-java@v4
40+
with:
41+
distribution: 'liberica'
42+
java-version: |
43+
${{ inputs.java-version }}
44+
${{ inputs.java-toolchain && '17' || '' }}
45+
- name: Set Up Gradle
46+
uses: gradle/actions/setup-gradle@1168cd3d07c1876a65e1724114de42ccbdfa7b78 # v3.2.1
47+
with:
48+
cache-read-only: false
49+
- name: Configure Gradle Properties
50+
shell: bash
51+
run: |
52+
mkdir -p $HOME/.gradle
53+
echo 'systemProp.user.name=spring-builds+github' >> $HOME/.gradle/gradle.properties
54+
echo 'systemProp.org.gradle.internal.launcher.welcomeMessageEnabled=false' >> $HOME/.gradle/gradle.properties
55+
echo 'org.gradle.daemon=false' >> $HOME/.gradle/gradle.properties
56+
- name: Configure Toolchain Properties
57+
if: ${{ inputs.java-toolchain }}
58+
shell: bash
59+
run: |
60+
echo toolchainVersion=${{ inputs.java-version }} >> $HOME/.gradle/gradle.properties
61+
echo systemProp.org.gradle.java.installations.auto-detect=false >> $HOME/.gradle/gradle.properties
62+
echo systemProp.org.gradle.java.installations.auto-download=false >> $HOME/.gradle/gradle.properties
63+
echo systemProp.org.gradle.java.installations.paths=${{ format('$JAVA_HOME_{0}_X64', inputs.java-version) }} >> $HOME/.gradle/gradle.properties
64+
- name: Build
65+
if: ${{ !inputs.publish }}
66+
env:
67+
GRADLE_ENTERPRISE_URL: 'https://ge.spring.io'
68+
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ inputs.gradle-enterprise-secret-access-key }}
69+
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ inputs.gradle-enterprise-cache-user }}
70+
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ inputs.gradle-enterprise-cache-password }}
71+
run: ./gradlew build
72+
- name: Build and Publish
73+
if: ${{ inputs.publish }}
74+
env:
75+
GRADLE_ENTERPRISE_URL: 'https://ge.spring.io'
76+
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ inputs.gradle-enterprise-secret-access-key }}
77+
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ inputs.gradle-enterprise-cache-user }}
78+
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ inputs.gradle-enterprise-cache-password }}
79+
run: ./gradlew -PdeploymentRepository=$(pwd)/deployment-repository build publishAllPublicationsToDeploymentRepository
80+
- name: Read Version From gradle.properties
81+
id: read-version
82+
shell: bash
83+
run: |
84+
version=$(sed -n 's/version=\(.*\)/\1/p' gradle.properties)
85+
echo "Version is $version"
86+
echo "version=$version" >> $GITHUB_OUTPUT

.github/workflows/build-and-deploy-snapshot.yml

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,15 @@ jobs:
1111
runs-on: ubuntu22-8-32
1212
if: ${{ github.repository == 'spring-projects/spring-boot' }}
1313
steps:
14-
- name: Set Up Java
15-
uses: actions/setup-java@v4
16-
with:
17-
distribution: 'liberica'
18-
java-version: 17
19-
- name: Check Out
14+
- name: Check Out Code
2015
uses: actions/checkout@v4
21-
- name: Set Up Gradle
22-
uses: gradle/actions/setup-gradle@1168cd3d07c1876a65e1724114de42ccbdfa7b78 # v3.2.1
23-
with:
24-
cache-read-only: false
25-
- name: Configure Gradle Properties
26-
shell: bash
27-
run: |
28-
mkdir -p $HOME/.gradle
29-
echo 'systemProp.user.name=spring-builds+github' >> $HOME/.gradle/gradle.properties
30-
echo 'systemProp.org.gradle.internal.launcher.welcomeMessageEnabled=false' >> $HOME/.gradle/gradle.properties
31-
echo 'org.gradle.daemon=false' >> $HOME/.gradle/gradle.properties
3216
- name: Build and Publish
33-
id: build
34-
env:
35-
CI: 'true'
36-
GRADLE_ENTERPRISE_URL: 'https://ge.spring.io'
37-
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }}
38-
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USER }}
39-
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
40-
run: ./gradlew -PdeploymentRepository=$(pwd)/deployment-repository build publishAllPublicationsToDeploymentRepository
17+
uses: ./.github/actions/build
18+
with:
19+
gradle-enterprise-access-key: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }}
20+
gradle-enterprise-cache-user: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USER }}
21+
gradle-enterprise-cache-password: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
22+
publish: true
4123
- name: Deploy
4224
uses: spring-io/artifactory-deploy-action@26bbe925a75f4f863e1e529e85be2d0093cac116 # v0.0.1
4325
with:
@@ -59,15 +41,8 @@ jobs:
5941
status: ${{ job.status }}
6042
build-scan-url: ${{ steps.build.outputs.build-scan-url }}
6143
run-name: ${{ format('{0} | Linux | Java 17', github.ref_name) }}
62-
- name: Read Version From gradle.properties
63-
id: read-version
64-
shell: bash
65-
run: |
66-
version=$(sed -n 's/version=\(.*\)/\1/p' gradle.properties)
67-
echo "Version is $version"
68-
echo "version=$version" >> $GITHUB_OUTPUT
6944
outputs:
70-
version: ${{ steps.read-version.outputs.version }}
45+
version: ${{ steps.build.outputs.version }}
7146
verify:
7247
name: Verify
7348
needs: build-and-deploy-snapshot

.github/workflows/ci.yml

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ jobs:
2828
java:
2929
version: 17
3030
steps:
31-
- name: Set Up Java
32-
uses: actions/setup-java@v4
33-
with:
34-
distribution: 'liberica'
35-
java-version: |
36-
${{ matrix.java.version }}
37-
${{ matrix.java.toolchain && '17' || '' }}
3831
- name: Prepare Windows runner
3932
if: ${{ runner.os == 'Windows' }}
4033
run: |
@@ -43,34 +36,14 @@ jobs:
4336
Stop-Service -name Docker
4437
- name: Check Out Code
4538
uses: actions/checkout@v4
46-
- name: Set Up Gradle
47-
uses: gradle/actions/setup-gradle@1168cd3d07c1876a65e1724114de42ccbdfa7b78 # v3.2.1
48-
with:
49-
cache-read-only: false
50-
- name: Configure Gradle Properties
51-
shell: bash
52-
run: |
53-
mkdir -p $HOME/.gradle
54-
echo 'systemProp.user.name=spring-builds+github' >> $HOME/.gradle/gradle.properties
55-
echo 'systemProp.org.gradle.internal.launcher.welcomeMessageEnabled=false' >> $HOME/.gradle/gradle.properties
56-
echo 'org.gradle.daemon=false' >> $HOME/.gradle/gradle.properties
57-
- name: Configure Toolchain Properties
58-
if: ${{ matrix.java.toolchain }}
59-
shell: bash
60-
run: |
61-
echo toolchainVersion=${{ matrix.java.version }} >> $HOME/.gradle/gradle.properties
62-
echo systemProp.org.gradle.java.installations.auto-detect=false >> $HOME/.gradle/gradle.properties
63-
echo systemProp.org.gradle.java.installations.auto-download=false >> $HOME/.gradle/gradle.properties
64-
echo systemProp.org.gradle.java.installations.paths=${{ format('$JAVA_HOME_{0}_X64', matrix.java.version) }} >> $HOME/.gradle/gradle.properties
6539
- name: Build
66-
id: build
67-
env:
68-
CI: 'true'
69-
GRADLE_ENTERPRISE_URL: 'https://ge.spring.io'
70-
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }}
71-
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USER }}
72-
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
73-
run: ./gradlew build
40+
uses: ./.github/actions/build
41+
with:
42+
java-version: ${{ matrix.java.version }}
43+
java-toolchain: ${{ matrix.java.toolchain }}
44+
gradle-enterprise-access-key: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }}
45+
gradle-enterprise-cache-user: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USER }}
46+
gradle-enterprise-cache-password: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
7447
- name: Send Notification
7548
uses: ./.github/actions/send-notification
7649
if: always()

0 commit comments

Comments
 (0)