This repository has been archived by the owner on Jan 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split maven CI and add code formatting (#52)
- Loading branch information
Showing
8 changed files
with
203 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright FUJITSU LIMITED 2021 | ||
|
||
# This workflow will build a Java project with Maven | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven | ||
|
||
name: Master CI | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
env: | ||
COMMIT: ${{ github.sha }} | ||
BRANCH: master | ||
REPOSITORY: ${{ github.repository }} | ||
GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Setup Workspace | ||
if: env.GH_TOKEN == '' | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: echo "GH_TOKEN=${GH_TOKEN}" >> $GITHUB_ENV | ||
- name: Checkout Source | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ env.GH_TOKEN }} | ||
- name: Install Java Runtime | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'temurin' # See 'Supported distributions' for available options | ||
java-version: '8' | ||
- run: | | ||
chmod +x ./scripts/*.sh | ||
- name: Check Copyright Headers | ||
run: ./scripts/check_copyrights.sh | ||
shell: bash | ||
- name: Apply Code Formatting | ||
run: ./scripts/format_code.sh | ||
shell: bash | ||
- name: Build with Maven | ||
run: mvn clean install -f pom.xml | ||
- name: Publish Formatted Code | ||
run: ./scripts/repush_formatted_code.sh | ||
env: | ||
COMMIT: ${{ github.sha }} | ||
BRANCH: master | ||
GH_TOKEN: ${{ env.GH_TOKEN }} | ||
shell: bash | ||
- name: Surefire Report | ||
uses: ScaCap/action-surefire-report@v1 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Archive Code Coverage Results | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: ${{ github.event.repository.name }}-coveragereport | ||
path: ./**/target/site/jacoco | ||
- name: Archive Test Results | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: ${{ github.event.repository.name }}-testresults | ||
path: ./**/target/surefire-reports |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
|
||
prepend_legal_notice () { | ||
tmpFile=$(mktemp) | ||
cat $tmpNotice $CLASS_FILE > $tmpFile | ||
mv "$tmpFile" $CLASS_FILE | ||
} | ||
|
||
set_copyright_dates () { | ||
YEAR=$(date +'%Y') | ||
DATE=$(date +'%d-%m-%Y') | ||
|
||
tmpNotice=$(mktemp) | ||
cat $COPYRIGHT_NOTICE_FILE > $tmpNotice | ||
|
||
sed -i 's/T_YEAR/'$YEAR'/g' $tmpNotice | ||
sed -i 's/T_DATE/'$DATE'/g' $tmpNotice | ||
} | ||
|
||
echo "CHECKING FOR LEGAL NOTICE IN $1..." | ||
|
||
CLASS_FILE=$1 | ||
COPYRIGHT_NOTICE_FILE=$2 | ||
LINE_LIMIT=7 | ||
|
||
LINES_IN_FILE=$(wc -l $CLASS_FILE | awk '{ print $1 }') | ||
|
||
if [ "$LINES_IN_FILE" -lt "$LINE_LIMIT" ] ; then | ||
linesToRead=$LINES_IN_FILE | ||
else | ||
linesToRead=$LINE_LIMIT | ||
fi | ||
|
||
set_copyright_dates | ||
|
||
while IFS='' read -r line || [[ -n "$line" ]] ; do | ||
linesToRead=$((linesToRead-1)) | ||
|
||
if [[ "$(echo "$line" | tr '[:upper:]' '[:lower:]')" == *"copyright fujitsu"* ]] ; then | ||
echo "LEGAL NOTICE FOUND! :)" | ||
break | ||
fi | ||
|
||
if [ "$linesToRead" -eq 0 ] ; then | ||
echo "LEGAL NOTICE NOT FOUND. PREPENDING..." | ||
prepend_legal_notice | ||
break | ||
fi | ||
done < "$1" | ||
|
||
echo "DONE!" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
. ./scripts/common.sh | ||
|
||
echo "PROCEEDING WITH COPYRIGHT CHECK..." | ||
|
||
determine_files_to_process | ||
|
||
if [[ ! -z "$GIT_DIFF_OUTPUT" ]] ; then | ||
echo $GIT_DIFF_OUTPUT | tr " " "\n" | while read -r line ; do | ||
bash scripts/check_add_class_legal_notice.sh $line scripts/java_class_legal_notice.md | ||
done | ||
else | ||
echo "NOTHING TO PROCESS. ABORTING..." | ||
echo "DONE!" | ||
fi |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Migration notice: Following input is expected | ||
# - $COMMIT_RANGE for $TRAVIS_COMMIT_RANGE | ||
# - $COMMIT for $TRAVIS_COMMIT | ||
|
||
determine_files_to_process () { | ||
if [[ ! -z "$COMMIT_RANGE" ]] ; then | ||
GIT_DIFF_OUTPUT=$(git diff --stat --name-only $(echo "$COMMIT_RANGE") | grep "\.java$") | ||
else | ||
GIT_DIFF_OUTPUT=$(git diff-tree --no-commit-id --name-only -r $(echo "$COMMIT") | grep "\.java$") | ||
fi | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
. ./scripts/common.sh | ||
|
||
echo "PROCEEDING WITH GOOGLE JAVA FORMAT STEP..." | ||
|
||
determine_files_to_process | ||
|
||
git pull | ||
|
||
if [[ ! -z "$GIT_DIFF_OUTPUT" ]] ; then | ||
if [ ! -f ./libraries/google-java-format.jar ] ; then | ||
curl -o ./libraries/google-java-format.jar --create-dirs https://repo1.maven.org/maven2/com/google/googlejavaformat/google-java-format/1.7/google-java-format-1.7-all-deps.jar | ||
chmod 755 ./libraries/google-java-format.jar | ||
fi | ||
|
||
echo $GIT_DIFF_OUTPUT | tr " " "\n" | while read -r line ; do | ||
echo "FORMATING FILE $line..." | ||
java -jar ./libraries/google-java-format.jar -r $line | ||
done | ||
else | ||
echo "NOTHING TO FORMAT. ABORTING..." | ||
fi | ||
|
||
echo "DONE!" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/******************************************************************************* | ||
* | ||
* Copyright FUJITSU LIMITED T_YEAR | ||
* | ||
* Creation Date: T_DATE | ||
* | ||
*******************************************************************************/ | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
. ./scripts/common.sh | ||
|
||
echo "PUSHING FORMATTED CODE BACK TO THE REPOSITORY..." | ||
|
||
git config --global user.email "oscm.automaton@gmail.com" | ||
git config --global user.name "OSCM Automaton" | ||
git config --global push.default simple | ||
git remote set-url origin https://${GH_TOKEN}@github.com/${REPOSITORY}.git | ||
|
||
determine_files_to_process | ||
|
||
if [[ ! -z "$GIT_DIFF_OUTPUT" ]] ; then | ||
git add *.java | ||
git commit -m "Applied code formatting [ci skip]" | ||
git push origin HEAD:$BRANCH | ||
else | ||
echo "NOTHING TO PUSH. ABORTING..." | ||
fi | ||
|
||
echo "DONE!" |