Merge pull request #186 from FOREGG-DEV/dev #139
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
name: Java CI with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Set YML and FCM Key | |
run: | | |
mkdir -p src/main/resources | |
# Decode application.yml from base64 | |
echo "${{ secrets.APPLICATION_YML }}" | base64 --decode > src/main/resources/application.yml | |
# Decode FCM key content and save it as the specific JSON file | |
echo "${{ secrets.FCM_KEY_PATH_CONTENT }}" | base64 --decode > src/main/resources/foregg-56830-firebase-adminsdk-tgmbx-739218a1a0.json | |
- name: Setup Gradle | |
uses: gradle/actions/[email protected] | |
- name: Build with Gradle Wrapper | |
run: ./gradlew build | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: cicdsample | |
path: build/libs/*.jar | |
dependency-submission: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Generate and submit dependency graph | |
uses: gradle/actions/[email protected] | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: cicdsample | |
- name: Setup SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Add remote server to known hosts | |
run: | | |
mkdir -p ~/.ssh | |
ssh-keyscan ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts | |
- name: SCP transfer | |
run: scp *.jar ${{ secrets.SSH_USERNAME }}@${{ secrets.SERVER_IP }}:~/cicd | |
- name: Execute remote commands | |
run: | | |
ssh -v ${{ secrets.SSH_USERNAME }}@${{ secrets.SERVER_IP }} "sudo fuser -k 8080/tcp || true" | |
ssh -v ${{ secrets.SSH_USERNAME }}@${{ secrets.SERVER_IP }} "sudo nohup /home/shane/.sdkman/candidates/java/current/bin/java -jar ~/cicd/*.jar > ~/cicd/nohup.log 2>&1 &" |