Updated to avoid moving to far when yielding #680
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check Code Formatting | |
on: | |
push: | |
paths-ignore: ['*.md', 'CODEOWNERS', 'LICENSE'] | |
branches: | |
- 'integration' | |
- 'release/version*' | |
pull_request: | |
paths-ignore: ['*.md', 'CODEOWNERS', 'LICENSE'] | |
merge_group: | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
env: | |
JAVA_VERSION: '11' | |
JAVA_DISTRIBUTION: 'zulu' #This is the default on v1 of the action for 1.8 | |
MAVEN_OPTS: "-Djansi.force=true -Dhttps.protocols=TLSv1.2 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Djava.awt.headless=true -XX:ThreadStackSize=1m -Daether.connector.basic.threads=8 -Daether.metadataResolver.threads=8 -Daether.syncContext.named.time=480" | |
GITHUB_REGISTRY: ghcr.io | |
GITHUB_USERNAME: ${{ secrets.GHCR_WRITE_USER_NAME }} | |
GITHUB_PASSWORD: ${{ secrets.GHCR_WRITE_ACCESS_TOKEN }} | |
jobs: | |
# Runs the pom sorter and code formatter to ensure that the code | |
# is formatted and poms are sorted according to project rules. If changes are found, | |
# they are committed back to the branch | |
check-code-formatting: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Set up JDK ${{env.JAVA_VERSION}} | |
uses: actions/setup-java@v4 | |
with: | |
distribution: ${{env.JAVA_DISTRIBUTION}} | |
java-version: ${{env.JAVA_VERSION}} | |
cache: 'maven' | |
server-id: github-datawave | |
# username and password are the env variables names that maven will use | |
server-username: GITHUB_USERNAME | |
server-password: GITHUB_PASSWORD | |
- name: Extract branch name | |
shell: bash | |
run: | | |
if [[ "${{ github.event_name }}" != "merge_group" ]]; then | |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
else | |
echo "Nothing to do" | |
fi | |
id: extract_branch | |
- name: Format code | |
run: | | |
if [[ "${{ github.event_name }}" != "merge_group" ]]; then | |
mvn --show-version --batch-mode --errors --no-transfer-progress "-Dstyle.color=always" clean formatter:format sortpom:sort impsort:sort -Dmaven.build.cache.enabled=false -Pautoformat -Dutils -Dservices -Dstarters | |
if ! git diff-index --quiet HEAD; then | |
echo "Code formatting issues detected. Please format locally."; | |
exit 1; | |
fi | |
else | |
echo "Nothing to do" | |
fi |