---
myst:
  html_meta:
    "description lang=en": "Continuous Integration with GitHub Actions and a binary cache"
    "keywords": "CI, Continuous Integration, GitHub Actions, Binary Cache, Nix"
---

(github-actions)=

# GitHub Actions를 이용한 지속적 통합

```{contributors}
:authors: domenkozar
```

커밋과 풀 리퀘스트를 위한 지속적 통합(CI) 워크플로로 [GitHub Actions](https://github.com/features/actions)를 설정하십시오.

Nix를 사용하면 CI가 바이너리 캐시를 이용해 모든 브랜치의 모든 프로젝트에 대한 개발자 환경을 빌드하고 캐시할 수 있습니다.

빌드 시간은 CI의 핵심 지표입니다. Cachix(아래 참조)는 가장 간단한 캐싱 옵션입니다.

## Cachix를 이용한 빌드 캐싱

[Cachix](https://cachix.org/)를 사용하면 derivation을 두 번 빌드하느라 시간을 낭비할 일이 없으며, 빌드된 derivation을 모든 개발자와 공유할 수 있습니다.

각 작업이 끝나면 방금 빌드된 derivation이 바이너리 캐시로 푸시됩니다.

각 작업이 시작되기 전에, 빌드할 derivation이 바이너리 캐시에 있으면 먼저 그곳에서 대체됩니다.

### 1\. 첫 번째 바이너리 캐시 만들기

누가 쓰기/읽기 권한을 가질지에 따라 팀별로 서로 다른 바이너리 캐시를 두는 것을 권장합니다.

[바이너리 캐시 생성](https://app.cachix.org/cache) 페이지의 양식을 작성하십시오.

새로 만든 바이너리 캐시에서 **Push binaries** 탭의 안내를 따르십시오.

### 2\. 시크릿 설정하기

GitHub 저장소 또는 조직(모든 저장소에서 사용하려는 경우)에서 다음을 수행하십시오:

1. `Settings`를 클릭하십시오.
2. `Secrets and variables`를 클릭한 다음 드롭다운 목록에서 `Actions`를 클릭하십시오.
3. `New repository secret`을 클릭하십시오.
4. 앞서 생성한 시크릿(`CACHIX_SIGNING_KEY` 및/또는 `CACHIX_AUTH_TOKEN`)을 추가하십시오.

### 3\. GitHub Actions 설정하기

다음 내용으로 `.github/workflows/test.yml`을 만드십시오:

```yaml
name: "Test"
on:
  pull_request:
  push:
jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: cachix/install-nix-action@v25
      with:
        nix_path: nixpkgs=channel:nixos-unstable
    - uses: cachix/cachix-action@v14
      with:
        name: mycache
        # If you chose signing key for write access
        signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
        # If you chose API tokens for write access OR if you have a private cache
        authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
    - run: nix-build
    - run: nix-shell --run "echo OK"
```

GitHub 저장소에 커밋하고 푸시하면 커밋과 PR에 상태 검사가 표시됩니다.

## 다음 단계

- [GitHub Actions 워크플로 문법](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions)을 참고하십시오.
- Nix 프로젝트를 빠르게 설정하려면 [Getting started Nix template](https://github.com/nix-dot-dev/getting-started-nix-template)을 읽어 보십시오.

[github-actions-caching-limits]: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
