🔧 DevOps

GitHub

GitHub

The world's largest code hosting platform. Provides CI/CD through GitHub Actions.

Detailed Explanation

GitHub is the world's largest code hosting platform that hosts Git repositories and provides collaboration features. Founded in 2008 and acquired by Microsoft in 2018, it is used by more than 100 million developers worldwide. It is the center of open-source projects and a core tool of modern software development.

Key Features

  • Git repository hosting: Unlimited public/private repositories
  • Pull Request: Code review and merge workflow
  • GitHub Actions: Built-in CI/CD pipeline
  • Issues & Projects: Issue tracking and project management
  • GitHub Copilot: AI-based code autocompletion
  • GitHub Pages: Static website hosting
  • GitHub Packages: Package registry (npm, Docker, etc.)

GitHub Collaboration Workflow

  • Fork: Create a copy of another repository in your own account
  • Clone: Copy a repository to your local machine
  • Branch: Create a feature branch
  • Commit & Push: Commit changes and push them to the remote
  • Pull Request: Merge request and code review
  • Merge: Merge into the main branch after approval

Code Example

GitHub Actions - CI/CD Workflow

# .github/workflows/ci.yml
name: CI Pipeline

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

env:
  NODE_VERSION: '20'

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run linter
        run: npm run lint

      - name: Run tests
        run: npm test -- --coverage

      - name: Upload coverage
        uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}

  build:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: 'npm'

      - run: npm ci
      - run: npm run build

      - name: Upload build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: build
          path: dist/

  deploy:
    needs: build
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: production
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          name: build
          path: dist

      - name: Deploy to production
        run: |
          # 배포 스크립트
          echo "Deploying to production..."

Build and Push Docker Image

# .github/workflows/docker.yml
name: Docker Build & Push

on:
  push:
    tags: ['v*']

jobs:
  docker:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    steps:
      - uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract metadata
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ghcr.io/${{ github.repository }}
          tags: |
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}

      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

Create Automatic Release

# .github/workflows/release.yml
name: Release

on:
  push:
    tags: ['v*']

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Generate changelog
        id: changelog
        uses: orhun/git-cliff-action@v2
        with:
          config: cliff.toml
          args: --latest --strip header

      - name: Create Release
        uses: softprops/action-gh-release@v1
        with:
          body: ${{ steps.changelog.outputs.content }}
          draft: false
          prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Pull Request Template

<!-- .github/PULL_REQUEST_TEMPLATE.md -->
## 변경 사항
-

## 관련 이슈
Closes #

## 체크리스트
- [ ] 테스트 코드 작성
- [ ] 문서 업데이트
- [ ] 로컬에서 테스트 완료

## 스크린샷 (UI 변경 시)

Practical Conversation Example

Junior Developer
"Managing Jenkins pipelines is hard. What are the benefits of moving to GitHub Actions?"
Senior developer
"GitHub Actions is fully integrated with the repository, so there's no need to manage a separate server. You define the workflow in YAML and commit it together with the repository, so it's also version-controlled. Above all, the Marketplace has thousands of reusable Actions, so you can finish most tasks in just a few lines."
Junior Developer
"What about the cost? Can I use it for free?"
Senior developer
"Public repositories are free, and private repositories are also free up to 2,000 minutes per month (Free plan). Beyond that you need a paid plan, but most small and medium-sized projects are fine within the free range. If you use a self-hosted runner, it's unlimited and free."

Cautions

Secrets Management

Do not write API keys or passwords directly in your code. Store them in GitHub Secrets and reference them with `${{ secrets.SECRET_NAME }}`.

Branch Protection

To prevent direct pushes to the main branch, set up Branch protection rules. You can enforce required reviewers, passing status checks, and more.

Actions Execution Time

GitHub Actions is billed based on execution time. Reduce unnecessary triggers and make use of caching.

Public Repository Caution

Actions logs in public repositories can be viewed by anyone. Take care that sensitive information is not printed to the logs.

Learn More