Skip to content

CI CD์™€ Github Action

Youngho Kim edited this page Nov 23, 2022 · 2 revisions
  • ์ž‘์„ฑ์ž: J045_๊น€์˜ํ˜ธ

CI/CD

CI/CD(Continuous Integration / Continuous Delivery ยท Deployment, ์ง€์†์  ํ†ตํ•ฉ ๋ฐ ์ง€์†์  ์ œ๊ณต) ์€ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ž์ฃผ, ์•ˆ์ •์ ์œผ๋กœ ์ฝ”๋“œ ๋ณ€๊ฒฝ์„ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ๋ฌธํ™”์™€ ์šด์˜์›์น™, ์ผ๋ จ์˜ ์ž‘์—… ๋ฐฉ์‹์„ ์˜๋ฏธํ•œ๋‹ค. DevOps ๋ฐ ์• ์ž์ผ ๋ฐฉ๋ฒ•๋ก ์˜ ๊ถŒ์žฅ ์‚ฌํ•ญ์ด๋‹ค.

์šฐ๋ฆฌ์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด ์šฐ๋ฆฌ๊ฐ€ ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผํ•˜๊ณ , ๋นŒ๋“œํ•œ ๋’ค ๋ฐฐํฌ๋ฅผ ๊ฑฐ์ณ์•ผ ํ•œ๋‹ค. ์ด๋ ‡๊ฒŒ ๋ฐฐํฌํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ์˜ค๋ฅ˜ ์œ ๋ฌด๋ฅผ ํŒ๋‹จํ•˜๊ธฐ ์œ„ํ•ด ์—ฌ๋Ÿฌ ํ…Œ์ŠคํŠธ๋ฅผ ๊ฑฐ์น˜๊ณค ํ•ด์•ผํ•œ๋‹ค. ์ด๋Ÿฌํ•œ ๋ฐ˜๋ณต์ ์ด๊ณ , ์‹ค์ˆ˜๊ฐ€ ์ƒ๊ธธ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋Š” ์ž‘์—…๋“ค์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด CI/CD๋ฅผ ํ™œ์šฉํ•œ๋‹ค.

์ด๋ฅผ ํ†ตํ•ด ๊ฐœ๋ฐœํŒ€์€ ์ฝ”๋“œ ํ’ˆ์งˆ๊ณผ ์†Œํ”„ํŠธ์›จ์–ด ๋ณด์•ˆ์„ ๋ณด์žฅํ•จ๊ณผ ๋™์‹œ์— ๋น„์ฆˆ๋‹ˆ์Šค ์š”๊ตฌ์‚ฌํ•ญ์„ ์ถฉ์กฑํ•˜๋Š”๋ฐ ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ๋‹ค.

CI (Continuous Integration)

CI, ์ง€์†์  ํ†ตํ•ฉ์€ ๊ฐœ๋ฐœํŒ€ ๋‚ด์—์„œ ๊ฐ์ž์˜ ์ž‘์—…๋ฌผ์„ ํ•˜๋‚˜๋กœ ํ†ตํ•ฉํ•˜๊ธฐ ์œ„ํ•œ ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ ๋ฐฉ๋ฒ•๋ก ์ด๋‹ค. ๊ฐ ํ†ตํ•ฉ์€ ํ…Œ์ŠคํŠธ๋ฅผ ํฌํ•จํ•œ ์ž๋™ํ™”๋œ ๋นŒ๋“œ๋ฅผ ํ†ตํ•ด ๊ฐ ์ž‘์—…๋ฌผ์„ ๊ฒ€์ฆํ•  ์ˆ˜ ์žˆ๋‹ค. ์ง€์†์  ํ†ตํ•ฉ์ด๋ผ๋Š” ๊ฐœ๋…์€ ์ต์ŠคํŠธ๋ฆผ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ฐœ๋ฐœ ํ”„๋กœ์„ธ์Šค์—์„œ ์œ ๋ž˜ํ•˜์˜€๋‹ค.

CI๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ, ๋ชจ๋“  ๊ฐœ๋ฐœ์ด ์ข…๋ฃŒ๋œ ๋’ค์— ์ปดํŒŒ์ผ/๋นŒ๋“œ/๋ฐฐํฌ๋ฅผ ๊ฑฐ์ณ์•ผ ์˜ค๋ฅ˜ ์—ฌ๋ถ€๋ฅผ ๊ฒ€์ฆํ•˜๊ณ  ์ˆ˜์ •์„ ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. ํ•˜์ง€๋งŒ, CI๋ฅผ ๋„์ž…ํ•จ์œผ๋กœ์จ ๊ฐ ๊ฐœ๋ฐœ์ž๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ณ , ์ด๋ฅผ main ๋ธŒ๋žœ์น˜์— ๋ณ‘ํ•ฉํ•˜์—ฌ ๊ทธ๋•Œ๊ทธ๋•Œ ๋นŒ๋“œํ•จ์œผ๋กœ์จ ๋ฒ„๊ทธ ์œ ๋ฌด๋ฅผ ๋น ๋ฅด๊ฒŒ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ๋‹ค.

