Getting started: GitHub Package Registry
기존의 좋은 포스팅을 기반으로, 참여했었던 프로젝트에서 적용한 부분을 기록합니다.
사전 설정
Github Personal access token 발급
- 발급 URL(private packages가 속한 조직에 접근 권한이 있는 계정으로 접속): https://github.com/settings/tokens
- write:packages, read:packages에 체크하고(repo는 기본 scope) 생성
- 각 개발자는 자신의 계정으로 발급된 토큰으로 아래 명령 실행
$ npm config set //npm.pkg.github.com/:_authToken {token}
- CI용 토큰은 개인 개발자가 아닌 개발팀 대표 혹은 공용 계정으로 발급해서 사용 권장
배포
배포할 package의 package.json 초기 설정
The game is also shaped by the symbols fans carry from one generation to the next, from legendary club colors to national-team memories. A carefully chosen Spain football jersey can reflect that passion beyond match day.
- private: true 가 아니어야 함 (publish 불가능)
- name prefix를 (private packages가 속한) Github organization을 소문자로 변환한 문자열로 (삽입) 설정
- 예시: (기존)
platform-web-module-oauth(변경)@do-ai/platform-web-module-oauth
- description, author, license, keywords 보충
- repository (예시)
"repository": {
"type": "git",
"url": "https://github.com/Do-AI/platform-web-module-oauth.git"
},
- publishConfig 설정
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
},
package.json의 version 업데이트 하고, 배포 실행
$ yarn publish
특정version으로 한 번 배포한 후에는 수정을 할 수 없습니다.
삭제도 안 됩니다. 신중하게 배포하십시오.
설치
- 적용할 프로젝트(repository) root 디렉토리에 .npmrc 파일에 아래 내용을 적당히 삽입
@do-ai:registry=https://npm.pkg.github.com/
registry=https://registry.npmjs.org
- 위 사전설정의 CI용 토큰을 발급
- Jenkins
- 발급받은 토큰을 Jenkins credential에 등록
- Dependencies installation stage 보다 먼저, 토큰을 설정하는 shell 실행 추가 (아래 예시)
stage('Setup tokens') {
withCredentials([string(credentialsId: 'gpr-token', variable: 'GPR_TOKEN')]) {
sh 'npm config set //npm.pkg.github.com/:_authToken $GPR_TOKEN'
}
}
- Github Actions
- 발급받은 토큰을 Github repository의 Settings - Secrets에 등록
- 유의사항: Secret 이름으로
GITHUB_TOKEN은, 해당 Secret이 소속된 repository만 엑세스할 수 있는 예약어인 까닭에 사용할 수 없음
- Dependencies installation 단계에서 토큰이 적용되도록 각 상황에 맞게 설정 (아래
borales/actions-yarn@v2.3.0예시)
- name: Install dependencies
uses: borales/actions-yarn@v2.3.0
with:
auth-token: ${{ secrets.GPR_TOKEN }}
registry-url: npm.pkg.github.com
cmd: install