Skip to content

Commit 36fc5cc

Browse files
committed
chore(ci-cd): add build yml
1 parent f23bdd1 commit 36fc5cc

File tree

4 files changed

+139
-2
lines changed

4 files changed

+139
-2
lines changed

.github/workflows/build.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# This workflow builds the Spring Boot application and deploys it to VM.
2+
# It is triggered on pushes to the 'main' branch or can be run manually.
3+
4+
name: Build and Deploy to VM
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
11+
# Allows us to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
jobs:
15+
build:
16+
name: Build JAR
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout Code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up JDK 17
24+
uses: actions/setup-java@v4
25+
with:
26+
java-version: '17'
27+
distribution: 'temurin' # A popular, high-quality build of OpenJDK
28+
29+
- name: Cache Maven packages
30+
uses: actions/cache@v4
31+
with:
32+
path: ~/.m2/repository
33+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
34+
restore-keys: |
35+
${{ runner.os }}-maven-
36+
37+
- name: Build with Maven Wrapper
38+
run: |
39+
chmod +x mvnw
40+
./mvnw clean package
41+
42+
- name: Upload JAR artifact
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: app-jar
46+
path: target/leetcode-api-*.jar
47+
retention-days: 1 # We only need this artifact for the next job
48+
49+
deploy:
50+
name: Deploy to VM
51+
runs-on: ubuntu-latest
52+
needs: build # This job will only run if the 'build' job succeeds
53+
54+
steps:
55+
- name: Download JAR artifact
56+
# Download the 'app-jar' artifact that the 'build' job uploaded
57+
uses: actions/download-artifact@v4
58+
with:
59+
name: app-jar
60+
path: . # Download to the current directory
61+
62+
- name: Find JAR file name
63+
# The downloaded file has a version number. We need to find the
64+
# exact file name to use it in the next step.
65+
id: find_jar
66+
run: echo "JAR_NAME=$(ls leetcode-api-*.jar)" >> $GITHUB_OUTPUT
67+
68+
- name: Copy JAR to VM via SCP
69+
70+
uses: appleboy/scp-action@v1.0.3
71+
with:
72+
host: ${{ secrets.VM_HOST }}
73+
username: ${{ secrets.VM_USERNAME }}
74+
key: ${{ secrets.VM_SSH_KEY }}
75+
port: 22
76+
source: ${{ steps.find_jar.outputs.JAR_NAME }}
77+
target: "/opt/leetstats-api" # This is the WorkingDirectory from our systemd file
78+
rename: "app.jar"
79+
80+
- name: SSH and Restart Service
81+
# This action securely logs into our VM and runs the restart commands
82+
uses: appleboy/ssh-action@v1.0.3a
83+
with:
84+
host: ${{ secrets.VM_HOST }}
85+
username: ${{ secrets.VM_USERNAME }}
86+
key: ${{ secrets.VM_SSH_KEY }}
87+
port: 22
88+
script: |
89+
echo "Stopping leetstats-api service..."
90+
sudo systemctl stop leetstats-api
91+
92+
echo "Starting leetstats-api service with new JAR..."
93+
sudo systemctl start leetstats-api
94+
95+
echo "Checking service status..."
96+
sleep 5 # Give the service a moment to start
97+
sudo systemctl status leetstats-api
98+
echo "Deployment complete."
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#-------------------------------------------------------------------------------#
2+
# Discover all capabilities of Qodana in our documentation #
3+
# https://www.jetbrains.com/help/qodana/about-qodana.html #
4+
#-------------------------------------------------------------------------------#
5+
6+
name: Qodana
7+
on:
8+
workflow_dispatch:
9+
pull_request:
10+
push:
11+
branches:
12+
- main
13+
14+
jobs:
15+
qodana:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
pull-requests: write
20+
checks: write
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
ref: ${{ github.event.pull_request.head.sha }}
25+
fetch-depth: 0
26+
- name: 'Qodana Scan'
27+
uses: JetBrains/qodana-action@v2025.2
28+
env:
29+
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
30+
with:
31+
# When pr-mode is set to true, Qodana analyzes only the files that have been changed
32+
pr-mode: false
33+
use-caches: true
34+
post-pr-comment: true
35+
use-annotations: true
36+
# Upload Qodana results (SARIF, other artifacts, logs) as an artifact to the job
37+
upload-result: false
38+
# quick-fixes available in Ultimate and Ultimate Plus plans
39+
push-fixes: 'none'

src/main/java/com/rajat_singh/leetcode_api/scheduler/LeetCodeSyncScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void syncAcRateData() {
109109
Logger.info("LeetCode [AC Rate] sync completed in {} seconds.", (endTime - startTime) / 1000);
110110
}
111111

112-
@Scheduled(cron = "0 31 5 * * ?", zone = "Asia/Kolkata") // Runs every day at 5:31 AM (IST) for POTD sync
112+
@Scheduled(cron = "0 1 0 * * ?") // Runs every day at 12:01 (UTC) for POTD sync
113113
@Async
114114
public void syncPOTD() {
115115
Logger.info("Starting LeetCode [POTD] sync... at {}", DateFormat.getDateInstance().format(System.currentTimeMillis()));

src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ spring:
33
name: leetcode-api
44

55
scheduler:
6-
enabled: false #TODO make it true when deploying via pipeline
6+
enabled: true #change this to true when deploying via pipeline for testing we can keep it false after once the data is loaded in db
77

88
jackson:
99
serialization:

0 commit comments

Comments
 (0)