์ด๋Ÿฌํ•œ ํ†ตํ•ฉ ๊ณผ์ •, ๋‹ค์‹œ ๋งํ•ด ์ปดํŒŒ์ผ/๋นŒ๋“œ/๋ฐฐํฌ ๊ณผ์ •๊ณผ ํ…Œ์ŠคํŠธ๋ฅผ ์ง์ ‘ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒƒ์€ ์‹œ๊ฐ„ ์†Œ๋ชจ๊ฐ€ ํฌ๊ธฐ ๋•Œ๋ฌธ์—, ์ด๋ฅผ ์ž๋™ํ™”ํ•˜์—ฌ ๋นŒ๋“œ ๊ฐ€๋Šฅ ์—ฌ๋ถ€ / ์˜ค๋ฅ˜ ์œ ๋ฌด๋ฅผ ์ž๋™์œผ๋กœ ๊ฒ€์ฆํ•  ์ˆ˜ ์žˆ๋‹ค.

์ฆ‰, CI๋ฅผ ๋„์ž…ํ•จ์œผ๋กœ์จ ๋ฒ„๊ทธ๋ฅผ ๋น ๋ฅด๊ฒŒ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๊ณ , ์†Œํ”„ํŠธ์›จ์–ด ํ’ˆ์งˆ ๊ฐœ์„  ๋ฐ ์—…๋ฐ์ดํŠธ ๊ฒ€์ฆ ๋ฐ ๋ฆด๋ฆฌ์ฆˆ๋ฅผ ์‹ ์†ํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค.

Martin Fowler๋Š” CI๋ฅผ ์œ„ํ•ด ์ตœ์†Œํ•œ ๋‹ค์Œ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•ด์•ผํ•œ๋‹ค๊ณ  ํ•œ๋‹ค.

  • ๋นŒ๋“œ ์ž๋™ํ™” ๊ตฌ์ถ•
  • ํ…Œ์ŠคํŠธ ์ž๋™ํ™”
  • ์ปค๋ฐ‹ ๋นŒ๋“œ ์†๋„ ํ–ฅ์ƒ
  • ์ฒ˜์Œ๋ถ€ํ„ฐ ํ”„๋กœ์ ํŠธ์— CI ๋„์ž…. ๋นŒ๋“œ ์‹œ๊ฐ„์ด ๊ธธ์–ด์ง€๊ธฐ ์‹œ์ž‘ํ•˜๋ฉด ์ฆ‰์‹œ ์กฐ์น˜๋ฅผ ์ทจํ•  ๊ฒƒ.

CD (Continuous Delivery / Deployment)

CD(Continuous Delivery / Deploy, ์ง€์†์  ์ œ๊ณต / ๋ฐฐํฌ) ๋Š” ์ œ๊ณตํ•  ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ํ•ญ์ƒ ์‹ ๋ขฐ ๊ฐ€๋Šฅํ•œ ์ˆ˜์ค€์—์„œ ๋ฐฐํฌ๋  ์ˆ˜ ์žˆ๋„๋ก ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค.

์ง€์†์  ์ œ๊ณต ์€ ์•ž์„œ CI๋ฅผ ํ†ตํ•ด ์†Œ์Šค์ฝ”๋“œ์˜ ๋นŒ๋“œ ๋ฐ ๋ฒ„๊ทธ ํŒŒ์•…์„ ์„ฑ๊ณต์ ์œผ๋กœ ์ง„ํ–‰ํ•œ ๊ฒฝ์šฐ, ์ด๋ฅผ ์ €์žฅ์†Œ์— ์—…๋กœ๋“œํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•˜์—ฌ, ์ง€์†์  ๋ฐฐํฌ๋Š” ์ €์žฅ์†Œ์— ์—…๋กœ๋“œํ•œ ๊ฒƒ์„ ๋ฐฐํฌํ™˜๊ฒฝ์— ๋ฆด๋ฆฌ์ฆˆํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค.


GitHub Action

Github Action์ด๋ž€

