pmowrer / semantic-release-monorepo

Apply semantic-release's automatic publishing to a monorepo.
MIT License
517 stars 80 forks source link

Error in semantic-release-monorepo: "Cannot read properties of undefined (reading 'map')" During Automated Publishing in Monorepo #158

Open wojtekKrol opened 3 months ago

wojtekKrol commented 3 months ago

I am trying to set up a monorepo with automated publishing of packages to both npm and GitHub Packages. My goal is to only publish packages that have been updated (detecting changes in files). I have configured my repository to use semantic-release with semantic-release-monorepo, but I am encountering errors during the release process.

This is the repository: https://github.com/paxcode-it/zodify-forms/tree/dev

Current Setup

Monorepo Structure

packages/
  - zod-to-fields/ 
    - release.config.cjs
    - package.json
  - zodify-forms/
    - release.config.cjs
    - package.json

Release Configuration (release.config.cjs) same for each package

/**
 * @type {import('semantic-release').GlobalConfig}
 */
module.exports = {
  extends: "semantic-release-monorepo",
  branches: [
    { name: "next", channel: "next", prerelease: true },
    { name: "experimental", channel: "experimental", prerelease: true },
    { name: "beta", channel: "beta", prerelease: true },
    { name: "dev", channel: "dev", prerelease: true },
  ],
  plugins: [
    ["@semantic-release/commit-analyzer", {
      preset: "conventionalcommits",
      releaseRules: [
        { breaking: true, release: "major" },
        { revert: true, release: "patch" },
        { type: "feat", release: "minor" },
        { type: "fix", release: "patch" },
        { type: "perf", release: "patch" },
        { type: "refactor", release: "patch" },
        { type: "build", release: "patch" },
        { type: "docs", release: "patch" },
        { type: "chore", release: false },
        { type: "test", release: false },
        { type: "ci", release: false },
        { type: "style", release: false },
      ],
      parserOpts: { noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES"] },
    }],
    ["@semantic-release/release-notes-generator", {
      preset: "conventionalcommits",
      presetConfig: {
        types: [
          { type: "revert", section: "Reverts", hidden: false },
          { type: "feat", section: "Features", hidden: false },
          { type: "fix", section: "Bug Fixes", hidden: false },
          { type: "perf", section: "Performance improvements", hidden: false },
          { type: "refactor", section: "Refactors", hidden: false },
          { type: "build", section: "Build System", hidden: false },
          { type: "docs", section: "Documentation", hidden: false },
          { type: "chore", hidden: true },
          { type: "test", hidden: true },
          { type: "ci", hidden: true },
          { type: "style", hidden: true },
        ],
      },
      parserOpts: { noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES"] },
    }],
    "@semantic-release/npm",
    "@semantic-release/github",
    ["@semantic-release/git", {
      "assets": ["package.json"],
      "message": "release(version): Release ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
    }],
  ],
};

GitHub Actions CI/CD Configuration

name: CI/CD

on:
  push:
    paths:
      - 'packages/**'
    branches:
      - main
      - beta
      - next
      - experimental
      - dev
  pull_request:
    paths:
      - 'packages/**'

jobs:
  CI:
    ...

  CD:
    permissions:
      contents: write
      issues: write
      pull-requests: write
      id-token: write
    if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 2
      - uses: pnpm/action-setup@v3
        with:
          version: 9
      - name: Read .nvmrc
        run: echo ::set-output name=NVMRC::$(cat .nvmrc)
        id: nvm
      - name: Setup Node.js (.nvmrc)
        uses: actions/setup-node@v4
        with:
          node-version: '${{ steps.nvm.outputs.NVMRC }}'
          cache: pnpm
          cache-dependency-path: './pnpm-lock.yaml'
      - run: pnpm install --frozen-lockfile
      - run: pnpm run build:lib
      - name: Release lib to NPM Registry and GitHub Packages
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GH_TOKEN: ${{ secrets.GH_TOKEN }}
        run: pnpm run deploy:lib

Problem Encountered

I am encountering an error during the release process:

TypeError: Cannot read properties of undefined (reading 'map')
    at withFiles (file:///home/runner/work/zodify-forms/zodify-forms/node_modules/.pnpm/semantic-release-monorepo@8.0.2_semantic-release@24.0.0/node_modules/semantic-release-monorepo/src/only-package-commits.js:26:13)
    at onlyPackageCommits (file:///home/runner/work/zodify-forms/zodify-forms/node_modules/.pnpm/semantic-release-monorepo@8.0.2_semantic-release@24.0.0/node_modules/semantic-release-monorepo/src/only-package-commits.js:38:34)
    ...

Additionally, I received an ENOGHTOKEN error indicating no GitHub token is specified. Full logs:https://github.com/paxcode-it/zodify-forms/actions/runs/10028361403/job/27715190158

Question

Is it possible to achieve what I want using semantic-release-monorepo? Specifically, I need to:

  1. Automatically publish only the packages that have been updated.
  2. Publish these packages to both npm and GitHub Packages.

If there are any alternative approaches or additional configurations required to achieve this, I would appreciate any guidance or examples. ( I couldn't find any open source project with those requirements)

Thank you

juliosampaio commented 2 months ago

I'm facing the exact same issue:

[10:07:00 AM] [semantic-release] › ✘  An error occurred while running semantic-release: TypeError: Cannot read properties of undefined (reading 'map')
    at withFiles (file:///runner/_work/acme-react-libraries/acme-react-libraries/node_modules/semantic-release-monorepo/src/only-package-commits.js:26:13)
    at onlyPackageCommits (file:///runner/_work/acme-react-libraries/acme-react-libraries/node_modules/semantic-release-monorepo/src/only-package-commits.js:38:34)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///runner/_work/acme-react-libraries/acme-react-libraries/node_modules/semantic-release-monorepo/src/options-transforms.js:8:58
    at async file:///runner/_work/acme-react-libraries/acme-react-libraries/node_modules/semantic-release-monorepo/src/lens-utils.js:7:17
    at async file:///runner/_work/acme-react-libraries/acme-react-libraries/node_modules/semantic-release-monorepo/src/only-package-commits.js:86:5 {
  pluginName: '[Function: semantic-release-monorepo]'
}

Was you able to solve that @wojtekKrol ?

wojtekKrol commented 2 months ago

Was you able to solve that @wojtekKrol ?

Unfortunately not yet

wojtekKrol commented 2 months ago

@juliosampaio please ping me once you resolve your problem okey?

juliosampaio commented 2 months ago

Hey @wojtekKrol , we actually decided to use Changesets instead, which is the opposite approach on all the automation provided by semantic-release, but fits perfectly on our use case. I'm glad we did tbh 😀

wojtekKrol commented 2 months ago

@juliosampaio and do you have case that includes monorepo with multiple libraries published to npm/github registry?

Can you share configs?

Thanks

dionysiusmarquis commented 2 weeks ago

This seems to happen if another plugin throws an error. I had to comment out extends: “semantic-release-monorepo” to be able to see the actual error.