Skip to content

[feature] CI 워크플로우 실행 결과 slack 알림 전송 구현 #5

[feature] CI 워크플로우 실행 결과 slack 알림 전송 구현

[feature] CI 워크플로우 실행 결과 slack 알림 전송 구현 #5

Workflow file for this run

name: CI Pipeline
on:
pull_request:
branches: [ "dev", "main" ]
permissions:
contents: read
checks: write
pull-requests: write
env:
DB_URL: ${{ secrets.DB_URL }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
SPRING_ACTIVE_PROFILE: ${{ vars.SPRING_ACTIVE_PROFILE }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
FCM_PROJECT_ID: ${{ secrets.FCM_PROJECT_ID }}
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
jobs:
formatting:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Formatting Code with Google Java Style Guide
uses: axel-op/googlejavaformat-action@v3
with:
args: "--replace --aosp"
github-token: ${{ secrets.GITHUB_TOKEN }}
unit-test:
runs-on: ubuntu-latest
permissions: write-all
needs: [formatting]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Gradle Caching
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: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
cache: 'gradle'
- name: Create firebase_admin_sdk_private_key.json from Secrets
run: |
mkdir -p $GITHUB_WORKSPACE/src/main/resources/key
echo "${{ secrets.FIREBASE_ADMIN_SDK_PRIVATE_KEY }}" | base64 --decode > $GITHUB_WORKSPACE/src/main/resources/key/firebase_admin_sdk_private_key.json
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: ./gradlew --info test
- name: Publish Test Report
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: "**/build/test-results/test/TEST-*.xml"
slack-reporting:
runs-on: ubuntu-latest
needs: [ formatting, unit-test ]
if: always()
steps:
- name: Determine final status
id: check_status
run: |

Check failure on line 85 in .github/workflows/ci.yaml

View workflow run for this annotation

GitHub Actions / CI Pipeline

Invalid workflow file

The workflow is not valid. .github/workflows/ci.yaml (Line: 85, Col: 14): Unexpected symbol: '$job'. Located at position 7 within expression: needs[$job].result
results=("build" "test" "deploy")
for job in "${results[@]}"; do
if [[ "${{ needs[$job].result }}" == "failure" || "${{ needs[$job].result }}" == "cancelled" ]]; then
echo "status=failure" >> $GITHUB_ENV
exit 0
fi
done
echo "status=success" >> $GITHUB_ENV
- name: Send Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_MESSAGE: |
*GitHub Actions 결과*
- Repository: ${{ github.repository }}
- Branch: ${{ github.ref }}
- Commit: ${{ github.sha }}
- Result: *${{ env.status }}*
SLACK_COLOR: ${{ env.status == 'success' && 'good' || 'danger' }}