angulargithubnpmgithub-actions

Github actions for creating an npm pacakge from angular workspace/library


enter image description hereSo I have this github action code, I'm trying to create a github package for diferent libraries in the workspace, The build step works fine however on the publish step I get this error Error: Process completed with exit code 2. dist folder doesnt exist it says. Note the dist folder is created after the build process is completed and it is added .gitignore fire as well.

I don't understand what am I doing wrong here.


name: Angular Package

on:
  release:
    types: [created]
  workflow_dispatch:
    inputs:
      release_type:
        required: false
        type: string
      project_name:
        description: 'Enter the project name'
        required: true
        type: string

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: Install Angular CLI
        run: npm install -g @angular/cli
      
      - name: Install dependencies  
        run: npm ci

      - name: Build Angular Project
        run: ng build ${{ github.event.inputs.project_name }}
        

  debug:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: List Files in dist
        run: ls -R dist

      - name: Print Current Directory
        run: pwd

  publish:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 16

      - name: Publish to GitHub Packages
        run: |
          cd dist/${{ github.event.inputs.project_name }}
          npm config set //npm.pkg.github.com/:_authToken ${{ secrets.GITHUB_TOKEN }}
          npm publish --access public
          env:
            NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Solution

  • This is the yaml file I've come up with. Note: Each run starts from the root folder. Note: to carry items to the next job you've to upload artifactsand download them in the next job.

    name: Angular Package
    
    on:
      release:
       types: [created]
       workflow_dispatch:
        inputs:
         project_name:
         description: 'Enter the project name'
         required: true
         type: string
    
    jobs:
     build:
      permissions: write-all
      runs-on: ubuntu-latest
      steps:
       - uses: actions/checkout@v3
       - uses: actions/setup-node@v3
         with:
          node-version: 16
          registry-url: https://npm.pkg.github.com/
    
       - name: Install Angular CLI
         run: npm install -g @angular/cli
      
      - name: Install dependencies  
        run: npm ci
    
      - name: Build Angular Project
        run: ng build ${{ github.event.inputs.project_name }}
    
      - name: Upload Artifacts
        uses: actions/upload-artifact@v3
        with:
          name: build-artifacts
          path: dist/
    
        
    
    debug:
     needs: build
     permissions: write-all
     runs-on: ubuntu-latest
     steps:
      - name: Download Artifacts
        uses: actions/download-artifact@v3
        with:
          name: build-artifacts
          path: dist
    
      - name: List Files in dist
        run: ls -R dist
    
      - name: Print Current Directory
        run: pwd
    
    publish:
     needs: build
     permissions: write-all
     runs-on: ubuntu-latest
     steps:
      - name: Checkout code
        uses: actions/checkout@v2
    
      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 16
          registry-url: https://npm.pkg.github.com/
    
      - name: Configure npm registry for GitHub Packages
        run: npm config set registry https://npm.pkg.github.com/
    
      - name: Download Artifacts
        uses: actions/download-artifact@v3
        with:
          name: build-artifacts
          path: dist
    
      - name: List Files in dist
        run: ls -R dist
    
      - name: Changing Directory
        run: |
          cd dist/${{ github.event.inputs.project_name }}
    
      - name: Publish To Github
        run: |
          cd dist/${{ github.event.inputs.project_name }}
          npm config set //npm.pkg.github.com/:_authToken ${{ secrets.GITHUB_TOKEN }}
          npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}