Skip to content

Commit

Permalink
refact: update build config
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Sep 7, 2024
1 parent 81f06af commit 85f3223
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 71 deletions.
48 changes: 21 additions & 27 deletions .ci/build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: © Vegard IT GmbH (https://vegardit.com)
# SPDX-FileContributor: Sebastian Thomschke (Vegard IT GmbH)
# SPDX-License-Identifier: Apache-2.0
#
# @author Sebastian Thomschke, Vegard IT GmbH
# SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/copycat

#####################
# Script init
Expand Down Expand Up @@ -37,7 +37,7 @@ echo "###################################################"
echo "# Determining GIT branch...... #"
echo "###################################################"
GIT_BRANCH=$(git branch --show-current)
echo " -> GIT Branch: $GIT_BRANCH"; echo
echo " -> GIT Branch: $GIT_BRANCH"


if ! hash mvn 2>/dev/null; then
Expand All @@ -64,46 +64,38 @@ if ! hash mvn 2>/dev/null; then
fi


echo
echo "###################################################"
echo "# Configuring JDK Class Data Sharing... #"
echo "###################################################"
java_version=$(java -version 2>&1)
echo "$java_version"
# https://docs.oracle.com/javase/8/docs/technotes/guides/vm/class-data-sharing.html
jdk_version_checksum=$(echo "$java_version" | md5sum | cut -f1 -d" ")
if [[ ! -f $HOME/.xshare/$jdk_version_checksum ]]; then
echo " -> Generating shared class data archive..."
mkdir -p $HOME/.xshare
java -Xshare:dump -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=$HOME/.xshare/$jdk_version_checksum
else
echo " -> Reusing shared class data archive..."
fi
export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS:-} -Xshare:on -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=$HOME/.xshare/$jdk_version_checksum"


echo
echo "###################################################"
echo "# Configuring MAVEN_OPTS... #"
echo "###################################################"
MAVEN_OPTS="${MAVEN_OPTS:-}"
MAVEN_OPTS="$MAVEN_OPTS -XX:+TieredCompilation -XX:TieredStopAtLevel=1" # https://zeroturnaround.com/rebellabs/your-maven-build-is-slow-speed-it-up/
MAVEN_OPTS="$MAVEN_OPTS -Djava.security.egd=file:/dev/./urandom" # https://stackoverflow.com/questions/58991966/what-java-security-egd-option-is-for/59097932#59097932
MAVEN_OPTS="$MAVEN_OPTS -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS" # https://stackoverflow.com/questions/5120470/how-to-time-the-different-stages-of-maven-execution/49494561#49494561
export MAVEN_OPTS="$MAVEN_OPTS -Xmx1024m -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dhttps.protocols=TLSv1.2"
MAVEN_OPTS+=" -Djava.security.egd=file:/dev/./urandom" # https://stackoverflow.com/questions/58991966/what-java-security-egd-option-is-for/59097932#59097932
MAVEN_OPTS+=" -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS" # https://stackoverflow.com/questions/5120470/how-to-time-the-different-stages-of-maven-execution/49494561#49494561
MAVEN_OPTS+=" -Xmx1024m -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dhttps.protocols=TLSv1.3,TLSv1.2"
echo " -> MAVEN_OPTS: $MAVEN_OPTS"
export MAVEN_OPTS

MAVEN_CLI_OPTS="-e -U --batch-mode --show-version --no-transfer-progress -s .ci/maven-settings.xml -t .ci/maven-toolchains.xml"
MAVEN_CLI_OPTS="-e -U --batch-mode --show-version -s .ci/maven-settings.xml -t .ci/maven-toolchains.xml"
if [[ -n ${GITEA_ACTIONS:-} || (-n ${CI:-} && -z ${ACT:-}) ]]; then # if running on a remote CI but not on local nektos/act runner
MAVEN_CLI_OPTS+=" --no-transfer-progress"
fi
if [[ -n ${ACT:-} ]]; then
MAVEN_CLI_OPTS+=" -Dformatter.validate.lineending=KEEP"
fi
echo " -> MAVEN_CLI_OPTS: $MAVEN_CLI_OPTS"


echo
echo "###################################################"
echo "# Determining current Maven project version... #"
echo "###################################################"
# https://stackoverflow.com/questions/3545292/how-to-get-maven-project-version-to-the-bash-command-line
projectVersion="$(mvn -s .ci/maven-settings.xml help:evaluate -Dexpression=project.version -q -DforceStdout)"
projectVersion=$(python -c "import xml.etree.ElementTree as ET; \
print(ET.parse(open('pom.xml')).getroot().find( \
'{http://maven.apache.org/POM/4.0.0}version').text)")
echo " -> Current Version: $projectVersion"