๋นŒ๋“œ์™€ ํ…Œ์ŠคํŠธ, ๋ฐฐํฌ ํŒŒ์ดํ”„๋ผ์ธ์„ ์ž๋™ํ™”ํ•  ์ˆ˜ ์žˆ๋Š” CI/CD ํ”Œ๋žซํผ์ด๋‹ค. ๊ฐ PR์— ๋Œ€ํ•œ ๋นŒ๋“œ์™€ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๊ฑฐ๋‚˜ ๋ณ‘ํ•ฉ๋œ PR์„ ํ”„๋กœ๋•์…˜์œผ๋กœ ๋ฐฐํฌํ•˜๋Š” ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

Github Action์€ DevOps ๊ทธ ์ด์ƒ์„ ๋ฐ”๋ผ๋ณด๊ณ  ์žˆ์œผ๋ฉฐ, ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ๋‹ค๋ฅธ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์„ ๋•Œ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค€๋‹ค. ๊นƒํ—ˆ๋ธŒ๋Š” ๋ฆฌ๋ˆ…์Šค, ์œˆ๋„์šฐ, MacOS ๊ฐ€์ƒ ๋จธ์‹ ์„ ์ด์šฉํ•˜์—ฌ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ณ , ํ˜น์€ ๋…๋ฆฝ์ ์œผ๋กœ ์šด์˜ํ•˜๋Š” ์„œ๋ฒ„๋ฅผ ์—ฐ๊ฒฐํ•˜์—ฌ ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.

GitHub Action ๊ตฌ์„ฑ์š”์†Œ

ํŠน์ • ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ๊นƒํ—™ ์•ก์…˜ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๊ฒฝ์šฐ, ๊ฐ ์›Œํฌํ”Œ๋กœ์šฐ๋Š” ๋ณ‘๋ ฌ์ ์œผ๋กœ, ํ˜น์€ ์ ˆ์ฐจ์ ์œผ๋กœ ์‹คํ–‰ํ•  ํ•˜๋‚˜ ์ด์ƒ์˜ Job์„ ๊ฐ–๋Š”๋‹ค. ๊ฐ Job๋“ค์€ Runner๋ผ๊ณ  ๋ถ€๋ฅด๋Š” ๊ฐ€์ƒ ๋จธ์‹ , ํ˜น์€ Container ๋‚ด์—์„œ ๋™์ž‘ํ•˜๋ฉฐ, Job๋“ค์€ ๊ฐ๊ฐ ํ•˜๋‚˜ ์ด์ƒ์˜ Step๋“ค์„ ๊ฐ–๋Š”๋‹ค. Step์€ ์ž‘์„ฑํ•œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜๊ฑฐ๋‚˜, ์›Œํฌํ”Œ๋กœ์šฐ ๊ฐ„์†Œํ™”๋ฅผ ์œ„ํ•ด Action ์ด๋ผ๋Š” ์žฌ์‚ฌ์šฉ ์ต์Šคํ…์…˜์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ทธ๋ฆผ) Github Action Workflow ( ์ถœ์ฒ˜: https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions )

๊ทธ๋ฆผ) Github Action Workflow (์ถœ์ฒ˜: https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions)

1. Workflow

ํ•˜๋‚˜ ์ด์ƒ์˜ Job๋“ค์„ ์‹คํ–‰ํ•˜๋Š”, ์„ค์ • ๊ฐ€๋Šฅํ•œ ์ž๋™ํ™” ํ”„๋กœ์„ธ์Šค๋ฅผ ์˜๋ฏธํ•œ๋‹ค. ์ด๋“ค์€ ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋‚ด์˜ YAML ํŒŒ์ผ๋กœ ์ •์˜ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋‚ด์—์„œ ๋ฐœ์ƒํ•œ ์ด๋ฒคํŠธ์— ์˜ํ•ด ์‹คํ–‰๋˜๊ฑฐ๋‚˜, ์ง€์ •ํ•œ ์‹œ๊ฐ„์—, ํ˜น์€ ์ˆ˜๋™์œผ๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋“ค์€ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ .github/workflows ์— ์ €์žฅํ•˜๋ฉฐ, 1๊ฐœ ์ด์ƒ ์กด์žฌํ•  ์ˆ˜ ์žˆ๋‹ค.

2. Events

์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š”, ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋‚ด์—์„œ์˜ ํŠน์ • ํ™œ๋™/๋™์ž‘(Activity)์„ ์˜๋ฏธํ•œ๋‹ค. Github์—์„œ PR์„ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜, ์Šค์ผ€์ฅด์— ๋”ฐ๋ผ ์‹คํ–‰ํ•˜๊ฑฐ๋‚˜, ์ˆ˜๋™์œผ๋กœ ์ด๋ฒคํŠธ๋ฅผ ์ผ์œผํ‚ฌ ์ˆ˜๋„ ์žˆ๋‹ค.

3. Jobs

๊ฐ™์€ Runner์—์„œ ์‹คํ–‰๋˜๋Š”, ์›Œํฌํ”Œ๋กœ์šฐ ๋‚ด์— ์กด์žฌํ•˜๋Š” Step ์ง‘ํ•ฉ์„ ์˜๋ฏธํ•œ๋‹ค. ๊ฐ Step์€ ์‹คํ–‰ํ•  ์‰˜ ์Šคํฌ๋ฆฝํŠธ๋‚˜ Action์„ ๋œปํ•œ๋‹ค. Step๋“ค์€ ์ˆœ์„œ๋Œ€๋กœ ์‹คํ–‰ํ•˜๋ฉฐ, ๋‹ค๋ฅธ Step์— ์˜์กด์„ฑ์„ ๊ฐ–๋Š”๋‹ค. ๊ฐ Step๋“ค์€ ๊ฐ™์€ Runner์—์„œ ์‹คํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์—, Step ๊ฐ„ ๋ฐ์ดํ„ฐ ๊ณต์œ ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

์ผ๋ฐ˜์ ์œผ๋กœ Job๋“ค์€ ๋‹ค๋ฅธ Job๋“ค๊ณผ์˜ ์˜์กด์„ฑ์„ ๊ฐ–์ง€ ์•Š์ง€๋งŒ, ์˜์กด์„ฑ์„ ๊ฐ–๋„๋ก ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด ๊ฒฝ์šฐ, ์˜์กด์„ฑ์ด ์žˆ๋Š” Job์ด ์ข…๋ฃŒ๋  ๋•Œ๊นŒ์ง€ Job ์‹คํ–‰์„ ๋Œ€๊ธฐํ•œ๋‹ค.

4. Actions

๋ณต์žกํ•˜๊ณ  ์ž์ฃผ ๋ฐ˜๋ณตํ•˜๋Š” ์ž‘์—…์„ ์‹คํ–‰ํ•˜๋Š”, Github Action์„ ์œ„ํ•œ ์‚ฌ์šฉ์ž ์ •์˜ Application์ด๋‹ค. ์ด๋Š” ์žฌ์‚ฌ์šฉ์„ ํ†ตํ•ด ์›Œํฌํ”Œ๋กœ์šฐ์—์„œ์˜ ๋ฐ˜๋ณต์ ์ธ ์ฝ”๋“œ ์ž‘์„ฑ์„ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค. ์ด๋ฅผ ์ด์šฉํ•˜๋ฉด Github์—์„œ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ pullํ•˜๊ฑฐ๋‚˜, ๋นŒ๋“œ ํ™˜๊ฒฝ์—์„œ ์“ฐ์ผ toolchain์„ ์„ค์น˜ํ•˜๊ฑฐ๋‚˜, ํด๋ผ์šฐ๋“œ ์ œ๊ณต์ž์— ๋Œ€ํ•œ ์ธ๊ฐ€๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

Action์€ ์ง์ ‘ ์ž‘์„ฑํ•  ์ˆ˜๋„ ์žˆ๊ณ , Github Marketplace์—์„œ ๋‹ค์šด๋กœ๋“œ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

5. Runners

์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์‹คํ–‰ํ•  ์„œ๋ฒ„๋ฅผ ์˜๋ฏธํ•œ๋‹ค. ๊ฐ Runner๋Š” ํ•œ๋ฒˆ์— ๋‹จ ํ•˜๋‚˜์˜ Job๋งŒ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. Github๋Š” ์›Œํฌํ”Œ๋กœ์šฐ ์‹คํ–‰์„ ์œ„ํ•ด ์šฐ๋ถ„ํˆฌ ๋ฆฌ๋ˆ…์Šค, ์œˆ๋„์šฐ, ๋งฅOS ๊ฐ€์ƒ ๋จธ์‹ ์„ ์ œ๊ณตํ•œ๋‹ค. ์ด๋ฅผ ์ด์šฉํ•˜๋ฉด ๊ฐ ์›Œํฌํ”Œ๋กœ์šฐ๋“ค์€ ์ƒˆ๋กœ์šด ๊ฐ€์ƒ ๋จธ์‹  ๋‚ด์—์„œ ๋™์ž‘ํ•œ๋‹ค. Github๋Š” ๊ฑฐ๋Œ€ํ•œ ์„ค์ •์„ ์œ„ํ•ด large runner๋ฅผ ์ œ๊ณตํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

๋งŒ์•ฝ ์œ„์—์„œ ์ œ๊ณตํ•˜๋Š” OS ์™ธ์— ๋‹ค๋ฅธ ๊ฒƒ์„ ์“ฐ๊ณ ์ž ํ•˜๊ฑฐ๋‚˜, ํŠน์ • ํ•˜๋“œ์›จ์–ด ์„ค์ •์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ง์—… Runner๋ฅผ ์„ธํŒ…ํ•˜์—ฌ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

Workflow ์ž‘์„ฑ์— ๋Œ€ํ•˜์—ฌ

ํ•˜๋‹จ์˜ yaml ํŒŒ์ผ์„ ๊ธฐ์ค€์œผ๋กœ ๋ณด์ž.

name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
  check-bats-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '14'
      - run: npm install -g bats
      - run: bats -v
  • name (Optional)
    • Github Action ํƒญ์—์„œ ๋ณด์—ฌ์งˆ ์›Œํฌํ”Œ๋กœ์šฐ ์ด๋ฆ„
  • run-name (Optional)
    • Github Action ํƒญ์—์„œ ๋ณด์—ฌ์งˆ ์›Œํฌํ”Œ๋กœ์šฐ Run ์ด๋ฆ„
  • on
    • ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์œ„ํ•œ Trigger(Event)๋ฅผ ์ •์˜ํ•œ๋‹ค.
    • ์œ„์˜ ์˜ˆ์‹œ์˜ ๊ฒฝ์šฐ push ๊ฐ€ ๋ฐœ์ƒํ•  ๋•Œ๋งˆ๋‹ค, PR์„ Mergeํ•  ๋•Œ๋งˆ๋‹ค ์›Œํฌํ”Œ๋กœ์šฐ๊ฐ€ ์‹คํ–‰๋œ๋‹ค. ๋ณ„๋‹ค๋ฅธ Branch๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ๋ชจ๋“  ๋ธŒ๋žœ์น˜์— ๋Œ€ํ•œ push์— ๋Œ€ํ•ด ์›Œํฌํ”Œ๋กœ์šฐ๊ฐ€ ์‹คํ–‰๋œ๋‹ค.
  • jobs
    • ํ•ด๋‹น ์›Œํฌํ”Œ๋กœ์šฐ ๋‚ด์—์„œ ์‹คํ–‰ํ•  Job ๋ชฉ๋ก์„ ์ •์˜ํ•œ๋‹ค.
  • check-bats-version (job ๋ช…์นญ)
    • โ€˜check-bats-versionโ€™์ด๋ผ๋Š” job์„ ์ •์˜ํ•œ๋‹ค.
    • ํ•˜์œ„์— ์ •์˜๋˜๋Š” ๊ฒƒ๋“ค์€ ํ•ด๋‹น job์˜ property๋ฅผ ์˜๋ฏธํ•œ๋‹ค.
    • runs-on
    • steps
      • ์†ํ•œ Job ๋‚ด์—์„œ ์‹คํ–‰ํ•  ๋ชจ๋“  step๋“ค์„ ์ •์˜ํ•œ๋‹ค. ๊ฐ job๋“ค์€ ๊ฐœ๋ณ„ action์ด๊ฑฐ๋‚˜ ์‰˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋œปํ•œ๋‹ค.
      • -use
        • job ๋‚ด์—์„œ step์œผ๋กœ์จ ์‚ฌ์šฉํ•  Action์„ ์ง€์ •ํ•œ๋‹ค. ์ด๋ฅผ ์ด์šฉํ•˜๋ฉด ๋ณธ์ธ์˜ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ์ •์˜ํ•œ Action์„ ์›Œํฌํ”Œ๋กœ์šฐ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, ๊ณต๊ฐœ ๋ ˆํฌ์ง€ํ† ๋ฆฌ, ํ˜น์€ Docker ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€ ๋‚ด์— ์ •์˜๋œ Action์„ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

        • ์ด๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ๋ฐ˜๋“œ์‹œ(๊นŒ์ง€๋Š” ์•„๋‹ˆ์ง€๋งŒ) ์‚ฌ์šฉํ•  Action์˜ ๋ฒ„์ „์„ ํ•จ๊ป˜ ์ ์–ด์•ผํ•œ๋‹ค. ๋ฒ„์ „์ด ์ œ๊ณต๋˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, ์˜๋„ํ•˜์ง€ ์•Š์€ ๋™์ž‘์ด ๋ฐœ์ƒํ•˜๊ฑฐ๋‚˜ ์›Œํฌํ”Œ๋กœ์šฐ๊ฐ€ ๊นจ์งˆ ์ˆ˜ ์žˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ Version์€ Git Ref, SHA, Docker ํƒœ๊ทธ๋กœ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

          steps:
            # Reference a specific commit
            - uses: actions/checkout@a81bbbf8298c0fa03ea29cdc473d45769f953675
            # Reference the major version of a release
            - uses: actions/checkout@v3
            # Reference a specific version
            - uses: actions/checkout@v3.2.0
            # Reference a branch
            - uses: actions/checkout@main
        • ์ผ๋ถ€ Action๋“ค์€ with ํ‚ค์›Œ๋“œ๋ฅผ ํ†ตํ•ด ์ž…๋ ฅ์„ ์š”๊ตฌํ•˜๊ธฐ๋„ ํ•œ๋‹ค. ์˜ˆ์‹œ์˜ - uses: actions/setup-node@v3 ๊ฐ€ ๊ทธ๋Ÿฌํ•œ ๊ฒƒ์œผ๋กœ, ์ด๋Š” ์„ค์น˜ํ•  node ๋ฒ„์ „์„ with๋กœ ์ œ๊ณตํ•ด์ฃผ์–ด์•ผ๋งŒ ํ•œ๋‹ค.

        • Action๋“ค์€ JS File์ด๋‚˜ Docker Container ์ด๋‹ค. Docker๋ฅผ ์“ฐ๋Š” ๊ฒฝ์šฐ ์‹คํ–‰ ํ™˜๊ฒฝ์€ ๋ฆฌ๋ˆ…์Šค๊ฐ€ ๋˜์–ด์•ผ๋งŒ ํ•œ๋‹ค.

        • https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses

      • -run

Action ์ถ”๊ฐ€ ๋ฐฉ๋ฒ•

1. Marketplace Action ํ™œ์šฉ

Github์˜ Workflow Editor ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๋ฉด ์‚ฌ์ด๋“œ๋ฐ”์— Marketplace์—์„œ ์•ก์…˜์„ ๊ฒ€์ƒ‰ํ•  ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ฐพ์€ Action์—์„œ Installation ํ•˜์œ„์˜ ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ ๊ทธ๋Œ€๋กœ ๋ถ™์—ฌ๋„ฃ์œผ๋ฉด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹ค๋งŒ ํ•ด๋‹น ๋ฐฉ๋ฒ•์œผ๋กœ Action์„ ์ด์šฉํ•  ๊ฒฝ์šฐ with๋กœ ์ž…๋ ฅ์„ ๋ฐ›๋Š”์ง€ ๋ฐ˜๋“œ์‹œ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค.

2. ๋™์ผ ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋‚ด ์ปค์Šคํ…€ Action ํ™œ์šฉ

๋™์ผ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ ๊ฒฝ์šฐ {owner}/{repo}@{ref} ํ˜น์€ ./path/to/dir ํ˜•์‹์œผ๋กœ ์ž‘์„ฑํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งŒ์•ฝ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํŒŒ์ผ ๊ตฌ์กฐ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

|-- hello-world (repository)
|   |__ .github
|       โ””โ”€โ”€ workflows
|           โ””โ”€โ”€ my-first-workflow.yml
|       โ””โ”€โ”€ actions
|           |__ hello-world-action
|               โ””โ”€โ”€ action.yml
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # This step checks out a copy of your repository.
      - uses: actions/checkout@v3
      # This step references the directory that contains the action.
      - uses: ./.github/actions/hello-world-action

์ด๋•Œ action.yml์€ ์•ก์…˜์— ๋Œ€ํ•œ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋ฅผ ์ œ๊ณตํ•œ๋‹ค. ๋ฌธ๋ฒ•์€ ๋‹ค์Œ์„ ์ฐธ๊ณ ํ•œ๋‹ค. ("[Metadata syntax for GitHub Actions](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions).")

3. ๋‹ค๋ฅธ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ ์ปค์Šคํ…€ Action ํ™œ์šฉ

์ด ๊ฒฝ์šฐ {owner}/{repo}@{ref} ํ˜•์‹์œผ๋กœ ๊ฐ€์ ธ๋‹ค ์“ธ ์ˆ˜ ์žˆ๋‹ค. ์ด๋•Œ, Action์€ ๊ณต๊ฐœ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ์ €์žฅ๋œ ๊ฒƒ๋งŒ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

jobs:
  my_first_job:
    steps:
      - name: My first step
        uses: actions/setup-node@v3

4. Docker Hub ์ƒ์˜ ์ปจํ…Œ์ด๋„ˆ ์ฐธ์กฐ

๋งŒ์•ฝ Docker Hub์— ๋ฐฐํฌ๋œ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€ ๋‚ด์— ์ •์˜๋œ Action์„ ํ™œ์šฉํ•  ๊ฒฝ์šฐ, docker://{image}:{tag} ํ˜•์‹์œผ๋กœ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. ๋ณดํ†ต ์ด๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์ „์— Docker container image์˜ ์ •ํ•ฉ์„ฑ์„ ๊ฒ€ํ† ํ•ด๋ด์•ผ ํ•œ๋‹ค.

jobs:
  my_first_job:
    steps:
      - name: My first step
        uses: docker://alpine:3.8

Action์— Input / Output ์ œ๊ณต

์ข…์ข… Action์€ ์ž…๋ ฅ์ด ํ•„์š”ํ•˜๊ฑฐ๋‚˜, ์ถœ๋ ฅ์„ ํ•ด์•ผํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค. ์ด ๊ฒฝ์šฐ ๊ฐ Action์˜ action.yml / action.yaml ํŒŒ์ผ์—์„œ ๋ฌด์—‡์„ ํ•„์š”๋กœ ํ•˜๊ณ , ๋ฌด์—‡์„ ์ถœ๋ ฅํ•˜๋Š”์ง€ ์ •์˜ํ•œ๋‹ค. ์•„๋ž˜์˜ ์˜ˆ์‹œ๋Š” file-path ์ž…๋ ฅ์„ ์ •์˜ํ•˜๋ฉฐ, results-file ์ถœ๋ ฅ์„ ์ •์˜ํ•œ๋‹ค.

name: "Example"
description: "Receives file and generates output"
inputs:
  file-path: # id of input
    description: "Path to test script"
    required: true
    default: "test-file.js"
outputs:
  results-file: # id of output
    description: "Path to results file"

์›Œํฌํ”Œ๋กœ์šฐ์— ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ ์–ธ

Github Action์—๋Š” ๊ฐ ์›Œํฌํ”Œ๋กœ์šฐ๊ฐ€ ์‹คํ–‰๋  ๋•Œ ์“ฐ์ผ ๊ธฐ๋ณธ ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ์ œ๊ณต๋œ๋‹ค. ๋งŒ์•ฝ ์ง์ ‘ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์ •์˜ํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฒฝ์šฐ, yaml ์›Œํฌํ”Œ๋กœ์šฐ ํŒŒ์ผ์— ์ด๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค. ํ™˜๊ฒฝ๋ณ€์ˆ˜๋Š” ์›Œํฌํ”Œ๋กœ์šฐ ์ „์—ญ(env), ํ˜น์€ ํŠน์ • Job(jobs.<job_id>.env), ํŠน์ • Step(jobs.<job_id>.step[*].env)์— ๋Œ€ํ•ด ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค. (dotenv๋ฅผ ์“ฐ๋Š” ๊ฒฝ์šฐ๋Š” ์ด๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๊ฒ€ํ† ํ•ด๋ณผ ๊ฒƒ.)

name: Greeting on variable day

on:
  workflow_dispatch

env:
  DAY_OF_WEEK: Monday

jobs:
  greeting_job:
    runs-on: ubuntu-latest
    env:
      Greeting: Hello
    steps:
      - name: "Say Hello Mona it's Monday"
        run: echo "$Greeting $First_Name. Today is $DAY_OF_WEEK!"
        env:
          First_Name: Mona

Job ๊ฐ„ ๋ฐ์ดํ„ฐ ๊ณต์œ 

