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

[CICD] Github Actions์˜ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ

by OR15A 2024. 3. 22.

 

2. Github Actions์˜ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ

 

1. checkout
  • github repository๋ฅผ ๊ฐ€์ ธ์™€์„œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ์•ก์…˜
  • ๋งˆ์ผ“ํ”Œ๋ ˆ์ด์Šค ๊ณต์‹ ์•ก์…˜
  • ํ•„์š”ํ•œ ํ…Œ์ŠคํŠธ๋‚˜ ๋นŒ๋“œ ์ž‘์—… ๋“ฑ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Œ
  • ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋‚ด์šฉ์„ CICD ์›Œํฌํ”Œ๋กœ์šฐ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ
  • uses ํ‚ค์›Œ๋“œ๋กœ ์•ก์…˜์„ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์Œ
name: checkout
on: workflow_dispatch

jobs:
  no-checkout:
    runs-on: ubuntu-latest
    steps:
    - name: check file list
      run: cat README.md

  checkout:
    runs-on: ubuntu-latest
    steps:
    - name: use checkout action
      uses: actions/checkout@v4
    - name: check file list
      run: cat README.md

checkout
no-checkout
checkout

  • ์ฒซ๋ฒˆ์งธ job์ด ์‹คํŒจํ•œ ์ด์œ ๋Š” checkout ๋ฏธ์‚ฌ์šฉ์œผ๋กœ ๊นƒํ—ˆ๋ธŒ ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ๋ฅผ ๊ฐ€์ ธ์˜ค์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์ž„

 

 

 

 

2. context
  • ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ํ™˜๊ฒฝ์— ๋Œ€ํ•œ ์ •๋ณด
  • ๋‹ค์–‘ํ•œ ์ปจํ…์ŠคํŠธ๊ฐ€ ์กด์žฌํ•จ

๋‹ค์–‘ํ•œ ์ปจํ…์ŠคํŠธ

  • context์˜ ์‚ฌ์šฉ ์ด์œ 
    • ๋” ์œ ์—ฐํ•œ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ
  • ๊ฐ๊ฐ์˜ ์ปจํ…์ŠคํŠธ๋Š” JavaSctript ๊ฐ์ฒด์ด๊ธฐ ๋•Œ๋ฌธ์— ์ถœ๋ ฅ์„ ํ•˜๋ ค๋ฉด ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ํ•ด์ค˜์•ผํ•จ
    • toJSON์ด๋ผ๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ Object๊ฐ์ฒด๋ฅผ Json๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์Œ
  • context.yaml ์˜ˆ์‹œ
name: context
on: workflow_dispatch

jobs:
  context:
    runs-on: ubuntu-latest
    steps:
    - name: github context
      run: echo '${{ toJSON(github)}}'
  • ์ปจํ…์ŠคํŠธ ์•ˆ์— ์–ด๋–ค ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ์ธ์ง€, ์–ด๋–ค run_id ์ธ์ง€ ๋“ฑ ๋‹ค์–‘ํ•œ ์ •๋ณด์„ ์•Œ ์ˆ˜ ์žˆ์Œ

์ •๋ณด

  • context์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•ด๋ณด๊ธฐ
    - name: check github context
      run: |
        echo ${{ github.repository }}
        echo ${{ github.event_name }}

์ •๋ณด ์ถœ๋ ฅ ์„ฑ

 

 

 

 

Filter
  • ์ด๋ฒคํŠธ๊ฐ€ ํŠน์ • ์กฐ๊ฑด์— ๋ถ€ํ•ฉํ•  ๋•Œ๋งŒ ์›Œํฌํ”Œ๋กœ์šฐ๊ฐ€ ํŠธ๋ฆฌ๊ฑฐ ๋˜๋„๋ก ํ•จ
    • ์›Œํฌํ”Œ๋กœ์šฐ ์‹คํ–‰์„ ๋” ํšจ๊ณผ์ ์œผ๋กœ ์ œ์–ดํ•  ์ˆ˜ ์žˆ์Œ

 

 

3. branch filter
  • ํŠน์ • ๋ธŒ๋žœ์น˜ ์ด๋ฒคํŠธ์—๋งŒ ํŠธ๋ฆฌ๊ฑฐ ๋˜๋Š” ์•ก์…˜
name: branch-filter
on: 
  push:
    branches: ["dev"]

