Skip to content

Update maven.yml

Update maven.yml #119

Workflow file for this run

name: Java CI with Maven and Auto Tagging
on:
push:
branches: [ deploy-aws ]
jobs:
CI:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Configure Environment Variables
run: |
sed -i 's#\${AZURE_STORAGE_CONNECTION_STRING}#'"${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}"'#g' src/main/resources/application.properties
sed -i 's#\${AZURE_STORAGE_CONTAINER_NAME}#'"${{ secrets.AZURE_STORAGE_CONTAINER_NAME }}"'#g' src/main/resources/application.properties
sed -i 's#\${MONGO_PORT}#'"27017"'#g' src/main/resources/application.properties
sed -i 's#\${MONGO_HOST}#'"ubuntu@10.0.0.249"'#g' src/main/resources/application.properties
sed -i 's#\${MONGO_DB}#'"educai"'#g' src/main/resources/application.properties
sed -i 's#\${MONGO_USERNAME}#'"educaiAdmin"'#g' src/main/resources/application.properties
sed -i 's#\${MONGO_PASSWORD}#'"i9lnkPC9U46sOg0"'#g' src/main/resources/application.properties
sed -i 's#\${AZURE_STORAGE_URL}#'"${{ secrets.AZURE_STORAGE_URL }}"'#g' src/main/resources/application.properties
- name: Display application.properties
run: cat src/main/resources/application.properties
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Run tests
run: mvn -B test
# - name: Bump version and push tag
# id: tag_version
# uses: mathieudutour/github-tag-action@v5.6
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# default_bump: patch
# initial_version: '1.0.0' # Sets the initial version if no tags exist
# release_branches: main # Ensures tags are only pushed on the main branch
- name: Upload Artifact
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: application
path: target/*.jar
CD:
needs: [CI]
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: application
path: target/
- name: Deploy to Azure VM
uses: appleboy/scp-action@v0.1.7
with:
host: "54.81.18.205"
username: "ubuntu"
key: ${{ secrets.AWS_SSH_PRIVATE_KEY }}
port: 22
source: "target/*.jar"
target: "/home/educai/java-app"
- name: Move Java App to Docker Container
uses: appleboy/ssh-action@v1.0.3
with:
host: 54.81.18.205
username: ubuntu
key: ${{ secrets.AWS_SSH_PRIVATE_KEY }}
port: 22
script: |
chmod +x /home/educai/script-backend.sh
sh /home/educai/script-backend.sh