blob: 712b153f8e6449dcc2183eb068c3ada54701fbe5 [file] [log] [blame]
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to you under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: build-reusable
on:
workflow_call:
inputs:
develocity-enabled:
description: Enable Develocity Build Scan publication
default: false
type: boolean
java-version:
description: The Java compiler version
default: 17
type: string
maven-args:
description: Additional Maven arguments
type: string
reproducibility-check-enabled:
description: Runs a reproducibility check on the build
default: true
type: boolean
site-enabled:
description: Flag indicating if Maven `site` goal should be run
default: false
type: boolean
secrets:
DV_ACCESS_TOKEN:
description: Access token to Gradle Enterprise
required: false
env:
MAVEN_ARGS: ${{ inputs.maven-args }}
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ macos-latest, ubuntu-latest, windows-latest ]
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
with:
# When running on `pull_request` use the PR branch, not the target branch
ref: ${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
- name: Set up Java
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # 4.5.0
with:
distribution: zulu
java-version: ${{ inputs.java-version }}
cache: maven
- name: Set up Develocity
if: inputs.develocity-enabled
shell: bash
run: |
if [ -f .mvn/develocity.xml ]; then
DEVELOCITY_VERSION=$(./mvnw help:evaluate -q -DforceStdout -Dexpression=develocity-maven-plugin.version)
USER_DATA_VERSION=$(./mvnw help:evaluate -q -DforceStdout -Dexpression=develocity-user-data-extension.version)
cat >.mvn/extensions.xml <<EOF
<extensions>
<extension>
<groupId>com.gradle</groupId>
<artifactId>develocity-maven-extension</artifactId>
<version>$DEVELOCITY_VERSION</version>
</extension>
<extension>
<groupId>com.gradle</groupId>
<artifactId>common-custom-user-data-maven-extension</artifactId>
<version>$USER_DATA_VERSION</version>
</extension>
</extensions>
EOF
# Print file for debugging purposes
cat .mvn/extensions.xml
fi
- name: Setup Develocity Build Scan capture
if: inputs.develocity-enabled
uses: gradle/develocity-actions/setup-maven@9f1bf05334de7eb619731d5466c35a153742311d # 1.2
with:
develocity-access-key: ${{ secrets.DV_ACCESS_TOKEN }}
# We could have used `verify`, but `clean install` is required while generating the build reproducibility report, which is performed in the next step.
# For details, see: https://maven.apache.org/guides/mini/guide-reproducible-builds.html#how-to-test-my-maven-build-reproducibility
- name: Build
id: build
shell: bash
run: |
./mvnw \
--show-version --batch-mode --errors --no-transfer-progress \
-DtrimStackTrace=false \
-DinstallAtEnd=true \
clean install
# We upload tests results.
- name: Upload test reports
if: always()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # 4.4.3
with:
name: surefire-${{matrix.os}}-${{github.run_number}}-${{github.run_attempt}}
path: |
**/target/surefire-reports
**/target/logs
- name: Clean up Develocity
if: inputs.develocity-enabled
shell: bash
run: |
rm -f .mvn/extensions.xml
# Clean up changes introduced by gradle/develocity-actions/maven-setup
echo "MAVEN_OPTS=" >> "$GITHUB_ENV"
# Node.js cache is needed for Antora
- name: Set up Node.js cache
if: inputs.site-enabled
id: nodejs-cache
uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # 4.1.1
with:
# We should be calculating the cache key using `package-lock.json` instead!
# See https://stackoverflow.com/a/48524475/1278899
# For that, `package-lock.json` needs to be committed into the repository – right now it is `.gitignore`d.
# Once it is there, we should ideally switch from `npm i` to `npm ci`.
# For that, we need to configure `dependabot` to update hundreds of dependencies listed in `package-lock.json`.
# That translates to a never ending rain of `dependabot` PRs.
# I doubt if the wasted CPU cycles worth the gain.
key: "${{ runner.os }}-nodejs-cache-${{ hashFiles('node', 'node_modules') }}"
# `actions/cache` doesn't recommend caching `node_modules`.
# Though none of its recipes fit our bill, since we install Node.js using `frontend-maven-plugin`.
# See https://github.com/actions/cache/blob/main/examples.md#node---npm
# We settle for this quick-n-dirty solution for the time being.
path: |
node
node_modules
- name: Build the website
if: inputs.site-enabled
shell: bash
env:
# Making Node.js cache hit visible for debugging purposes
NODEJS_CACHE_HIT: ${{ steps.nodejs-cache.outputs.cache-hit }}
run: |
./mvnw \
--show-version --batch-mode --errors --no-transfer-progress \
site
# `clean verify artifact:compare` is required to generate the build reproducibility report.
# For details, see: https://maven.apache.org/guides/mini/guide-reproducible-builds.html#how-to-test-my-maven-build-reproducibility
- name: Verify build reproducibility
if: inputs.reproducibility-check-enabled
id: reproducibility
shell: bash
run: |
./mvnw \
--show-version --batch-mode --errors --no-transfer-progress \
-DskipTests=true \
clean verify artifact:compare
# Upload reproducibility results if the build fails.
- name: Upload reproducibility results
if: inputs.reproducibility-check-enabled && failure() && steps.reproducibility.conclusion == 'failure'
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # 4.4.3
with:
name: reproducibility-${{matrix.os}}-${{github.run_number}}-${{github.run_attempt}}
path: |
**/target/bom.xml
**/target/*.buildcompare
**/target/*.jar
**/target/*.zip
**/target/reference/**