使用操作/设置节点时如何更改@yarn:github操作中的注册表

Posted

技术标签:

【中文标题】使用操作/设置节点时如何更改@yarn:github操作中的注册表【英文标题】:How do I change the @yarn:registry in github action when using actions/setup-node 【发布时间】:2021-12-14 10:57:08 【问题描述】:

我正在尝试安装GSAP 3 with Shockingly Green 包。

以下是插件推荐的步骤。

//npm.greensock.com/:_authToken=XXXXXXXXXXXXXXXXXXXXXX
@gsap:registry=https://npm.greensock.com

yarn add gsap@npm:@gsap/shockingly

这是我在 github 操作中使用的工作流文件。

name: Deployment

on:
  push:
    branches: [ development ]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - uses: actions/setup-node@v1.4.4
      with:
        node-version: 14.16.0

    - name: Setup php with intl
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.4'
        extensions: intl-67.1

    - name: Install Composer
      run: sudo composer

    - name: Install dependencies
      run: |
        composer install -o
        yarn
      env:
        NPM_AUTH_TOKEN: $ secrets.NPM_AUTH_TOKEN 

    - name: Build
      run: yarn build
      
    - name: Sync
      env:
        dest: 'root@XXXXXXXXXXX:/var/www/html/wp-content/themes/XXXXXXX'
      run: |
        echo "$secrets.DEPLOY_KEY" > deploy_key
        chmod 600 ./deploy_key
        rsync -chav --delete \
          -e 'ssh -i ./deploy_key -o StrictHostKeyChecking=no' \
          --exclude /deploy_key \
          --exclude /.git/ \
          --exclude /.github/ \
          --exclude /node_modules/ \
          ./ $env.dest

我已经使用 GSAP 提供给我的代码添加了适当的机密 NPM_AUTH_TOKEN。

但我不断收到此错误。

yarn install v1.22.17
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
error An unexpected error occurred: "https://npm.greensock.com/@gsap%2fshockingly/-/shockingly-3.8.0.tgz: Request failed \"403 Forbidden\"".
info If you think this is a bug, please open a bug report with the information provided in "/home/runner/work/lacadives-theme/lacadives-theme/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error: Process completed with exit code 1.

我认为操作是在错误的注册表上运行的。 有没有办法可以将注册表更改为@gsap:registry=https://npm.greensock.com

【问题讨论】:

【参考方案1】:

有两个问题需要解决。

    正确设置 .npmrc 并删除 yarn.lock 文件

我的最终yml 文件。

name: Deployment

on:
  push:
    branches: [ development ]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - uses: actions/setup-node@v1.4.4
      with:
        node-version: 14.16.0
        
    - name: Create NPMRC
      run: |
          echo "//npm.greensock.com/:_authToken=XXXXXXXXXXXXXXXXXXXXXXXXXXXX" >> ~/.npmrc
          echo "@gsap:registry=https://npm.greensock.com" >> ~/.npmrc

    - name: Setup PHP with intl
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.4'
        extensions: intl-67.1

    - name: Install Composer
      run: sudo composer

    - name: Install dependencies
      run: |
        composer install -o
        rm yarn.lock
        yarn

    - name: Build
      run: yarn build
      
    - name: Sync
      env:
        dest: 'root@XXXXXXX:/var/www/html/wp-content/themes/XXXXXXXXX'
      run: |
        echo "$secrets.DEPLOY_KEY" > deploy_key
        chmod 600 ./deploy_key
        rsync -chav --delete \
          -e 'ssh -i ./deploy_key -o StrictHostKeyChecking=no' \
          --exclude /deploy_key \
          --exclude /.git/ \
          --exclude /.github/ \
          --exclude /node_modules/ \
          ./ $env.dest

【讨论】:

以上是关于使用操作/设置节点时如何更改@yarn:github操作中的注册表的主要内容,如果未能解决你的问题,请参考以下文章

如何在 AWS 部署中使用特定节点版本进行纱线设置?

使用 sudo 运行时找不到命令

VueCLI3如何更改安装时的包管理器为yarn或npm

指定 YARN 节点标签时,YARN 应用程序无法启动

Apache Spark 在 YARN 中部署时如何处理系统故障?

如何编辑通过纱线安装的节点模块?