Angular workspace NPM package creation using GitHub Actions

I’m trying to set up a GitHub Action to create NPM packages for different libraries in my Angular workspace. The build step works fine, but I’m running into issues with the publish step.

Here’s what’s happening:

  1. The build process completes successfully
  2. The dist folder is created and added to .gitignore
  3. When trying to publish, I get an error saying the dist folder doesn’t exist
  4. The error message is Error: Process completed with exit code 2.

I’m confused about why this is happening. The dist folder should be there after the build, right? Has anyone encountered this issue before? Any ideas on how to fix it?

Here’s a simplified version of my workflow:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
      - run: npm ci
      - run: ng build ${{ inputs.project_name }}

  publish:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
      - run: |
          cd dist/${{ inputs.project_name }}
          npm publish

Any help would be appreciated!

hey man, i had the same problem. turns out the dist folder doesn’t carry over between jobs. try using actions/upload-artifact and actions/download-artifact to save and restore the dist folder. worked for me! good luck with ur publishing!

I’ve encountered this issue before, and it’s related to how GitHub Actions isolates job environments. Each job runs in a separate context, so the dist folder from your build job isn’t accessible in the publish job.

To resolve this, you need to persist the dist folder between jobs. Use GitHub’s artifact actions to upload and download the dist folder. Modify your workflow like this:

jobs:
  build:
    # Existing build steps...
    - uses: actions/upload-artifact@v3
      with:
        name: dist
        path: dist

  publish:
    needs: build
    # Existing publish setup...
    - uses: actions/download-artifact@v3
      with:
        name: dist
    - run: npm publish

This should fix the ‘dist folder not found’ error. Adjust paths if needed based on your project structure.

I’ve dealt with a similar issue before, and it’s likely related to how GitHub Actions handles job contexts. Each job runs in a fresh environment, so the dist folder created in your build job isn’t available in the publish job.

To fix this, you need to persist the dist folder between jobs. Use the actions/upload-artifact and actions/download-artifact actions to achieve this. Here’s how you can modify your workflow:

jobs:
  build:
    # ... existing build steps ...
    - uses: actions/upload-artifact@v2
      with:
        name: dist
        path: dist

  publish:
    needs: build
    # ... existing publish setup ...
    - uses: actions/download-artifact@v2
      with:
        name: dist
    - run: npm publish

This should resolve the ‘dist folder not found’ error. Remember to adjust paths as needed based on your project structure. Hope this helps!