πŸ–₯️ λ°±μ—”λ“œ/CICD

[CICD] κΉƒν—™ 레포 생성 μžλ™ν™”

OR15A 2024. 3. 23. 00:51

 

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을 κ°•μ œλ‘œ μ‹€ν–‰ν•  수 있음