jobs:
  branch-filter:
    runs-on: ubuntu-latest
    steps:
    - name: echo
      run: echo hello

 

 

 

4. path filter
  • ํŠน์ • ๊ฒฝ๋กœ์˜ ํŒŒ์ผ์ด ๋ณ€๊ฒฝ๋  ๋•Œ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•จ
  • ! ๋Š” ํŠน์ • ํŒŒ์ผ, ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ œ์™ธํ•  ์ˆ˜ ์žˆ
name: path-filter
on:
  push:
    path:
    - '.github/workflows/part1/*'
    - '!.github/workflows/part1/push.yaml*'

jobs:
  path-filter:
    runs-on: ubuntu-latest
    steps:
    - name: echo hello
      run: echo hello

 

 

 

 

5. tag filter
  • ํŠน์ • ํƒœ๊ทธ์—์„œ ์‹คํ–‰ํ•จ
    • ex) v1.0.0์œผ๋กœ ํƒœ๊น…ํ•ด์•ผ ์‹คํ–‰๋จ
  • push ์ด๋ฒคํŠธ ์—์„œ๋งŒ ์‚ฌ์šฉ ์‚ฌ๋Šฅ
  • ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•
    • git tag <tag-name>

ํƒœ๊ทธ

name: tag-filter
on:
  push:
    tags:
    - 'v[0-9]+.[0-9]+.[0-9]+' # v1.0.0    v2.0.1


jobs:
  tag-filter:
    runs-on: ubuntu-latest
    steps:
    - name: echo 
      run: echo hello

 

 

 

 

6. timeout
  • ํŠน์ • ์‹œ๊ฐ„์ด์ƒ ์‹คํ–‰๋˜๋ฉด ์ž๋™์œผ๋กœ ์ค‘๋‹จ๋˜๋„๋ก ์„ค์ •ํ•˜๋Š” ๊ธฐ๋Šฅ
  • ํŠน์ • job , ํŠน์ • step ๋ฌดํ•œ๋ฃจํ”„๋กœ ์ธํ•œ ๋ถˆํ•„์š”ํ•œ ์ž์› ์†Œ๋ชจ๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•จ
  • default 360๋ถ„
  • ํƒ€์ž„์•„์›ƒ ์ •์˜ ๋ ˆ๋ฒจ : job level, step level
  • timeout-minutes ๋ผ๋Š” ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•จ
name: timeout
on: push

jobs:
  timeout:
    runs-on: ubuntu-latest
    timeout-minutes: 2
    steps:
    - name: loop
      run: |
        count=0
        while true; do
          echo "seconds: $count"
          count=$((count+1))
          sleep 1
        done
      timeout-minutes: 1
    - name: echo
      run: echo hello

 

 

 

 

7. cache
  • ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋น ๋ฅด๊ฒŒ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๋„๋ก ์ €์žฅํ•˜๋Š” ๊ธฐ๋Šฅ
  • ์˜์กด์„ฑ ์„ค์น˜ ์‹œ๊ฐ„์„ ๋‹จ์ถ•์‹œํ‚ฌ ์ˆ˜ ์žˆ์Œ
  • ๊นƒํ—™ ๋งˆ์ผ“ํ”Œ๋ ˆ์ด์Šค์˜ ๊ณต์‹ ์•ก์…˜
  • ๊ฐ•์˜ ์˜ˆ์ œ๋Š” ๋ฆฌ์•กํŠธ - npm start ๋ฅผ ์œ„ํ•ด ์‚ฌ์šฉํ•จ 
