name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm test | 기본 워크플로우 구조 |
on: push | 모든 push에서 트리거 |
on: [push, pull_request] | 여러 이벤트 |
on:
push:
branches: [main, develop]
paths:
- "src/**"
- "!**.md" | 브랜치 및 경로 필터 |
on:
schedule:
- cron: "0 0 * * *" | 스케줄 (매일 자정) |
on:
workflow_dispatch:
inputs:
environment:
type: choice
options: [dev, prod] | 입력이 있는 수동 트리거 |
on:
release:
types: [published] | 릴리스 게시 시 |
on:
workflow_call:
inputs:
config:
type: string
required: true | 재사용 가능한 워크플로우 |
jobs:
build:
runs-on: ubuntu-latest | Ubuntu에서 기본 job |
jobs:
build:
runs-on: windows-latest | Windows에서 실행 |
jobs:
build:
runs-on: macos-latest | macOS에서 실행 |
jobs:
build:
runs-on: [self-hosted, linux] | 셀프 호스팅 러너 |
jobs:
test:
needs: build
runs-on: ubuntu-latest | Job 의존성 |
jobs:
deploy:
needs: [build, test]
if: github.ref == 'refs/heads/main' | 조건부 job |
jobs:
build:
timeout-minutes: 30
continue-on-error: true | 타임아웃 및 오류 처리 |
jobs:
test:
strategy:
matrix:
node: [16, 18, 20]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }} | 다중 버전 매트릭스 |
strategy:
matrix:
include:
- node: 18
experimental: true
exclude:
- os: windows-latest
node: 16 | 조합 포함/제외 |
strategy:
fail-fast: false
max-parallel: 2 | 매트릭스 옵션 |
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true | 중복 워크플로우 취소 |
steps:
- name: Checkout
uses: actions/checkout@v4 | 액션 사용 |
steps:
- name: Run script
run: echo "Hello" | 셸 명령 실행 |
steps:
- name: Multi-line script
run: |
echo "Line 1"
echo "Line 2" | 여러 줄 스크립트 |
steps:
- run: dir
shell: pwsh | 셸 지정 (pwsh, bash, python) |
steps:
- name: Conditional step
if: github.event_name == 'push'
run: echo "Pushed" | 조건부 스텝 |
steps:
- name: Always run
if: always()
run: echo "Cleanup" | 항상 실행 (실패 시에도) |
steps:
- run: npm test
working-directory: ./frontend | 작업 디렉토리 설정 |
steps:
- run: long-task
timeout-minutes: 10 | 스텝 타임아웃 |
steps:
- run: risky-command
continue-on-error: true | 오류 시 계속 |
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history | 저장소 체크아웃 |
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm | 캐시와 함께 Node.js 설정 |
- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip | Python 설정 |
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin | Java 설정 |
- uses: actions/setup-go@v5
with:
go-version: "1.21" | Go 설정 |
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm- | 의존성 캐시 |
- uses: actions/upload-artifact@v4
with:
name: build-output
path: dist/
retention-days: 5 | 아티팩트 업로드 |
- uses: actions/download-artifact@v4
with:
name: build-output
path: ./dist | 아티팩트 다운로드 |
- uses: docker/setup-buildx-action@v3 | Docker Buildx 설정 |
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} | GHCR 로그인 |
- uses: docker/build-push-action@v5
with:
push: true
tags: ghcr.io/${{ github.repository }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max | Docker 이미지 빌드 및 푸시 |
env:
NODE_ENV: production
API_URL: https://api.example.com | 워크플로우 레벨 env |
jobs:
build:
env:
CI: true | Job 레벨 env |
steps:
- run: echo $MY_VAR
env:
MY_VAR: value | 스텝 레벨 env |
steps:
- run: echo "value=${{ env.MY_VAR }}" >> $GITHUB_OUTPUT
id: step1
- run: echo ${{ steps.step1.outputs.value }} | 스텝 간 출력 전달 |
steps:
- run: echo "${{ secrets.API_KEY }}" | 저장소 시크릿 사용 |
steps:
- run: ./deploy.sh
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET }} | 시크릿을 env 변수로 |
jobs:
deploy:
environment: production
steps:
- run: echo ${{ secrets.PROD_KEY }} | 환경별 시크릿 |
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }} | 자동 생성 토큰 |
permissions:
contents: write
pull-requests: write
issues: read | 토큰 권한 |
${{ github.repository }} | owner/repo |
${{ github.ref }} | refs/heads/main 또는 refs/tags/v1 |
${{ github.sha }} | 커밋 SHA |
${{ github.actor }} | 트리거한 사용자 |
${{ github.event_name }} | push, pull_request 등 |
${{ github.run_number }} | 워크플로우 실행 번호 |
${{ github.workspace }} | 워크스페이스 경로 |
if: ${{ github.ref == 'refs/heads/main' }} | 문자열 비교 |
if: contains(github.event.head_commit.message, '[skip ci]') | 포함 확인 |
if: startsWith(github.ref, 'refs/tags/') | 시작 확인 |
if: success() && github.ref == 'refs/heads/main' | 복합 조건 |
if: failure() | 실패 시 실행 |
if: cancelled() | 취소 시 실행 |
${{ toJson(github.event) }} | JSON으로 변환 |
${{ fromJson(needs.job1.outputs.matrix) }} | JSON 파싱 |
jobs:
deploy:
environment:
name: production
url: https://example.com
steps:
- run: ./deploy.sh | 환경에 배포 |
jobs:
deploy:
environment:
name: staging
concurrency:
group: staging
cancel-in-progress: true | 동시성이 있는 환경 |
permissions:
pages: write
id-token: write
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/configure-pages@v4
- uses: actions/upload-pages-artifact@v3
with:
path: ./dist
- uses: actions/deploy-pages@v4
id: deployment | GitHub Pages에 배포 |
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET }}
aws-region: us-east-1
- run: aws s3 sync ./dist s3://bucket | AWS S3에 배포 |
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- uses: azure/webapps-deploy@v2
with:
app-name: my-app
package: ./dist | Azure에 배포 |