在 Github 上使用 yarn 安装私有 Github 包 操作未经 yarn.lock 授权
Installing private Github Package using yarn on Github Actions is Unauthorized with yarn.lock
已经有很多类似的问题浮出水面:
- Install private github package from package.json on Github Actions
然而,我们的问题似乎有所不同,因为:
yarn install
运行在本地机器上没问题
- 问题仅在使用 Github 操作时出现
如果我们删除 yarn.lock
,yarn install
GH 操作成功
有人 运行 以前参与过这个吗?特别是它不能使用 yarn.lock
文件?
万一重要,这里是设置:
build.yml
:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://npm.pkg.github.com'
- name: Install
run: yarn install
env:
# GITHUB_TOKEN can't access packages hosted in private repos,
# even within the same organisation
NODE_AUTH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Build
run: yarn build
- name: Test
run: yarn test --forbid-only
我们还有一个用于本地安装的 .npmrc
文件:
@<org>:registry=https://npm.pkg.github.com
但是没有.yarnrc
文件。
我们设法通过在 build.yml
配置中显式复制 .npmrc
配置来解决此问题:
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://npm.pkg.github.com'
# These following two lines are the key:
always-auth: true
scope: '@reedsy'
我正在创建文件 .npmrc 和 .yarnrc。
类型:
name: Test
on: push
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Node ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Create NPMRC
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PACKAGES_TOKEN }}" >> ~/.npmrc
echo "@you-scope:registry=https://npm.pkg.github.com" >> ~/.npmrc
echo 'registry "https://registry.yarnpkg.com"' >> ~/.yarnrc
- run: yarn install
用 LowerCase.
为 github 或 github 中的组织的用户替换 @you-scope
为您的 github 访问此存储库创建一个 PACKAGES_TOKEN 秘密令牌。
已经有很多类似的问题浮出水面:
- Install private github package from package.json on Github Actions
然而,我们的问题似乎有所不同,因为:
yarn install
运行在本地机器上没问题- 问题仅在使用 Github 操作时出现 如果我们删除
yarn install
GH 操作成功
yarn.lock
,有人 运行 以前参与过这个吗?特别是它不能使用 yarn.lock
文件?
万一重要,这里是设置:
build.yml
:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://npm.pkg.github.com'
- name: Install
run: yarn install
env:
# GITHUB_TOKEN can't access packages hosted in private repos,
# even within the same organisation
NODE_AUTH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Build
run: yarn build
- name: Test
run: yarn test --forbid-only
我们还有一个用于本地安装的 .npmrc
文件:
@<org>:registry=https://npm.pkg.github.com
但是没有.yarnrc
文件。
我们设法通过在 build.yml
配置中显式复制 .npmrc
配置来解决此问题:
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://npm.pkg.github.com'
# These following two lines are the key:
always-auth: true
scope: '@reedsy'
我正在创建文件 .npmrc 和 .yarnrc。 类型:
name: Test
on: push
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Node ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Create NPMRC
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PACKAGES_TOKEN }}" >> ~/.npmrc
echo "@you-scope:registry=https://npm.pkg.github.com" >> ~/.npmrc
echo 'registry "https://registry.yarnpkg.com"' >> ~/.yarnrc
- run: yarn install
用 LowerCase.
为 github 或 github 中的组织的用户替换 @you-scope为您的 github 访问此存储库创建一个 PACKAGES_TOKEN 秘密令牌。