name: cache
on:
  push:
    paths:
    - 'my-app/**'    # my-app ํ•˜์œ„์˜ ๋ชจ๋“  ํŒŒ์ผ์„ ํฌํ•จํ•จ

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - name: checkout the code
      uses: actions/checkout@v4    # ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ ์ฒดํฌ์•„์›ƒ ์•ก์…˜
    - name: setup-node
      uses: actions/setup-node@v3    # ์…‹์—… ๋…ธ๋“œ ์•ก์…˜ ์‚ฌ์šฉ
      with:
        node-version: 18     # 18๋ฒ„์ „์˜ ๋…ธ๋“œ๋ฅผ ์ธ์Šคํ†จ ํ•˜๋Š” ์•ก์…˜
    - name: Cache Node.js modules
      uses: actions/cache@v3
      with:    # withํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ธํ’‹๊ฐ™์„ ์ „๋‹ฌํ•จ
        path: ~/.npm    # ์บ์‹ฑํ•  ๊ฒฝ๋กœ
        key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
           	 # ์บ์‹œ์˜ ํ‚ค, ์šด์˜์ฒด์ œ๋ณ„๋กœ ์บ์‹œ๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•ด์„œ
        restore-keys: |
          ${{ runner.os }}-node-    # ๊ฐ ์šด์˜์ฒด์ œ๋ณ„๋กœ ๋งค์‹œ ๊ตฌ๋ฌธ ๊ฐœ์‹œ์˜ ๋ฒ”์ฃผ๋ฅผ ๋‚˜ํƒ€๋ƒ„
    - name: Install dependencies     # ์˜์กด์„ฑ ์„ค์น˜
      run: |
        cd my-app
        npm ci
    - name: npm build    # ๋นŒ๋“œ์ž‘์—… ์‹คํ–‰
      run: |
        cd my-app
        npm run build
  • 3๋ฒˆ์งธ job์€ ์ดํ›„์— ๊ฐ™์€ ์šด์˜์ฒด์ œ์—์„œ ๋™์ผํ•œ package-lock.json์„ ๊ฐ€์ง„ ์›Œํฌํ”Œ๋กœ์šฐ๊ฐ€ ์‹คํ–‰๋  ๋•Œ ์ด์ „์— ์ €์žฅํ–ˆ๋˜ ์บ์‹œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์˜์กด์„ฑ ์„ค์น˜๋ฅผ ๋น ๋ฅด๊ฒŒ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์คŒ

 

 

 

8. artifact
  • ์›Œํฌํ”Œ๋กœ์šฐ ์‹คํ–‰ ์ค‘ ์ƒ์„ฑ๋œ ํŒŒ์ผ/ํŒŒ์ผ๋ชจ์Œ
  • ๋™์ผํ•œ ์›Œํฌํ”Œ๋กœ์šฐ ๋‚ด์—์„œ job ์‚ฌ์ด์— ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ•˜๋Š” ๊ฒƒ
  • ์›Œํฌํ”Œ๋กœ์šฐ๊ฐ€ ์ข…๋ฃŒ๋œ ์ดํ›„์—๋„ ์ผ์ •๊ธฐ๊ฐ„๋™์•ˆ ๋ฐ์ดํ„ฐ๋ฅผ ์œ ์ง€ํ•จ(90์ผ)
  • ๋‹ค์šด๋กœ๋“œ๋„ ๊ฐ€๋Šฅํ•จ
  • ๊นƒํ—™ ๋งˆ์ผ“ํ”Œ๋ ˆ์ด์Šค์— ์ •์˜๋œ ๊ณต์‹ ์•ก์…˜
    • upload-artifact
    • download-artifact
name: artifact
on: push

jobs:
  upload-artifact:
    runs-on: ubuntu-latest
    steps:
    - name: echo 
      run: echo hello-world > hello.txt   # ํ…์ŠคํŠธํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ , ๋ฌธ์ž์—ด ์ง‘์–ด๋„ฃ๊ธฐ
    - name: upload artifact
      uses: actions/upload-artifact@v3    # upload-artifact ์•ก์…˜์„ ์ด์šฉํ•ด์„œ hello.txtํŒŒ์ผ์„
      with: 	                          # artifact๋กœ ์—…๋กœ๋“œํ•จ
        name: artifact-test
        path: ./hello.txt

  download-artifact:
    runs-on: ubuntu-latest
    needs: [upload-artifact]
    steps:
    - name: download artifact
      uses: actions/download-artifact@v3
      with:
        name: artifact-test
        path: ./
    - name: check
      run: cat hello.txt

 

 

 

