Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 27 additions & 45 deletions .github/workflows/spring-cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy on PR Merged to develop
name: CD on PR Merged to develop

on:
pull_request:
Expand All @@ -7,71 +7,53 @@ on:

jobs:
build:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout Repository
uses: actions/checkout@v3

Comment on lines +14 to 16
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

actions/checkout 버전을 v4로 올려야 최신 러너에서 동작합니다.

actionlint 경고대로 v3 러너는 더 이상 권장되지 않습니다. 이미 v4가 GA 상태이므로 바로 교체하는 편이 좋습니다.

-      - name: Checkout Repository
-        uses: actions/checkout@v3
+      - name: Checkout Repository
+        uses: actions/checkout@v4
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Checkout Repository
uses: actions/checkout@v3
- name: Checkout Repository
uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.7)

15-15: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🤖 Prompt for AI Agents
In .github/workflows/spring-cd.yml around lines 14 to 16, the GitHub Actions
workflow uses actions/checkout@v3, which is outdated and not recommended for the
latest runners. Update the version from v3 to v4 by changing the uses line to
actions/checkout@v4 to ensure compatibility and follow best practices.

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle

- name: Grant permission to gradlew
run: chmod +x gradlew
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Build with Gradle
run: ./gradlew build
- name: Grant permission to gradlew
run: chmod +x gradlew

- name: Run tests
run: ./gradlew test
- name: Build with Gradle
run: ./gradlew build

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload JAR as artifact
uses: actions/upload-artifact@v3
with:
name: app-jar
path: build/libs/*.jar

deploy-on-merge:
if: github.event.pull_request.merged == true # ✔ merge된 PR일 때만 실행
deploy:
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
- name: Download JAR artifact
uses: actions/download-artifact@v3
with:
distribution: 'temurin'
java-version: 17

- name: Build with Gradle
run: ./gradlew clean build -x test
name: app-jar

- name: Set up SSH
- name: Set up SSH Agent
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.EC2_SSH_KEY }}

- name: Copy JAR to EC2
run: |
scp -i ${{secrets.EC2_SSH_KEY}} -o StrictHostKeyChecking=no build/libs/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/${{ secrets.EC2_USER }}/app/app.jar
scp -o StrictHostKeyChecking=no app-jar/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/ubuntu/app/app.jar

Comment on lines 50 to 53
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

원격 경로가 사용자 고정값에 의존합니다.

/home/ubuntu/... 경로를 하드코딩하면 secrets.EC2_USERubuntu가 아닐 때 실패합니다. 홈 디렉터리 ~ 를 사용하거나 별도 변수로 빼는 쪽이 안전합니다.

-          scp -o StrictHostKeyChecking=no app-jar/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/ubuntu/app/app.jar
+          scp -o StrictHostKeyChecking=no app-jar/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:~/app/app.jar
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Copy JAR to EC2
run: |
scp -i ${{secrets.EC2_SSH_KEY}} -o StrictHostKeyChecking=no build/libs/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/${{ secrets.EC2_USER }}/app/app.jar
scp -o StrictHostKeyChecking=no app-jar/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/ubuntu/app/app.jar
- name: Copy JAR to EC2
run: |
scp -o StrictHostKeyChecking=no app-jar/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:~/app/app.jar
🤖 Prompt for AI Agents
In .github/workflows/spring-cd.yml around lines 50 to 53, the remote path is
hardcoded to /home/ubuntu/app/app.jar which assumes the user is 'ubuntu'. To fix
this, replace the hardcoded path with a dynamic one using the home directory
shortcut ~ or define a separate variable for the user's home directory, then use
it in the scp command to ensure compatibility when secrets.EC2_USER is not
'ubuntu'.

- name: Restart App with Docker Compose
run: |
ssh -i ${{secrets.EC2_SSH_KEY}} -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
cd /home/${{ secrets.EC2_USER }}/app
ssh -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
cd /home/ubuntu/app
docker compose up -d --force-recreate
EOF
Loading