Github actions
๐ ๏ธ ์์ด์ ํธ ์คํฌ
npx -y skills add DaleStudy/skills --skill github-actionsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
GitHub Actions ์ํฌํ๋ก์ฐ ์์ฑ, ๋ณด์ ๋ฐ ๋ฒ์ ๊ด๋ฆฌ ์คํฌ. ๋ค์ ์ํฉ์์ ์ฌ์ฉ: (1) ์ ์ํฌํ๋ก์ฐ ํ์ผ(.yml) ์์ฑ ์, (2) ๊ธฐ์กด ์ํฌํ๋ก์ฐ ์์ ์, (3) ์ก์ ๋ฒ์ ๊ฒํ ๋๋ ์ ๋ฐ์ดํธ ์, (4) CI/CD ๋ณด์ ๊ฐ์ฌ ์, (5) 'actions/', 'uses:', 'workflow', '.github/workflows' ํค์๋๊ฐ ํฌํจ๋ ์์ ์
The file declares its own license as MIT. That is the authorโs claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
6.4 KB, as published. Nobody here has run it
GitHub Actions
์ฐธ๊ณ : GitHub Actions ์ํฌํ๋ก์ฐ ์คํ ๋ฐ ๊ฒฐ๊ณผ ์กฐํ, ์ด์/PR ๊ด๋ฆฌ ๋ฑ
ghCLI ๊ด๋ จ ์์ ์github์คํฌ์ ํจ๊ป ๋ก๋ํ์ฌ ์ฐธ์กฐํ๋ค.
์ฃผ์ ์ฌํญ (Anti-patterns)
1. ์ค๋๋ ๋ฒ์ ์ฌ์ฉ
# โ ์ค๋๋ ๋ฒ์ - ๊ฐ์ฅ ํํ ์ค์
uses: actions/checkout@v4 # v6๊ฐ ์ต์ ์ธ ๊ฒฝ์ฐ
# โ
์ต์ ๋ฉ์ด์ ๋ฒ์ (gh release view๋ก ํ์ธ ํ ์ฌ์ฉ)
uses: actions/checkout@v6
์ต์ ๋ฒ์ ์์ ์ ๊ณตํ๋ ์ฑ๋ฅ ๊ฐ์ ๊ณผ ๋ณด์ ํจ์น๋ฅผ ๋์น์ง ์๋๋ก ํฉ๋๋ค.
๋ฒ์ ํ์ธ ๋ช ๋ น์ด:
gh release view --repo {owner}/{repo} --json tagName --jq '.tagName'
# ์์
gh release view --repo actions/checkout --json tagName --jq '.tagName'
gh release view --repo oven-sh/setup-bun --json tagName --jq '.tagName'
์ฐธ๊ณ : ๋ณด์ ๋ฏผ๊ฐ ํ๊ฒฝ์ด๋ ์ ๋ขฐ๋ ๋ฎ์ ์๋ํํฐ ์ก์ ์ SHA ํผ๋(
@a1b2c3...)์ ๊ณ ๋ ค.
2. ๋ฏผ๊ฐ์ ๋ณด ํ๋์ฝ๋ฉ
# โ ํ๋์ฝ๋ฉ - ๋ณด์ ์ํ
env:
API_KEY: "sk-1234567890"
DATABASE_PASSWORD: "mypassword123"
# โ
secrets ์ฌ์ฉ
env:
API_KEY: ${{ secrets.API_KEY }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
๋น๋ฐ๋ฒํธ๋ API Key์ ๊ฐ์ ๋ฏผ๊ฐ ์ ๋ณด๊ฐ ๊ทธ๋๋ก ๋ ธ์ถ๋์ด ๋ณด์ ์ฌ๊ณ ๋ก ์ด์ด์ง ์ ์์ต๋๋ค. ๋ณด์ ์ ์ค์ํ ์ ๋ณด๋ ๋ฐ๋์ ์ ์ฅ์๋ ์กฐ์ง์ ์ํฌ๋ฆฟ์ผ๋ก ์ ์ฅํด๋๊ณ ์ฝ์ด ์์ผํฉ๋๋ค.
์ฐธ๊ณ : Using secrets
3. ์ ๋ ฅ๊ฐ ์ธ์ ์ ์ทจ์ฝ์
# โ ์ธ์ ์
์ทจ์ฝ - github.event ์ง์ ์ฌ์ฉ
run: echo "${{ github.event.issue.title }}"
run: gh issue comment ${{ github.event.issue.number }} --body "${{ github.event.comment.body }}"
# โ
ํ๊ฒฝ๋ณ์๋ก ์ ๋ฌํ์ฌ ์ธ์ ์
๋ฐฉ์ง
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
echo "$ISSUE_TITLE"
gh issue comment ${{ github.event.issue.number }} --body "$COMMENT_BODY"
์ ์์ ์ธ ์ฌ์ฉ์๊ฐ ์ด์ ์ ๋ชฉ์ด๋ ์ฝ๋ฉํธ์ ์ ธ ๋ช ๋ น์ด๋ฅผ ์ฃผ์ ํ ์ ์์ต๋๋ค.
์ฐธ๊ณ : Script injections
4. pull_request_target ์ด๋ฒคํธ ์ค์ฉ
# โ ๏ธ ์ํ - ํฌํฌ์ ์ฝ๋๋ฅผ ์ ๋ขฐ๋ ์ปจํ
์คํธ์์ ์คํ
on: pull_request_target
steps:
- uses: actions/checkout@v{N}
with:
ref: ${{ github.event.pull_request.head.sha }} # ์ํ!
pull_request_target ์ด๋ฒคํธ๋ ํฌํฌ์ PR์์๋ ์ํฌ๋ฆฟ์ ์ ๊ทผ ๊ฐ๋ฅํฉ๋๋ค. ํฌํฌ ์ฝ๋๋ฅผ ์ฒดํฌ์์ํ๋ฉด ์
์ฑ ์ฝ๋๊ฐ ์คํ๋ ์ ์์ต๋๋ค.
์ฐธ๊ณ : pull_request_target
5. ์ฌ์ ์ค์น๋ ๋๊ตฌ์ ์ค๋ณต ์ค์
# โ ๋ถํ์ํ setup - node, npm, npx๋ ์ด๋ฏธ ์ค์น๋จ
steps:
- uses: actions/setup-node@v{N}
- run: npx some-command
# โ
๋ฐ๋ก ์ฌ์ฉ
steps:
- run: npx some-command
- run: python script.py
- run: docker build .
์ค๋ณต ์ค์น๋ ์ํฌํ๋ก์ฐ ์คํ ์๊ฐ์ ๋๋ฆฌ๊ณ ๋ถํ์ํ ๋คํธ์ํฌ ์์ฒญ์ ๋ฐ์์ํต๋๋ค.
์ฃผ์ ์ฌ์ ์ค์น ๋๊ตฌ: Node.js, npm, npx, Python, pip, Ruby, gem, Go, Docker, git, gh, curl, wget, jq, yq
์ฃผ์ ๋ฏธ์ค์น ๋๊ตฌ: Bun, Deno, Rust, Zig, pnpm, Poetry, Ruff
์ฌ์ ์ค์น๋ ๋๊ตฌ ํ์ธ:
- Ubuntu: https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
- macOS: https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md
- Windows: https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md
๋ชจ๋ฒ ์ฌ๋ก (Best Practices)
์ต์ ๊ถํ ์์น
๊ถํ์ ๊ฐ๋ฅํ ํ์ ๋ ๋ฒจ์ ์ ์ธ. ๋ฒ์๋ฅผ ์ข๊ฒ ์ ์ง:
# โ
๊ถํ ๋ฒ์: workflow > job > step (์ข์์๋ก ์ข์)
jobs:
build:
permissions:
contents: read # job ๋ ๋ฒจ์์ ํ์ํ ๊ถํ๋ง
๊ถ์ฅ ์ํฌํ๋ก์ฐ ๊ตฌ์กฐ
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
# ๋ฒ์ ์ gh release view๋ก ํ์ธ ํ ์ฌ์ฉ
- uses: actions/checkout@v{N}
- name: Setup Bun
uses: oven-sh/setup-bun@v{N}
์์ฃผ ์ฌ์ฉ๋๋ ์ด๋ฒคํธ
on:
push: # ํธ์ ์
branches: [main]
pull_request: # PR ์์ฑ/์
๋ฐ์ดํธ ์
branches: [main]
workflow_dispatch: # ์๋ ์คํ
schedule: # ์ค์ผ์ค ์คํ
- cron: "0 0 * * 1" # ๋งค์ฃผ ์์์ผ 00:00 UTC
release: # ๋ฆด๋ฆฌ์ค ์์ฑ ์
types: [published]
workflow_call: # ๋ค๋ฅธ ์ํฌํ๋ก์ฐ์์ ํธ์ถ
์์ฃผ ์ฌ์ฉ๋๋ ๊ถํ
permissions:
contents: read # CI (๋น๋/ํ
์คํธ), ์ฝ๋ ์ฒดํฌ์์
contents: write # ์ปค๋ฐ/ํธ์
pull-requests: write # PR ์ฝ๋ฉํธ ๋ด
issues: write # ์ด์ ์ฝ๋ฉํธ
packages: write # ํจํค์ง ๋ฐฐํฌ (contents: write์ ํจ๊ป)
id-token: write # OIDC ํด๋ผ์ฐ๋ ์ธ์ฆ (contents: read์ ํจ๊ป)
์์ฃผ ์ฌ์ฉ๋๋ ์ก์
# ๋ฒ์ ์ gh release view --repo {owner}/{repo} --json tagName --jq '.tagName'์ผ๋ก ํ์ธ
steps:
- uses: actions/cache@v{N} # ์์กด์ฑ ์บ์ฑ
- uses: actions/checkout@v{N} # ์ฝ๋ ์ฒดํฌ์์
- uses: actions/download-artifact@v{N} # ์ํฐํฉํธ ๋ค์ด๋ก๋
- uses: actions/upload-artifact@v{N} # ์ํฐํฉํธ ์
๋ก๋
- uses: oven-sh/setup-bun@v{N} # Bun ์ค์