Search code examples
github-actionsyarnpkggsap

How do I change the @yarn:registry in github action when using actions/setup-node


I am trying to install GSAP 3 with Shockingly Green package.

The following are the steps recommended by the plugin.

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

And

yarn add gsap@npm:@gsap/shockingly

This is my workflow file which I am using in github action.

name: Deployment

on:
  push:
    branches: [ development ]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - uses: actions/[email protected]
      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}}

I have added proper secret NPM_AUTH_TOKEN with the code provided to me by GSAP.

But I keep getting this error.

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.

I think action is running on wrong registry. Is there a way that I can change the registry to @gsap:registry=https://npm.greensock.com.


Solution

  • There were two issues which needed to be addressed.

    1. Setting up .npmrc correctly
    2. And removing yarn.lock file

    My final yml file.

    name: Deployment
    
    on:
      push:
        branches: [ development ]
    
    jobs:
      deploy:
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v2
    
        - uses: actions/[email protected]
          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}}