Skip to content

Merge pull request #104 from Azure-Samples/dependabot/npm_and_yarn/ap… #15

Merge pull request #104 from Azure-Samples/dependabot/npm_and_yarn/ap…

Merge pull request #104 from Azure-Samples/dependabot/npm_and_yarn/ap… #15

Workflow file for this run

name: APP CI/CD Pipeline
on:
push:
branches:
- main
paths:
- "app/**"
tags:
- v*.*.*
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
outputs:
env-name: ${{steps.set-deploy-env.outputs.DEPLOY_ENVIRONMENT}}
steps:
- uses: actions/checkout@v2
- name: Set up Java version
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
- name: Set environment for branch
id: set-deploy-env
run: |
echo "checking branch name [${{github.ref_name}}]"
if [[ ${{github.ref_name}} == 'main' ]]; then
echo "main branch detected. Set Development environment"
echo "DEPLOY_ENVIRONMENT=Development" >> "$GITHUB_OUTPUT"
elif [[ ${{github.ref_name}} == *'release'* ]]; then
echo "release branch detected. Set Test environment"
echo "DEPLOY_ENVIRONMENT=Test" >> "$GITHUB_OUTPUT"
elif [[ ${{github.ref_name}} == *'v'* ]]; then
echo "tag detected. Set Production environment"
echo "DEPLOY_ENVIRONMENT=Production" >> "$GITHUB_OUTPUT"
else
echo "branch not detected. Set Development environment as default"
echo "DEPLOY_ENVIRONMENT=Development" >> "$GITHUB_OUTPUT"
fi
- name: Build React Frontend
run: |
echo "Building frontend and merge into spring boot static folder. Environment [${{ steps.set-deploy-env.outputs.DEPLOY_ENVIRONMENT }}]"
cd ./app/frontend
npm install
npm run build
mkdir -p ../backend/src/main/resources/static
cp -r ./build/* ../backend/src/main/resources/static
- name: Verify Indexer project
run: |
echo "Testing indexer project."
cd ./app/indexer
mvn test
- name: Build Spring Boot App
run: |
echo "Building spring boot app. Environment [${{ steps.set-deploy-env.outputs.DEPLOY_ENVIRONMENT }}]"
cd ./app/backend
mvn package
artifactid=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
jarversion=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
originaljarname="$artifactid-$jarversion.jar"
echo "Renaming $originaljarname to app.jar"
# Renaming jar so it is auto detected by app service
mv ./target/$originaljarname ./target/app.jar
- name: Upload artifacts for backend deployment jobs
uses: actions/upload-artifact@v2
with:
name: spring-boot-app
path: |
./app/backend/target/app.jar
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: ${{ needs.build.outputs.env-name}}
url: ${{ steps.deploy-app.outputs.webapp-url }}
steps:
- name: Download backend artifact from build job
uses: actions/[email protected]
with:
name: spring-boot-app
path: ./backend
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: 'Deploy backend to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-app
with:
app-name: ${{ vars.AZUREAPPSERVICE_APP_NAME }}
package: ./backend
- name: logout
run: |
az logout