Skip to content

*WIP* Test formatting workflow #4

*WIP* Test formatting workflow

*WIP* Test formatting workflow #4

Workflow file for this run

name: Code Formatting
on:
pull_request:
paths-ignore: ['*.md', 'CODEOWNERS', 'LICENSE']
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"
REGISTRY: ghcr.io
USER_NAME: ${{ secrets.GHCR_WRITE_USER_NAME }}
ACCESS_TOKEN: ${{ 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'
- 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
env:
USER_NAME: ${{ secrets.USER_NAME }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
run: |
if [[ "${{ github.event_name }}" != "merge_group" ]]; then
mvn -s $GITHUB_WORKSPACE/.github/workflows/settings.xml --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
git status
git diff-index --quiet HEAD || (echo "Modified files found. Creating new commit with formatting fixes" && echo "diffs_found=true" >> "$GITHUB_ENV")
else
echo "Nothing to do"
fi
- name: Commit Changes
run: |
if [[ "$diffs_found" = true && "${{ github.event_name }}" != "merge_group" ]]; then
git config --global user.name "GitHub Actions"
git config --global user.email "datawave@github.com"
git fetch origin
git checkout ${{ steps.extract_branch.outputs.branch }}
git pull origin ${{ steps.extract_branch.outputs.branch }} --no-rebase
git commit -am "GitHub Actions: Fix Formatting"
git push origin ${{ steps.extract_branch.outputs.branch }}
else
echo "Nothing to do"
fi