Update gradle.yml #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | |
name: Java CI with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build --stacktrace | |
- name: War to Artifact for deploy | |
uses: actions/upload-artifact@v3 | |
with: | |
name: War artifact | |
path: ./build/libs | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: download Artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: War artifact | |
- name: Make directory | |
run: mkdir -p deploy | |
- name: Copy War | |
run: cp ./green_parking_11-0.0.1-SNAPSHOT.war ./deploy/parking.war | |
- name: copy file via ssh password | |
uses: appleboy/scp-action@v0.1.4 | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USER }} | |
password: ${{ secrets.SERVER_PASS }} | |
port: ${{ secrets.PORT }} | |
source: "deploy/parking.war" | |
target: ${{ secrets.target_dir }}/webapps | |
overwrite: "true" | |
- name: File Touch with SSH | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: "ubuntu" | |
key: ${{ secrets.SECRET_KEY }} | |
port: 22 | |
debug: true | |
script: | | |
sudo systemctl stop tomcat9.service | |
sudo cp /var/lib/tomcat9/webapps/parking.war /var/lib/tomcat9/back_webapp/parking.war | |
sudo rm -rf /var/lib/tomcat9/webapps/parking | |
sudo cp /var/lib/tomcat9/webapps/deploy/parking.war /var/lib/tomcat9/webapps/parking.war | |
sudo rm -rf /var/lib/tomcat9/webapps/deploy | |
sudo systemctl restart tomcat9.service | |
sudo systemctl restart apache2 |