Azure DevOps / Pipeline & Artifacts / Unable to publish packages with @changesets/cli

124 views Asked by At

i try to manage npm packages with @changesets/cli in a monorepo project, and i try to make it works but i got errors when changesets try to find branch :

+ npx changeset status
  error Error: Failed to find where HEAD diverged from main. Does main exist?
  error     at getDivergedCommit (/home/vsts/work/1/s/node_modules/.pnpm/@[email protected]/node_modules/@changesets/git/dist/git.cjs.dev.js:66:11)
  error     at async getChangedFilesSince (/home/vsts/work/1/s/node_modules/.pnpm/@[email protected]/node_modules/@changesets/git/dist/git.cjs.dev.js:198:22)
  error     at async Object.getChangedPackagesSinceRef (/home/vsts/work/1/s/node_modules/.pnpm/@[email protected]/node_modules/@changesets/git/dist/git.cjs.dev.js:239:24)
  error     at async getStatus (/home/vsts/work/1/s/node_modules/.pnpm/@[email protected]/node_modules/@changesets/cli/dist/cli.cjs.dev.js:1174:27)
  error     at async run$2 (/home/vsts/work/1/s/node_modules/.pnpm/@[email protected]/node_modules/@changesets/cli/dist/cli.cjs.dev.js:1450:11)

Here is my task in a part of my pipeline config :

pool:
  vmImage: ubuntu-latest

variables:
  IS_MAIN: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')]

steps:
- task: Bash@3
  name: version
  displayName: 'Release version'
  condition: and(succeeded(), eq(variables.IS_MAIN, true))
  env:
    GIT_TOKEN: $(System.AccessToken)
    CI: true
  inputs:
    targetType: 'inline'
    script: |
      set -x

      git fetch --all
      git switch $(basename $(Build.SourceBranch))

      npx changeset status --since origin/main
      if [ $? -eq 0 ]; then
        npx changeset version
        git add .changeset
        npx changeset publish
        git -c http.extraheader="AUTHORIZATION: bearer $GIT_TOKEN" push
        git -c http.extraheader="AUTHORIZATION: bearer $GIT_TOKEN" push origin --tags
      fi

my baseBranch config of .changeset/config.json file is main, i tried with origin/main. i also tried to directly tell to changeset that origin/main is the HEAD like npx changeset status --since origin/main

Using theses commands still works in local but not in the pipeline environnement. This pipeline are getting me sick for the last 3 days so i don't have any other choices to come here.

0

There are 0 answers