๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ–ฅ๏ธ ๋ฐฑ์—”๋“œ/CICD

[CICD] ํ‚ค์›Œ๋“œ ๊ธฐ๋ฐ˜ ์ด์Šˆ ์•Œ๋ฆผ ์ž๋™ํ™”

by OR15A 2024. 3. 23.

 

3. ๊ฐ„๋‹จํ•œ ์›Œํฌํ”Œ๋กœ์šฐ ๋งŒ๋“ค๊ธฐ

 

ํ‚ค์›Œ๋“œ ๊ธฐ๋ฐ˜ ์ด์Šˆ ์•Œ๋ฆผ ์ž๋™ํ™” ๋งŒ๋“ค๊ธฐ
  • ์ด์Šˆ๊ฐ€ ์ƒ์„ฑ๋  ๋•Œ ์‹คํ–‰
    • issue event
    • types: [opened]
  • ํŠน์ • ํ‚ค์›Œ๋“œ๊ฐ€ ํฌํ•จ๋˜๋ฉด ์Šฌ๋ž™์œผ๋กœ ๊ณต์œ ํ•˜๊ธฐ
    • if critical -> ์Šฌ๋ž™์˜ critical-issue ์ฑ„๋„๋กœ ๊ณต์œ 
    • if cormal -> ์Šฌ๋ž™์˜ normal-issue ์ฑ„๋„๋กœ ๊ณต์œ 
    •  
  • ํ‚ค์›Œ๋“œ๋Š” ๋ณ€๋™์‚ฌํ•ญ์ด ์ƒ๊ธธ ์ˆ˜ ์žˆ์Œ

 

๋ณต์žก์„ฑ์„ ์ค„์ด๋Š” ๋ฐฉ๋ฒ•
  • ํ‚ค์›Œ๋“œ ๊ด€๋ฆฌํ•˜๊ธฐ
    • (X) ๊นƒํ—™์•ก์…˜ ์›Œํฌํ”Œ๋กœ์šฐ์—์„œ ๊ด€๋ฆฌ
    • (O) ์™ธ๋ถ€์—์„œ ํ‚ค์›Œ๋“œ ๊ด€๋ฆฌ    ex) keyword.txt
  • slack step ์‚ฌ์šฉ ๊ตฌ์กฐ
    • ํ‚ค์›Œ๋“œ๋งŒํผ ์‚ฌ์šฉํ•˜๋ฉด ๊ด€๋ฆฌ๊ฐ€ ์–ด๋ ค์›€
    • slack step 1๊ฐœ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ
  • ๋™์ผํ•œ ์Šฌ๋ž™ ์›นํ›… ์ด๋ฆ„ ์‚ฌ์šฉํ•˜๊ธฐ
    • ๋™์ผํ•œ ์‹œํฌ๋ฆฟ ์ด๋ฆ„ ์‚ฌ์šฉํ•˜๊ธฐ
    • ${{ secret.SLACK_WEBHOOK }}
  • ๊ตฌ์„ฑ
    • job 2๊ฐœ ์‚ฌ์šฉํ•˜๊ธฐ
      • job-1 : get keyword (keyword-list.txt ์‚ฌ์šฉ. ์ด๋ฅ˜ ์ œ๋ชฉ์ด ํ‚ค์›Œ๋“œ ๋ฆฌ์ŠคํŠธ์— ์žˆ๋‹ค๋ฉด ๊ทธ ๊ฐ’์„ ์•„์›ƒํ’‹์œผ๋กœ ๊ตฌ์„ฑ)
      • job-2 : slack (get keyword์˜ ์•„์›ƒํ’‹์„ ๋ฐ›์•„์„œ environment๋กœ ์‚ฌ์šฉ)
  • ์ด์Šˆ์— ๋Œ€ํ•œ Environment๋งŒ๋“ค๊ธฐ
    • ๊ฐ Envieonmment ์•ˆ์— secret ๋งŒ๋“ค๊ธฐ
    • ์ด์Šˆ ์ฑ„๋„์˜ ํ‚ค์›Œ๋“œ - ์Šฌ๋ž™ ํ•ด๋‹น ์ฑ„๋„ url ๋กœ secret๋งŒ๋“ค๊ธฐ

Environment

name: issue-notify

on:
  issues:
    types: [opened]

jobs:

  get-keyword:
    runs-on: ubuntu-latest
    outputs:
      level: ${{ steps.get-keyword.outputs.level }}
    steps:
    - name: checkout 
      uses: actions/checkout@v4
    - name: get keyword
      id: get-keyword
      run: |
        echo level=Undefined >> $GITHUB_OUTPUT
        
        keywords=$(cat keyword-list.txt)
        for keyword in $keywords; do
          if [[ "${{ github.event.issue.title }}" =~ "$keyword" ]]; then
            echo level=$keyword >> $GITHUB_OUTPUT
          fi
        done
    - name: get output
      run: |
        echo ${{ steps.get-keyword.outputs.level }}
  
  
  slack:
    needs: [get-keyword]
    if: needs.get-keyword.outputs.level != 'Undefined'
    runs-on: ubuntu-latest
    # environment: ${{ needs.get-keyword.outputs.level }}
    strategy:
      matrix:    # ๋งคํŠธ๋ฆญ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์‹œ๊ฐ์ ์œผ๋กœ ์–ด๋–ค ํ™˜๊ฒฝ์„ ์‚ฌ์šฉํ–ˆ๋Š”์ง€ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์Œ
        environment: ["${{ needs.get-keyword.outputs.level }}"]
    environment: ${{ matrix.environment }}
    steps:
    - name: slack 
      uses: slackapi/slack-github-action@v1.24.0
      with:
        payload: |
          {
            "attachments": [
              {
                "pretext": "issue alert message",
                "color": "28a745",
                "fields": [
                  {
                    "title": "Level : ${{ needs.get-keyword.outputs.level }}",
                    "short": true,
                    "value": "issue url : ${{ github.event.issue.html_url }}"
                  }
                ]
              }
            ]
          }
      env:
        SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK