github ์์๋ github actions ๋ผ๋ ์๋น์ค๋ฅผ ์ด์ฉํด ci/cd ๋ฅผ ์คํํด์ฃผ๊ณ ์์ต๋๋ค. ci/cd ๋ ์ฝ๊ฒ ๋งํ๋ฉด ํ ํ๋ก์ ํธ์์ ์ฝ๋๊ฐ ์ถ๊ฐ/์ญ์ ๋ฑ ๋ณ๊ฒฝ๋์์ ๋ ์ง์์ ์ผ๋ก ํตํฉ ( Continuous Integration ) ํด์ฃผ๊ณ ๋ฐฐํฌ ( Continuous Deployment ) ํด์ฃผ๋ ๊ฒ์ผ๋ก , ์ฝ๋ ๋น๋์ ์ด์์ด ์๋์ง , ํ
์คํธ์๋ ์ด์์ด ์๋์ง , ๋ฐฐํฌ๊ณผ์ ์์ ๋ฌธ์ ๋ ์๋์ง ๋ฑ๋ฑ์ ์ฒดํฌํด ์ค๋๋ค.
์ด ๊ณผ์ ์ ๋ฌผ๋ก ์ฌ๋์ด ์งํํ ์ ์์ง๋ง, ๋งค๋ฒ ํด์ค์ผ ํด์ ๊ท์ฐฎ๊ณ ์ค์ํ ๊ฐ๋ฅ์ฑ์ด ์๊ธฐ ๋๋ฌธ์ github actions๋ฅผ ์ด์ฉํด์ pull request ์ ci ์๋ํํ๋ ๋ฐฉ๋ฒ์ ์๊ฐํฉ๋๋ค.
์์ฆ์ github actions๋ฅผ ์ด์ฉํ ci/cd ๊ฐ ๋ง์ด ๋์คํ๋์ด์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด์ ํ์ฌ๋ฅผ ๋ค๋ ๋๋ ๋ง์ด ์ฌ์ฉํ๋๋ฐ , actions๋ฅผ ์ด์ฉํด์ ํ ์คํธ / ๋น๋ / ๋ฐฐํฌ ๋ชจ๋ ์๋ํ๋ก ์งํํ์ต๋๋ค. ์ถ๊ฐ๋ก auto versioning , tagging , fail message ๋ฑ๋ ์๋ํ๋ก ์งํํ์ต๋๋ค. ์ด์ ์๋ ์ง์ ์๋์ผ๋ก ์งํํ์๋๋ฐ , ์ฌ๋์ด ์งํํ๋ค๋ณด๋ ๋นผ๋จน๊ฑฐ๋ ์๋ชป ๋ฑ๋กํ๋ ๊ฒฝ์ฐ๊ฐ ์๊ฒจ์ ์์ ํด์ผ ํ๋ ๊ฒฝ์ฐ๊ฐ ์๊ธฐ๊ณ , ๊ทธ๋ฌ๋ค๋ณด๋ ๋ ์ ๊ฒฝ์ธ๊ฒ ๋ง์์ง๋ ๋๋์ด ๋ค์์ต๋๋ค. ๊ทธ๋์ ์๋ํ๋ฅผ ๋์ ํ๋๋ฐ , ๋์ค์๋ ํจ์น๋ ธํธ ์์ฑ๋ ๋ ธ์ ์ผ๋ก ์๋ํํด์ ์งํํ์ต๋๋ค. ์๋ํ ํ๋ ๊ณผ์ ์ด ์ด๋ ต์ง๋ง ํ๋ฒ ์งํํด๋๋ฉด ๊ทธ ์ดํ์๋ ์ ๊ฒฝ์ธ๊ฒ ์์ด์ ์คํ๋ ค ์๊ฐ ๋ฑ๋ฑ์ ๋จ์ถ์ํฌ ์ ์์์ต๋๋ค.
.github ํด๋ ์ถ๊ฐํ๋ก์ ํธ์ ๋งจ ์์ ํด๋์ .github ํด๋๋ฅผ ์ถ๊ฐํ๊ณ , ๊ทธ ์์ workflows ํด๋๋ฅผ ์ถ๊ฐํ๋ค.
.github/workflows ๋ด๋ถ์ yml ํ์ผ ์์ฑ.github/workflows ๋ด๋ถ์ yml ํ์ผ์ ์์ฑํ๋ค. ๋๋ ci๋ง ์งํํ๋ค๋ ์๋ฏธ๋ก ci.yml ๋ก ์์ฑํ๋ค. ์์ฑํด์ผ ํ๋ ๊ฒ์ ํฌ๊ฒ 3๊ฐ์ง๋ก ๋๋ ์ ์๋ค.
pull request ๊ฐ ์ด๋ ธ์ ๋ ( opened ) , ๋ซํ๋ค๊ฐ ๋ค์ ์ด๋ ธ์ ๋ ( reopened ) , ์ฝ๋๊ฐ ๋ณ๊ฒฝ๋์์ ๋ ( synchronize ) ci๊ฐ ๋๊ณ ์ถ์ผ๋ฏ๋ก , ์๋์ ๊ฐ์ด ์ถ๊ฐํ๋ค.
yaml
on:
pull_request:
types:
- opened
- reopened
- synchronize
jobs์ ๊ฒฝ์ฐ ํ๋ฒ์ ๊ธฐ๋ณธ์ ์ผ๋ก๋ ์ฌ๋ฌ job๋ค์ ์คํ์ํฌ ์ ์๋ค.
yaml
jobs:
job1: ~~
job2: ~~
job3: ~~
๋ฌผ๋ก ํน์ ํ ๋ฐฉ๋ฒ์ผ๋ก ์์๋ฅผ ์ ์ดํ ์๋ ์๋ค. ๋ค๋ง ์ด๋ฒ ๊ฒฝ์ฐ์๋ 1๊ฐ์ง๋ง ์ฌ์ฉํ๋ค.
yaml
jobs:
changes:
if: github.event.pull_request.state != 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout
id: git_checkout
uses: actions/checkout@v4
- name: Setup node
id: setup_node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: yarn
- name: Install dependency
id: install_dependency
run: yarn install 2> >(tee log_${{ github.run_id }}.txt)
- name: Run Build
id: run_build
run: yarn build 2> >(tee log_${{ github.run_id }}.txt)
changes: job ์ ์ด๋ฆ์ผ๋ก , ๋ณ๊ฒฝ๋์์ ๋ actions๊ฐ ์คํ๋๊ฒ ํ๊ธฐ ์ํด์ changes๋ก ์ง์ด์ฃผ์๋ค.if : pr ์ด closed๊ฐ ์๋ ๊ฒฝ์ฐ์ actions๊ฐ ์งํ๋๋๋ก ์ค์ ํ๋ค.runs-on : actions ๊ฐ ์คํ๋๋ ํ๊ฒฝ์ ์ค์ ํ๋ค. ubuntu , macOS ๋ฑ๋ฑ์ด ์๋๋ฐ ์ด๋ฒ์๋ ubuntu-latest ๋ก ์งํํ๋ค.steps : ๊ฐ ์์
์์ ์คํ๋ ๋ด์ฉ์ ๋จ๊ณ๋ณ๋ก ์ค์ ํ๋ค.
Checkout : checkout ์ ๊ฒฝ์ฐ ๋น๋ํ๊ฑฐ๋ , ํ
์คํธํ๊ธฐ ์ํด์ ์ฝ๋๋ฅผ ๊ฐ์ ธ์ค๋ ๊ณผ์ ์ด๋ค.Setup node : ๊ฐ์ ธ์จ ์ฝ๋๋ฅผ ์คํํ๋๋ก Node.js ํ๊ฒฝ์ ์ค์ ํ๋๋ฐ ์ฌ์ฉํ๋ค. ์ด๋ฒ ๊ฒฝ์ฐ node 20 ๋ฒ์ ์ ์ฌ์ฉํด์ 20์ผ๋ก ์ค์ ํ๋ค. cache์ ๊ฒฝ์ฐ yarn ํจํค์ง ๋งค๋์ ๋ฅผ ์บ์ฑํด์ , dependency๋ฅผ ์ค๋ณต์ผ๋ก ์ค์นํ๋ ๊ฒ์ ๋ฐฉ์งํด์ ์คํ ์๊ฐ์ ์ค์ธ๋ค.Install dependency : dependency๋ฅผ ์ค์นํ๋ค.Run Build : build ๋ฅผ ์คํํ๋ค.ํด๋น ๋ณ๊ฒฝ์ฌํญ์ push ํ , ๊ฐ์ด pr์ ์์ฑํ๋ฉด

