Skip to content

Merge branch 'main' of https://github.com/bsideproject/14_3_BE #62

Merge branch 'main' of https://github.com/bsideproject/14_3_BE

Merge branch 'main' of https://github.com/bsideproject/14_3_BE #62

Workflow file for this run

# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
name: Maven Package
on:
push:
branches: ['main']
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
# - uses: actions/checkout@v3
# - name: Set up JDK 17
# uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
# distribution: 'temurin'
server-id: 14_3 # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Publish to GitHub Packages Apache Maven
env:
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
HOST: ${{ secrets.SERVER_HOST }}
USERNAME: ${{ secrets.SERVER_USERNAME }}
PORT: ${{ secrets.SERVER_PORT }}
# scp -i private_key.pem -P $PORT -o StrictHostKeyChecking=no -r target/*.jar $USERNAME@$HOST:/home/$USERNAME/
#nohup java -jar /home/$USERNAME/*.jar > /dev/null 2>&1 & disown
run: |
echo "$PRIVATE_KEY" > private_key.pem
chmod 600 private_key.pem
scp -i private_key.pem -P $PORT -o StrictHostKeyChecking=no -r target/*.jar $USERNAME@$HOST:/var/www/html/jars/
ssh -i private_key.pem -p $PORT -o StrictHostKeyChecking=no $USERNAME@$HOST 'bash -s' <<- EOF
pgrep java | xargs kill -9 || true
nohup java -jar /var/www/html/jars/*.jar > /dev/null 2>&1 & disown
exit
EOF
rm -f private_key.pem