9. output
  • ํ•œ job์—์„œ ์ƒ์„ฑ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๋™์ผํ•œ job์˜ step์ด๋‚˜, ๋‹ค๋ฅธ job ๋“ค๊ณผ ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ•˜๊ฒŒ ํ•ด์คŒ
  • ์—ฌ๋Ÿฌ step๊ณผ job ๊ฐ„์— ๋ฐ์ดํ„ฐ๋ฅผ ์†์‰ฝ๊ฒŒ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ์Œ
  • outfut vs artifact
    • outfut : ๋‹จ์ˆœํ•œ ๊ฐ’ ์ „๋‹ฌํ•  ๋•Œ ์‚ฌ์šฉํ•จ, key-value ํ˜•ํƒœ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•จ
    • artifact : ํŒŒ์ผ ๋˜๋Š” ํŒŒ์ผ ๋ชจ์Œ์œผ๋กœ ๋ฐ์ดํ„ฐ ๊ณต์œ  ๊ฐ€๋Šฅํ•จ, ํŒŒ์ผ๊ธฐ๋ฐ˜ ๋ฐ์ดํ„ฐ ๊ณต์œ ์‹œ ์‚ฌ์šฉํ•˜๊ธฐ
  • ์‚ฌ์šฉ ๊ตฌ์กฐ

  • ์„ค์ •ํ•œ ์•„์›ƒํ’‹ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•
    • ์•„์›ƒํ’‹์ด ์ •์˜๋œ ์Šคํ…์˜ ๊ณ ์œ  id๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•จ
  • ๊ฐ ์Šคํ…์€ ๊ณ ์œ ํ•œ ์•„์ด๋””๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ์•„์›ƒํ’‹์„ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ์Œ
  • ์ถœ๋ ฅ ๋ฐฉ๋ฒ•
    • steps.์Šคํƒญ_์•„์ด๋””.outputs.์•„์›ƒํ’‹_ํ‚ค
  • ์ฒซ๋ฒˆ์งธ ์Šคํƒญ์—์„œ ์•„์›ƒํ’‹ ์„ค์ •์„ ํ•˜๊ณ , ๋‘๋ฒˆ์งธ ์Šคํƒญ์—์„œ ์•„์›ƒํ’‹์„ ์ถœ๋ ฅํ•จ

  • job ํ˜•ํƒœ์˜ ์•„์›ƒํ’€๋„ ํ‚ค ๋ฒจ๋ฅ˜ ํ˜•ํƒœ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•จ
  • job ๋ ˆ๋ฒจ์—์„œ ์•„์›ƒํ’‹ ์„ค์ •์„ ์™„๋ฃŒํ•˜๋ฉด, ์ข…์†์„ฑ์ด ์žˆ๋Š” job์€ ํ•ด๋‹น ์•„์›ƒํ’‹์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ

name: output
on: push

jobs:
  create-output:
    runs-on: ubuntu-latest
    outputs:
      test: ${{ steps.check-output.outputs.test }}
    steps:
    - name: echo output
      id: check-output
      run: |
        echo "test=hello" >> $GITHUB_OUTPUT
    - name: check output
      run: |
        echo ${{ steps.check-output.outputs.test }}
  
  get-output:
    needs: [create-output]
    runs-on: ubuntu-latest
    steps:
    - name: get output
      run: echo ${{ needs.create-output.outputs.test }}

 

 

 

 

10. environment variables ๊นƒํ—™์•ก์…˜ ํ™˜๊ฒฝ๋ณ€์ˆ˜
  • step์ด๋‚˜ job์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜
  • key - value ํ˜•ํƒœ๋กœ ๋ฐ์ดํ„ฐ ์ €์žฅํ•จ
  • ๋™์ผํ•œ job์—์„œ๋งŒ ๋ฐ์ดํ„ฐ ๊ณต์œ ๊ฐ€ ๊ฐ€๋Šฅํ•จ
  • ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๊ตฌ์„ฑ๋ฐฉ๋ฒ•
    • env ์‚ฌ์šฉ : ์›Œํฌํ”Œ๋กœ์šฐ ๋‚ด์—์„œ ์ •์˜ํ•จ. 
      • workflow  ๋ ˆ๋ฒจ,  job ๋ ˆ๋ฒจ, step ๋ ˆ๋ฒจ์—์„œ ์ •์˜ํ•ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ
      • ์šฐ์„ ์ˆœ์œ„ step >> job >> workflow
    • ๋ฏธ๋ฆฌ ์ •์˜  

[ env ์‚ฌ์šฉํ•œ ์ •์˜ ]

workflow &nbsp;๋ ˆ๋ฒจ,&nbsp;&nbsp; job ๋ ˆ๋ฒจ,&nbsp; step ๋ ˆ๋ฒจ์—์„œ ์ •์˜
env