์์ ๊ฐ์ด ์์ฑ๋๊ณ , github actions๊ฐ ์ถ๊ฐ๋๊ฒ ๋๋ค. ์ปค๋ฐ์ด ์ถ๊ฐ๋ ๋๋ง๋ค actions๊ฐ ๋๊ฒ ๋๊ณ , ์์ฒ๋ผ ์คํจํ๋ ๊ฒฝ์ฐ์ ์ฑ๊ณตํ๋ ๊ฒฝ์ฐ ๊ฐ๊ฐ ์๋ ค์ฃผ๊ฒ ๋๋ค.

๊ฐ ์ปค๋ฐ ์ ์์ด์ฝ ๋๋ actions์ ๋ค์ด๊ฐ์ ์์ธ ๋ด์ฉ์ ๋ณผ ์ ์๋๋ฐ ์ ์ฌ์ง์ฒ๋ผ ์์ธ๋ก ๋์ค๊ฒ ๋๋ค.
์ค์ ์ฌ์ฉํ ๋๋ ๊ทธ๋๊ทธ๋ ๊ธํ๊ฒ ์ถ๊ฐํ๋๋ผ ์ ๋ชจ๋ฅด๋ ๋ถ๋ถ์ด ๋ง์ด ์์๋๋ฐ , ์ด๋ฒ ๊ธฐํ๋ก ๋ณด๋ค ์์ธํ ์ด๋ค ์์ ์ ํ๋์ง ์ ์ ์์ด์ ์ข์๋ค. ์์ผ๋ก ์ฌ๊ธฐ ์์ ์ ์ ์์๊ฐ๋ฉด์ ์ฌ๋ฌ ci/cd ๋ฅผ ์ถ๊ฐํ๊ณ ์ ํ๋ค. ๋ํ marketplace ์ ์ฌ๋ฌ ์ฌ๋๋ค์ด ์ฌ๋ ค๋์ actions๋ ํ์ธํด ๋ณด๋ ค๊ณ ํ๋ค.
์ github actions๊ฐ ์๋ repo๋ ์ฌ๊ธฐ ์์ ํ์ธํ์ค ์ ์์ต๋๋ค.