Skip to content

Java CI with Maven #623

Java CI with Maven

Java CI with Maven #623

# 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: Java CI with Maven
on:
workflow_dispatch:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '1 10 * * *'
push:
branches:
- main
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8.0.212
uses: actions/setup-java@v3
with:
java-version: 8.0.212
distribution: 'zulu'
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Run Java Application
run: java -jar target/bing-wallpaper-jar-with-dependencies.jar
- name: Save Maven cache
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
- name: Commit files
env:
GIT_USERNAME: ${{ secrets.GIT_USERNAME }}
GIT_EMAIL: ${{ secrets.GIT_EMAIL }}
MY_GIT_TOKEN: ${{ secrets.MY_GIT_TOKEN }}
run: |
git config --global user.name $GIT_USERNAME
git config --global user.email $GIT_EMAIL
git pull
if ! git diff --quiet --exit-code; then
git add README.md
git add bing-wallpaper.md
git add picture/*
git add docs/*
git commit -m "update readme.md"
PUSH_OUTPUT=$(git push 2>&1)
echo "$PUSH_OUTPUT"
NEW_COMMIT_SHA=$(echo "$PUSH_OUTPUT" | grep -oP '\S+ -> \S+' | awk '{print $1}')
echo "NEW_COMMIT_SHA=$NEW_COMMIT_SHA" >> $GITHUB_ENV
fi
build_and_deploy_job:
runs-on: ubuntu-latest
needs: build
name: Build and Deploy Job
steps:
- uses: actions/checkout@v3
with:
ref: main
submodules: true
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_YELLOW_MUSHROOM_020DA8100 }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: "docs"