name: var-1
on: push

env:  
  level: workflow  # ์›Œํฌํ”Œ๋กœ์šฐ ๋ ˆ๋ฒจ env ์ •์˜

jobs:
  get-env-1:
    runs-on: ubuntu-latest
    steps:
    - name: check env
      run: echo "LEVEL ${{ env.level }}"
  
  get-env-2:
    runs-on: ubuntu-latest
    env:
      level: job   # ์žก ๋ ˆ๋ฒจ env ์ •์˜
    steps:
    - name: check env
      run: echo "LEVEL ${{ env.level }}"

  get-env-3:
    runs-on: ubuntu-latest
    env:
      level: job
    steps:
    - name: check env
      run: echo "LEVEL ${{ env.level }}"
      env:
        level: step    # ์Šคํ… ๋ ˆ๋ฒจ env ์ •์˜
  
  get-env:
    runs-on: ubuntu-latest
    steps:
    - name: create env
      run: echo "level=job" >> $GITHUB_ENV  # ์ง์ ‘ env ์ •์˜
    - name: check env
      run: echo "LEVEL ${{ env.level }}"

 

[ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋ฏธ๋ฆฌ ์ •์˜ํ•˜๊ธฐ ]

  • ์›Œํฌํ”Œ๋กœ์šฐ ๋ฐ–์—์„œ ๋ฏธ๋ฆฌ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์ •์˜ํ•จ
  • ์ด ๊ฐ’์„ ๋ฐ”๊พธ๋ฉด ์›Œํฌํ”Œ๋กœ์šฐ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ์Œ

  • Settings - security - Actions secrets and variables - Actions -  variables

name: var-2
on: push

jobs:
  get-var: 
    runs-on: ubuntu-latest
    steps:
    - name: get var
      run: echo ${{ vars.level }}

 

 

 

 

11. secrets
  • ๋ฏผ๊ฐํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์•ˆ์ „ํ•˜๊ฒŒ ์ €์žฅํ•ด์„œ ์›Œํฌํ”Œ๋กœ์šฐ์— ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ
  • ๋ฏผ๊ฐ ์ •๋ณด๋ฅผ ์ฝ”๋“œ์™€ ๋ถ„๋ฆฌํ•˜์—ฌ, ๋…ธ์ถœ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•จ
  • ์‚ฌ์šฉ ํ•˜๋Š” ๊ณณ : API Key, ์•”ํ˜ธ, ์ธ์ฆ ํ† ํฐ
  • Settings - security - Actions secrets and variables - Actions -  secrets 

name: secrets
on: push

jobs:
  get-secrets:
    runs-on: ubuntu-latest
    steps:
    - name: get secrets
      run: echo ${{ secrets.level }}

 

 

 

12. environment
  • ํŠน์ • ํ™˜๊ฒฝ์—์„œ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ํ™˜๊ฒฝ๋ณ€์ˆ˜์™€ ์‹œํฌ๋ฆฟ์„ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ
  • Repository์—์„œ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Œ
  • ์ •์˜ ๋ ˆ๋ฒจ : organization level, repository level, environment level

์ •์˜ ๋ ˆ๋ฒจ

 

 

 

 

13. matrix
  • ๋ณ€์ˆ˜๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์—ฌ๋Ÿฌ job์„ ์‹คํ–‰ํ•˜๋Š” ๊ธฐ๋Šฅ
  • matrix๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ•˜๋‚˜์˜ ์žก์„ ๊ตฌ์„ฑํ•˜๋ฉด, ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์žก์„ ์‹คํ–‰ํ•˜๋„๋ก ํ•  ์ˆ˜ ์žˆ
  • ๋ณ€์ˆ˜๋กœ ํ•˜๋‚˜์˜ ์žก์œผ๋กœ ์—ฌ๋Ÿฌ ๋Ÿฌ๋„ˆ(OS)๊ฐ€ ์žก์„  ์‹คํ–‰ํ•˜๊ฒŒ ํ•˜๊ฑฐ๋‚˜, ๊ฐ™์€ ์ฝ”๋“œ ๋ฒ ์ด์Šค์—์„œ  ๊ฐ ๋ฒ„์ „๋ณ„๋กœ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Œ
name: matrix
on: push