๋งŒ์•ฝ Job์ด ์ƒ์„ฑํ•œ file์„ ๋‹ค๋ฅธ Job์—์„œ๋„ ์“ฐ๊ณ ์ž ํ•˜๊ฑฐ๋‚˜, ๋‚˜์ค‘์— ์ด๋ฅผ ์‚ฌ์šฉํ•˜๊ณ ์ž ๋‹ค๋ฅธ ๊ณณ์— ์ €์žฅํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด, ์ด๋ฅผ GitHub์— Artifacts๋กœ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Š” ์ฝ”๋“œ๋ฅผ ๋นŒ๋“œ/ํ…Œ์ŠคํŠธํ•  ๋•Œ ์ƒ์„ฑ๋œ ํŒŒ์ผ๋“ค์„ ์˜๋ฏธํ•œ๋‹ค. ๊ฐ ์•„ํ‹ฐํŽ™ํŠธ๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ/ํŒจํ‚ค์ง€ ํŒŒ์ผ์ผ ์ˆ˜๋„ ์žˆ๊ณ , ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ์ด๊ฑฐ๋‚˜, ์Šคํฌ๋ฆฐ์ƒท, ๋˜๋Š” ๋กœ๊ทธ ํŒŒ์ผ์ผ ์ˆ˜ ์žˆ๋‹ค. ์ด๋“ค์€ ์ž์‹ ๋“ค์„ ์ƒ์„ฑํ•˜๋Š”, ํ˜น์€ ์ž์‹ ๋“ค์„ ์‚ฌ์šฉํ•˜๋Š” Job์ด ์กด์žฌํ•˜๋Š” ์›Œํฌํ”Œ๋กœ์šฐ ์‹คํ–‰๊ณผ ์—ฐ๊ด€๋˜์–ด์žˆ๋‹ค. ํ•˜๋‚˜์˜ ์‹คํ–‰์— ์กด์žฌํ•˜๋Š” ๋ชจ๋“  Action๊ณผ ์›Œํฌํ”Œ๋กœ์šฐ๋Š” ํ•ด๋‹น ์‹คํ–‰์— ๋Œ€ํ•œ Artifact์— ๋Œ€ํ•œ ์“ฐ๊ธฐ ์ ‘๊ทผ ๊ถŒํ•œ์„ ๊ฐ–๋Š”๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ๊ฒฐ๊ณผ ํŒŒ์ผ์„ Artifact๋กœ ์—…๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋‹ค.

jobs:
  example-job:
    name: Save output
    steps:
      - shell: bash
        run: |
          expr 1 + 1 > output.log
      - name: Upload output file
        uses: actions/upload-artifact@v3
        with:
          name: output-log-file
          path: output.log

Artifact๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ง€์ •ํ•˜์—ฌ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹ค๋งŒ ์ด ๊ฒฝ์šฐ with ํ‚ค์›Œ๋“œ๋กœ ๋‹ค์šด๋กœ๋“œํ•  Artifact์˜ ์ด๋ฆ„์„ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ๋งŒ ํ•œ๋‹ค. ์•„๋ž˜์˜ ์˜ˆ์‹œ์˜ ๊ฒฝ์šฐ output-log-file์„ ๋‹ค์šด๋กœ๋“œํ•œ๋‹ค.

jobs:
  example-job:
    steps:
      - name: Download a single artifact
        uses: actions/download-artifact@v3
        with:
          name: output-log-file

์ฃผ์˜ํ•  ๊ฒƒ์€, ํ•œ ์‹คํ–‰ ๋‹จ์œ„ ๋‚ด์—์„œ ๊ฐ™์€ Artifact์— ๋Œ€ํ•œ ์—…๋กœ๋“œ์™€ ๋‹ค์šด๋กœ๋“œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด, ๋‹ค์šด๋กœ๋“œํ•˜๋Š” Job์€ ์—…๋กœ๋“œํ•˜๋Š” Job์— ๋Œ€ํ•œ ์˜์กด์„ฑ์„ ์ •์˜ํ•ด์•ผ๋งŒ ํ•œ๋‹ค. ์ด๋Š” jobs.<job_id>.needs: [Artifact Upload Job Id]๋ฅผ ํ†ตํ•ด ์ •์˜ํ•œ๋‹ค. ([์ฐธ๊ณ ](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idneeds))

๐Ÿ“š ๊ทธ๋ผ์šด๋“œ ๋ฃฐ

โœ๏ธ ์ปจ๋ฒค์…˜

๐Ÿง‘โ€๐Ÿซ ๋ฉ˜ํ† ๋ง

๐Ÿ“ ์• ์ž์ผ ํ”„๋กœ์„ธ์Šค

๊ธฐํš
๋ฐ์ผ๋ฆฌ ์Šคํฌ๋Ÿผ
์Šคํ”„๋ฆฐํŠธ ๋ฆฌ๋ทฐ
์Šคํ”„๋ฆฐํŠธ ํšŒ๊ณ 
ํŠธ๋Ÿฌ๋ธ” ์ŠˆํŒ…
๊ธฐํƒ€ ์‚ฐ์ถœ๋ฌผ

๐Ÿ“– ๊ธฐ์ˆ ๋ฌธ์„œ

Week2
Week3
Week4
Week5

๐Ÿ—‚ ์ฐธ๊ณ ๋ฌธ์„œ

Clone this wiki locally