#
# decide whether to perform a release build or build+deploy a snapshot version
#
Expand Down Expand Up @@ -137,6 +129,7 @@ if [[ ${projectVersion:-foo} == ${POM_CURRENT_VERSION:-bar} && ${MAY_CREATE_RELE
-DreleaseVersion=${POM_RELEASE_VERSION} \
-DdevelopmentVersion=${nextDevelopmentVersion} \
help:active-profiles clean release:clean release:prepare release:perform \
| grep -v -e "\[INFO\] Download.* from repository-restored-from-cache" `# suppress download messages from repo restored from cache ` \
| grep -v -e "\[INFO\] .* \[0.0[0-9][0-9]s\]" # the grep command suppresses all lines from maven-buildtime-extension that report plugins with execution time <=99ms
else
echo
Expand All @@ -145,5 +138,6 @@ else
echo "###################################################"
mvn $MAVEN_CLI_OPTS "$@" \
help:active-profiles clean verify \
| grep -v -e "\[INFO\] Download.* from repository-restored-from-cache" `# suppress download messages from repo restored from cache ` \
| grep -v -e "\[INFO\] .* \[0.0[0-9][0-9]s\]" # the grep command suppresses all lines from maven-buildtime-extension that report plugins with execution time <=99ms
fi
66 changes: 66 additions & 0 deletions .ci/maven-settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,71 @@
<username>${env.GITHUB_USER}</username>
<password>${env.GITHUB_API_KEY}</password>
</server>
<server>
<id>central</id>
<configuration>
<!-- https://maven.apache.org/guides/mini/guide-resolver-transport.html#timeouts -->
<connectTimeout>10000</connectTimeout>
<requestTimeout>30000</requestTimeout>
</configuration>
</server>
</servers>

<profiles>
<profile>
<id>prefer-repo-restored-from-cache</id>
<activation>
<property>
<name>env.RESTORED_REPO_PATH</name>
</property>
</activation>

<repositories>
<repository>
<id>repository-restored-from-cache</id>
<url>file://${RESTORED_REPO_PATH}</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repository-restored-from-cache</id>
<url>file://${RESTORED_REPO_PATH}</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

</settings>
83 changes: 70 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,53 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Show environment variables
- name: "Show: GitHub context"
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo $GITHUB_CONTEXT


- name: "Show: environment variables"
run: env | sort


- name: Git Checkout
uses: actions/checkout@v4 # https://github.com/actions/checkout


- name: "Install: JDK ${{ env.JAVA_VERSION }}"
- name: "Install: JDK ${{ env.JAVA_VERSION }}"
uses: actions/setup-java@v4 # https://github.com/actions/setup-java
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
cache: maven

- name: Test with Maven

- name: "Cache: Restore"
id: cache-restore
uses: actions/cache/restore@v4 # https://github.com/actions/cache/blob/main/restore/README.md
with:
# IMPORTANT: path must have exactly the same value as in the cache save step otherwise restore will fail with cache key not found
path: |
~/.m2/bin
~/.m2/repository
!~/.m2/repository/.cache
!~/.m2/repository/.meta
!~/.m2/repository/com/vegardit/maven
!~/.m2/repository/*SNAPSHOT*
key: ${{ runner.os }}-${{ runner.arch }}-mvn-repo-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-mvn-repo-
- name: "Move Restored Repo"
if: ${{ steps.cache-restore.outputs.cache-hit }}
run: |
RESTORED_REPO_PATH=$HOME/.m2/repository-restored
mv -v ~/.m2/repository $RESTORED_REPO_PATH
echo "RESTORED_REPO_PATH=$RESTORED_REPO_PATH" >> $GITHUB_ENV
- name: "Test with Maven 🔨"
if: ${{ github.ref_name != 'main' || env.ACT }}
env:
GITHUB_USER: ${{ github.actor }}
Expand All @@ -78,7 +109,7 @@ jobs:
bash .ci/build.sh ${{ github.event.inputs.additional_maven_args }}
- name: Build with Maven
- name: "Build with Maven 🔨"
if: ${{ github.ref_name == 'main' && !env.ACT }}
env:
GITHUB_USER: ${{ github.actor }}
Expand All @@ -88,11 +119,37 @@ jobs:
set -eu
# https://github.heygears.community/t/github-actions-bot-email-address/17204
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
bash .ci/build.sh ${{ github.event.inputs.additional_maven_args }}
##################################################
# Cache Update
# See https://github.com/actions/cache/issues/342#issuecomment-1399442670
##################################################
- name: "Cache: Delete Previous"
if: ${{ steps.cache-restore.outputs.cache-hit && !env.ACT }}
env:
GH_TOKEN: ${{ github.token }}
run: |
gh extension install actions/gh-actions-cache
# "|| true" is to avoid "Error: Resource not accessible by integration" from failing the job
gh actions-cache delete ${{ steps.cache-restore.outputs.cache-primary-key }} --confirm || true
- name: "Cache: Update"
uses: actions/cache/save@v4 # https://github.com/actions/cache/blob/main/save/README.md
with:
path: |
~/.m2/bin
~/.m2/repository
!~/.m2/repository/.cache
!~/.m2/repository/.meta
!~/.m2/repository/com/vegardit/maven
!~/.m2/repository/*SNAPSHOT*
key: ${{ steps.cache-restore.outputs.cache-primary-key }}


- name: Test minimized fat jar
run: |
set -ex
Expand Down Expand Up @@ -329,19 +386,19 @@ jobs:
esac
- name: "Get: maven-build-artifacts"
uses: actions/download-artifact@v4
with:
name: maven-build-artifacts


- name: Enable Developer Command Prompt
if: matrix.arch == 'windows-amd64'
# makes cl.exe available on PATH
# https://github.com/marketplace/actions/enable-developer-command-prompt
uses: ilammy/msvc-dev-cmd@v1


- name: "Get: maven-build-artifacts"
uses: actions/download-artifact@v4
with:
name: maven-build-artifacts


- name: "Collect metadata"
run: |
set -eu
Expand Down
40 changes: 26 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
# Contributing
# Contributing to the Project

Thanks for your interest in contributing to this project!
Thank you for your interest in contributing to this project! We strive to make the contribution process clear and welcoming.

We want to make contributing as easy and transparent as possible.
Please take a moment to review the guidelines below.


## Code of Conduct

Our code of conduct is described in [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md).
Please follow it in all your interactions with the project.
Please review and adhere to our [Code of Conduct](CODE_OF_CONDUCT.md) in all your interactions with the project.
This helps us maintain a positive and respectful environment for everyone involved.


## Issues
## How to Contribute

We use GitHub issues to track bugs and feature requests. Please ensure your description is clear and has sufficient instructions to be able to reproduce the issue.
### Contributor Responsibilities

By submitting your contributions, you agree to the following:
- You are the sole author of the content you contribute, or you have the appropriate rights and permissions to contribute it.
- If employed, you have obtained any necessary permissions from your employer to contribute to this project.
- All contributions will be made available under the project’s license.

## Pull Requests
### Issues

Before you make a substantial pull request, please file an issue and make sure someone from the team agrees that there is a problem or room for improvement.
We use GitHub Issues to track bugs and feature requests. When submitting an issue, please ensure:
- The description is clear and concise.
- You provide enough details and steps to reproduce the issue, if applicable.

### Pull Requests

### License
Before making substantial contributions:
1. **Discuss Changes**: Please file an issue first to discuss your proposed changes with the team. This helps ensure your contribution aligns with the project’s goals.
2. **Follow Best Practices**: Adhere to the guidelines and ensure your code meets the project’s standards (see [Code Guidelines](#code-guidelines)).

By contributing your code, you agree to license your contribution under the [Apache License 2.0](LICENSE.txt).
When submitting a pull request:
- Ensure your changes are well-documented.
- Include tests for any new features or significant changes.
- Reference the relevant issue(s) in your pull request description.


### Source Code Formatting
## Licensing

Before committing your code ensure it is formatted according the [vegardit.com Eclipse formatter rules](https://github.com/vegardit/vegardit-maven-parent/blob/main/src/etc/eclipse-formatter.xml).
By contributing to this project, you agree that your contributions will be licensed under the [Apache License 2.0](LICENSE.txt).

IntelliJ users can use the [Eclipse Code Formatter](https://plugins.jetbrains.com/plugin/6546-eclipse-code-formatter) plugin to import and use the formatter settings.
The project itself is also licensed under the [Apache License 2.0](LICENSE.txt)).
Loading

0 comments on commit 85f3223

Please # to comment.