Public Github Package Private
Bước 1: Tạo file Github Workflows
mkdir .github cd .github mkdir workflows cd workflows touch github-packages.yml
Example file github-packages.yml
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages name: GlobalNavi Publish Packages on: release: types: [ created ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 16 - run: npm install - run: npm ci publish-gpr: needs: build runs-on: ubuntu-latest permissions: contents: read packages: write steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 16 registry-url: https://npm.pkg.github.com/ - run: npm install - run: npm ci - run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
Ở file này chú ý Github actions này sẽ chạy khi tạo mới 1 bản release trên Github Repository, mình có thể chuyển actions thành "Push to new branch"
on: push: # Sequence of patterns matched against refs/heads branches: - main
Bước 2: Cập nhật file package.json và thêm .npmrc lưu trữ thông tin Authentication to GitHub Packages
Package.json thêm các thuộc tính:
"repository": "https://github.com/Andom-Geniam/git-globalnavi", "publishConfig": { "@Andom-Geniam:registry": "https://npm.pkg.github.com" }
.npmrc thêm
//npm.pkg.github.com/:_authToken=Token @Andom-Geniam:registry=https://npm.pkg.github.com
_authToken tạo ở https://github.com/settings/tokens (dung classic token) https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry
![Ảnh màn hình 2022-11-02 lúc 17.30.42.png](https://firebasestorage.googleapis.com/v0/b/classfunc-com.appspot.com/o/blogs%2Falbums%2Fuppy-a%2Fnh%2Fma%2Fn%2Fhi%2Fnh%2F2022%2F11%2F02%2Flu%2Fc%2F17%2F30%2F42%2Fpng-o9-10-o0-10-o0-10-1d-1d-10-o1-10-1e-1e-1e-image%2Fpng-484545-1667385048317_A%CC%89nh%20ma%CC%80n%20hi%CC%80nh%202022-11-02%20lu%CC%81c%2017.30.42.png?alt=media&token=cc9bd9a0-6af1-4d9b-90d3-2b1cb4474c5a)