Skip to content

Merge pull request #22 from Yui-KitamuraLLC/yui-Kitamura-patch-1 #184

Merge pull request #22 from Yui-KitamuraLLC/yui-Kitamura-patch-1

Merge pull request #22 from Yui-KitamuraLLC/yui-Kitamura-patch-1 #184

# This workflow will build a Java project with Maven,
# then commit the .jar file to the branche
# author KITAMURA Yui (at) Yui-Kitamura LLC.
name: Java_Build_Maven_And_Commit
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_call:
inputs:
jdk:
type: string
required: false
secrets:
APP_ID:
description: 'the app id of your GitHubApp'
required: true
SECRET:
description: 'the secret key of your GitHubApp'
required: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: setPushSha
id: pushSha
if: ${{github.event_name == 'push' }}
run: echo 'TARGET_SHA=' ${{ github.sha }} >> $GITHUB_ENV
- name: setPRSha
id: prSha
if: ${{github.event_name == 'pull_request' }}
run: echo 'TARGET_SHA=' ${{ github.event.pull_request.head.sha }} >> $GITHUB_ENV
- name: shaShow
id: targetSha
run: echo "SHA=${{ env.TARGET_SHA }}" >> $GITHUB_OUTPUT
- run: echo ${{steps.targetSha.outputs.SHA}}
- uses: actions/checkout@v3
- name: use jdk version
id: useJdkVersion
run: |
inJdk=${{inputs.jdk}}
useJdk=${inJdk:-"17"}
echo $useJdk
echo "v=${useJdk}" >> $GITHUB_OUTPUT
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: ${{steps.useJdkVersion.outputs.v}}
distribution: 'temurin'
cache: maven
- name: Build with Maven
id: mavenBuild
run: mvn -B package -DjdkVersion=${{steps.useJdkVersion.outputs.v}} --file pom.xml
- uses: actions/upload-artifact@v3
id: upload
with:
name: 'Package'
path: target/*.jar
outputs:
targetSha: ${{ steps.targetSha.outputs.SHA }}
attachComment:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: download-build
id: download
uses: actions/download-artifact@v3
with:
name: 'Package'
path: target
- name: echo-dl-path
run: ls -R -l -h
working-directory: ${{steps.download.outputs.download-path}}
- name: Get github token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.SECRET }}
- name: git setting
run: |
git config --local user.email "mavenBuildCommit.yml@workflow.github.yui.eng.pro"
git config --local user.name "GitHub Action"
- name: add
id: add
shell: bash
run: |
git add $(find ${{steps.download.outputs.download-path}} -name *.jar -not -name original*)
jarName=$(find ${{steps.download.outputs.download-path}} -name *.jar -not -name original*)
echo "jarName="${jarName}
repoFull=${{github.repository}}
repoName=${repoFull#${{github.repository_owner}}/}
for ((i=0; i<${#jarName[@]}; i++)); do
if [ $i -eq 0 ]
then
filePath=${jarName[0]##*${repoName}/}
else
filePath="${filePath} ${jarName[$i]}"
fi
done
echo "filePath="${filePath}
echo "file="${filePath} >> $GITHUB_OUTPUT
branch=${{github.head_ref}}
wkBranch=${branch:-${{github.ref_name}}}
echo ${wkBranch}
echo "tgtBranch=${wkBranch}" >> $GITHUB_OUTPUT
- name: commit
id: commit
uses: yui-Kitamura/commit@2.0.1
with:
files: |
${{steps.add.outputs.file}}
commit-message: build jar file by GitHubAction(maven.yml) [skip ci]
ref: refs/heads/${{steps.add.outputs.tgtBranch}}
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: create-commit-comment-orgCmt
uses: peter-evans/commit-comment@v2
with:
sha: ${{ needs.build.outputs.targetSha }}
body: |
build generated jar file on ${{ steps.commit.outputs.commit-sha }}
- Created by [commit-comment](https://github.com/marketplace/actions/commit-comment)
- name: create-commit-comment-jarCmt
uses: peter-evans/commit-comment@v2
with:
sha: ${{ steps.commit.outputs.commit-sha }}
body: |
build generated jar file on ${{ needs.build.outputs.targetSha }}
- Created by [commit-comment](https://github.com/marketplace/actions/commit-comment)
outputs:
targetJarName: ${{steps.add.outputs.file}}