jobs:
  get-matrix:
    strategy:
      matrix:
        os: [windows-latest, ubuntu-latest]
        version: [12,14]
    runs-on: ${{ matrix.os }}
    steps:
    - name: check matrix
      run: |
        echo ${{ matrix.os }}
        echo ${{ matrix.version }}

 

 

 

 

14. if condition
  • ํŠน์ • ์กฐ๊ฑด์ด ์ถฉ์กฑ๋  ๋•Œ๋งŒ ์‹คํ–‰๋˜๋„๋ก ํ•  ๋•Œ ์‚ฌ์šฉ
  • ์˜คํผ๋ ˆ์ดํ„ฐ๋ฅผ ์ ์ ˆํžˆ ์‚ฌ์šฉํ•ด์„œ ์กฐ๊ฑด ๊ตฌ์„ฑํ•˜๊ธฐ

์˜คํผ๋ ˆ์ด

  • job ๋ ˆ๋ฒจ, step ๋ ˆ๋ฒจ์—์„œ ์ •์˜ํ•  ์ˆ˜ ์žˆdma
  • filter vs if condition
    • filter : workflow ํŠธ๋ฆฌ๊ฑฐ๋ฅผ ์„ธ๋ฐ€ํ•˜๊ฒŒ ์ œ์–ด (ex-dev๋ธŒ๋žœ์น˜์ผ๋•Œ๋งŒ ํŠธ๋ฆฌ๊ฑฐ)
    • if condition : workflow๊ฐ€ ํŠธ๋ฆฌ๊ฑฐ ๋œ ์ดํ›„ job๊ณผ step๋งŒ ์„ธ๋ฐ€ํ•˜๊ฒŒ ์ œ์–ด (ex-dev ๋ธŒ๋žœ์น˜์ผ๋•Œ๋Š” ์ฒซ๋ฒˆ์งธ job๋งŒ ์‹คํ–‰/ master ๋ธŒ๋žœ์น˜์ผ ๋•Œ ๋‘๋ฒˆ์งธ job์˜ ์„ธ๋ฒˆ์งธ step skipํ•˜๊ธฐ)
name: if-1
on:
  push:
  workflow_dispatch:

jobs:
  job1:
    runs-on: ubuntu-latest
    if: github.event_name == 'push'
    steps:
    - name: get event name
      run: echo ${{ github.event_name }}
  job2:
    runs-on: ubuntu-latest
    if: github.event_name != 'push'
    steps:
    - name: get event name
      run: echo ${{ github.event_name }}
  job3:
    runs-on: ubuntu-latest
    steps:
    - name: get event name
      if: github.event_name == 'push'
      run: echo "PUSH"
    - name: get event name
      if: github.event_name != 'push'
      run: echo "WORKFLOW_DISPATCH"

 

 

 

 

15. startWith, endsWith, contains 
  • ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
  • ๋ฌธ์ž์—ด ์กฐ๊ฑด์„ ๊ฒ€์‚ฌํ•ด์„œ ์กฐ๊ฑด์ด ์ถฉ์กฑ๋˜๋ฉด ํ•ด๋‹น jbob์ด๋‚˜ step์„ ์‹คํ–‰ํ•˜๋„๋ก ์ œ์–ดํ•˜๋Š”๋ฐ ์œ ์šฉ
  • startWith ( searchString, searchValue )
  • endsWith ( searchString, searchValue )
  • contains ( search, item )
    • search๋Š” ๋ฌธ์ž์—ด์ด๋‚˜ ๋ฐฐ์—ด. ๋ฐฐ์—ด์€ ์ฝค๋งˆ๋กœ ๊ตฌ๋ถ„๋œ ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ๋กœ ์ž‘์„ฑ
name: string-function
on: push

jobs:
  string-function:
    runs-on: ubuntu-latest
    steps:
    - name: startswith
      if: startsWith('github actions', 'git')
      run: echo "git"
    - name: startswith
      if: startsWith('github actions', 'test')
      run: echo "test"

    - name: endswith
      if: endsWith('github actions', 'ions')
      run: echo "ions"
    - name: endsWith
      if: endsWith('github actions', 'test')
      run: echo "test"

    - name: contains
      if: contains('github actions', 'act')
      run: echo "contains act"
    - name: contains
      if: contains('github, actions', 'git')
      run: echo "contains git"