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

[CICD] ๊นƒํ—™ ๋ ˆํฌ ์ƒ์„ฑ ์ž๋™ํ™”

by OR15A 2024. 3. 23.

 

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

 

๊นƒํ—› ๋ ˆํฌ ์ƒ์„ฑ ์ž๋™ํ™”
name: create-repo
on:
  workflow_dispatch:
    inputs:
      prefix:
        description: 'set repo prefix'
        required: true
        default: 'service'
        type: choice
        options:
        - example
        - service
      name:
        description: 'set repo name'
        required: true
        default: 'github-actions'
        type: string

jobs:
  create-repo-automation:
    runs-on: ubuntu-latest
    steps:
    - name: gh auth login
      run: |
        echo ${{ secrets.PERSONAL_ACCESS_TOKEN }} | gh auth login --with-token
    - name: create-repo
      id: create-repo
      run: |
        gh repo create sangwon-action/${{ inputs.prefix }}-${{ inputs.name }} --public --add-readme
    - name: slack 
      if: always()
      uses: slackapi/slack-github-action@v1.24.0
      with:
        payload: |
          {
            "attachments": [
              {
                "pretext": "create repo result",
                "color": "28a745",
                "fields": [
                  {
                    "title": "create repo result ${{ steps.create-repo.outcome }}",
                    "short": true,
                    "value": "${{ inputs.prefix }}-${{ inputs.name }}"
                  }
                ]
              }
            ]
          }
      env:
        SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
  • ๋ ˆํฌ์ง€ํ† ๋ฆฌ ํ† ํฐ, ์Šฌ๋ž™ ์›น๋ถ url๊ฐ’์„ secret ์œผ๋กœ ์ €์žฅํ•ด์„œ ์‚ฌ์šฉํ•จ
  • ๋ ˆํฌ ์ƒ์„ฑ ์‹œ gh cli (github cli) ์‚ฌ์šฉํ•จ
    • gh cli : ํ„ฐ๋ฏธ๋„์—์„œ github ๊ธฐ๋Šฅ์„ ์ปค๋งจ๋“œ๋กœ ์ œ์–ด ๊ฐ€๋Šฅํ•จ
    • ๋ ˆํฌ์ง€ํ† ๋ฆฌ, ์ด์Šˆ, ํ’€ ๋ฆฌํ€˜์ŠคํŠธ, ๊นƒํ—™ ์•ก์…˜ ๋“ฑ ๊ด€๋ฆฌ
    • ๊นƒํ—™ ๋Ÿฌ๋„ˆ์—์„œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•จ
  • if: always() ์‚ฌ์šฉํ•˜๋ฉด ์ฒซ๋ฒˆ์งธ step์ด ์‹คํŒจํ•˜๋”๋ผ๋„ ๋‘๋ฒˆ์งธ step์„ ๊ฐ•์ œ๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Œ