Giga Meta
Giga Meta

Reputation: 319

Semantic release not publishing correct folder

For the past few days, I'm trying to publish my package to github by using semantic-release. Unfortunately, I can't publish the correct folder as source code (zip) file in my npm package hosted on github.

My github action pipeline:

on:
  push:
    branches:
      - main

env:
  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

defaults:
  run:
    working-directory: ./frontend

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: 'npm'
          cache-dependency-path: ./frontend
      - name: Install packages
        run: npm install
      - name: Build frontend
        run: npm run build
      - name: Copy json file to dist dir
        run: cp package.json ./dist
      - name: Run semantic release and publish package
        run: |
          cd ./dist
          pwd
          npm run semantic-release

It's supposed to publish the dist folder, but I see the whole project directory as the source code output to npm. It's not publishing my build folder. When I run pwd, I'm on the correct path: /home/runner/work/test/test/frontend/dist

Semantic-release is also not respecting my property in my package.json file:

"files": [
  "/dist"
]

I specifically want to output the dist folder, but unfortunately, everything is in the output folder except the dist folder.

I also tried adding a pkgRoot property to to the '@semantic-release/npm' module, but still! No dist folder being published.

['@semantic-release/npm', { 'pkgRoot': './dist' }],

What can be the issue of this problem?

Upvotes: 5

Views: 2415

Answers (1)

ssbarbee
ssbarbee

Reputation: 1712

I was also having this issue yesterday and this is what worked for me. Notice that I omitted a lot of configuration stuff from the files mentioned not to "bloat" the answer. Let me know if this works for you!

package.json

Remove the "files" key.

"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
  "build": "rm -rf dist && tsc --project tsconfig.build.json && cp package.json dist/package.json",
}

semantic-release/npm configuration

"@semantic-release/npm", { "pkgRoot": "./dist" }],

semantic-release/git configuration

[
   "@semantic-release/git",
   {
      "assets": [
         "package.json",
         "README.md",
         "CHANGELOG.md",
         "dist/**/*.{js}"
      ],
      "message": "chore: Release ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
        }
]

tsconfig.json

"compilerOptions": {
  "rootDir": "src",
  "outDir": "./dist",
}

Upvotes: 0

Related Questions