In order to trigger your github action workflow when the change happens in any of your JAVA app files, You can automatically trigger the workflow by adding this line as mentioned here in this Official Github document
on:
push:
branches:
- 'main'
- 'releases/**'
If you want to trigger the workflow when the change happens to specific file in the workflow, You can use the script below:-
on:
push:
branches:
- 'main'
- 'releases/**'
One more option according to this SO thread answer by madhead is to use the method below:-
- uses: stefanzweifel/git-auto-commit-action@v4
Complete github workflow:-
You can find my complete github workflow here
Code:-
name: Build and deploy JAR app to Azure Web App - siliconwebapp098
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Java version
uses: actions/setup-java@v1
with:
java-version: '17'
- name: Build with Maven
run: mvn clean install
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: java-app
path: '${{ github.workspace }}/target/*.jar'
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: java-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'siliconwebapp098'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_163298DB206C4BA8AD04D70825D89253 }}
package: '*.jar'
I tried above github workflow to deploy my Java sample in Azure Web app with runtime set to Java and the workflow was successful, Refer below:-
Output:-

I edited my App.java code and commited it, After the commit, Github action workflow got triggered automatically like below:-

