Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lerna publish ends up in Error 128 on AWS CodeBuild after successfully published package #3022

Open
jhkruse opened this issue Nov 3, 2021 · 3 comments

Comments

@jhkruse
Copy link

jhkruse commented Nov 3, 2021

We want to use AWS CodeBuild for publishing our lerna packages. After lerna successfully published our packages it ends up in an Error 128 without any further log information.
We use
lerna publish from-package --git-head ${CODEBUILD_RESOLVED_SOURCE_VERSION} --no-git-reset --yes
in buildspec.yml. I also tried to install git in CodeBuild using git-credential-helper: yes.

On CodeBuild there is no .git folder. So I could reproduce the problem on renaming my .git folder locally.
I had a look at the Codebase and saw that in bump from-git as well as in bump from-package the function verifyWorkingTreeClean is called. This function will fail on CodeBuild because of no existing .git folder.

Expected Behavior

  • No Error 128 after successfully published
  • Further log information on this error.

Current Behavior

  • Error 128 after successfully published
  • No further log information on this error.

Possible Solution

Create an option for suppressing the verifyWorkingTreeClean function like lerna publish --no-verify-working-tree-clean.

Steps to Reproduce (for bugs)

  1. Call lerna publish from-package --git-head ${CODEBUILD_RESOLVED_SOURCE_VERSION} --no-git-reset --yes in AWS CodeBuild from buildspec.yml, MAKEFILE or package.json.
  2. Or rename your local .git folder
lerna.json

{
  "version": "independent",
  "npmClient": "npm",
  "command": {
    "create": {
      "access": "restricted",
      "description": "TODO",
      "homepage": "TODO",
      "keywords": [
        "digital-office"
      ],
      "license": "TODO",
      "registry": "https://registry.npmjs.org/"
    },
    "publish": {
      "ignoreChanges": [
        "*.md"
      ],
      "message": "chore(release): publish %s",
      "registry": "https://registry.npmjs.org"
    },
    "bootstrap": {
      "ignore": "component-*",
      "npmClientArgs": [
        "--no-package-lock"
      ]
    }
  },
  "packages": [
    "packages/*"
  ]
}

Context

Deploy packages with lerna in AWS CodeBuild.

Your Environment

Executable Version
lerna --version ~4.0.0
npm --version 6.14.13
yarn --version VERSION
node --version v14.17.2
OS Version
NAME VERSION
Ubuntu 20.04
macOS Monterey 12.0.1
@signal-intrusion
Copy link

signal-intrusion commented Nov 15, 2021

I can confirm that this is a persistent issue. I added logLevel=silly and disabled as many git thingies as lerna allows: "lerna publish from-package --git-head ${CODEBUILD_RESOLVED_SOURCE_VERSION} --no-git-tag-version --no-git-reset --yes --loglevel silly",

One possible source is that lerna still tries to use thegit describe command: lerna sill EWORKINGTREE Command failed with exit code 128: git describe --always --long --dirty --first-parent. I see that when publishing from-package you attempt to validate the working tree:

chain = chain
.then(() => this.verifyWorkingTreeClean())
.catch((err) => {
// an execa error is thrown when git suffers a fatal error (such as no git repository present)
if (err.failed && /git describe/.test(err.command)) {
// (we tried)
this.logger.silly("EWORKINGTREE", err.message);
this.logger.notice("FYI", "Unable to verify working tree, proceed at your own risk");
} else {
// validation errors should be preserved
throw err;
}
});
This is almost certainly where the 128 exit code is assigned. Lerna implicity assigns any exitCode on error with no option to surpress, although the publishing continues in this case...
function wrapError(spawned) {
if (spawned.pkg) {
return spawned.catch((err) => {
// ensure exit code is always a number
err.exitCode = getExitCode(err);
// log non-lerna error cleanly
err.pkg = spawned.pkg;
throw err;
});
}
return spawned;
}

Logs before publishing:

lerna sill argv {
326 | lerna sill argv   _: [ 'publish' ],
327 | lerna sill argv   'git-head': '226d864d259de5f519e7cfeaffe89db7953d0517',
328 | lerna sill argv   gitHead: '226d864d259de5f519e7cfeaffe89db7953d0517',
329 | lerna sill argv   'git-reset': false,
330 | lerna sill argv   gitReset: false,
331 | lerna sill argv   push: false,
332 | lerna sill argv   yes: true,
333 | lerna sill argv   y: true,
334 | lerna sill argv   loglevel: 'silly',
335 | lerna sill argv   composed: 'publish',
336 | lerna sill argv   lernaVersion: '4.0.0',
337 | lerna sill argv   '$0': 'node_modules/.bin/lerna',
338 | lerna sill argv   bump: 'from-package'
339 | lerna sill argv }
340 | lerna notice cli v4.0.0
341 | lerna verb rootPath /codebuild/output/src125936439/src
342 | lerna info ci enabled
343 | lerna verb session daad521d82ff5d27
344 | lerna verb user-agent lerna/4.0.0/node@v12.22.2+x64 (linux)
345 | lerna sill EWORKINGTREE Command failed with exit code 128: git describe --always --long --dirty --first-parent
346 | lerna sill EWORKINGTREE fatal: not a git repository (or any parent up to mount point /codebuild)
347 | lerna sill EWORKINGTREE Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
348 | lerna notice FYI Unable to verify working tree, proceed at your own risk
349 | lerna sill getUnpublishedPackages
350 |  
351 | Found 7 packages to publish:
352 | - @namespace/bui-intl => 2.0.308
353 | - @namespace/bui-light => 2.0.308
354 | - @namespace/bui-react => 2.0.308
355 | - @namespace/bui-style-tokens => 2.0.308
356 | - @namespace/bui-webpack-config => 2.0.308
357 | - @namespace/cra-template-bui => 2.0.308
358 | - @namespace/eslint-config-bui => 2.0.308
359 |  
360 | lerna info auto-confirmed
361 | lerna info publish Publishing packages to npm...
362 | lerna notice Skipping all user and access validation due to third-party registry
363 | lerna notice Make sure you're authenticated properly ¯\_(ツ)_/¯
364 | lerna WARN ENOLICENSE Packages @namespace/bui-intl, @namespace/bui-light, @namespace/bui-react, @namespace/bui-style-tokens, @namespace/bui-webpack-config, @namespace/cra-template-bui, and @namespace/eslint-config-bui are missing a license.
365 | lerna WARN ENOLICENSE One way to fix this is to add a LICENSE.md file to the root of this repository.
366 | lerna WARN ENOLICENSE See https://choosealicense.com for additional guidance.
367 | lerna sill lifecycle No script for "prepublish" in "@namespace/bui", continuing
368 | lerna sill lifecycle "prepare" starting in "@namespace/bui"
369 | lerna info lifecycle @namespace/bui@2.0.308~prepare: @namespace/bui@2.0.308

Logs after publishing:

lerna sill lifecycle No script for "publish" in "@namespace/bui", continuing
--
933 | lerna sill lifecycle No script for "postpublish" in "@namespace/bui", continuing
934 | Successfully published:
935 | - @namespace/bui-intl@2.0.308
936 | - @namespace/bui-light@2.0.308
937 | - @namespace/bui-react@2.0.308
938 | - @namespace/bui-style-tokens@2.0.308
939 | - @namespace/bui-webpack-config@2.0.308
940 | - @namespace/cra-template-bui@2.0.308
941 | - @namespace/eslint-config-bui@2.0.308
942 | lerna success published 7 packages
943 | npm ERR! code ELIFECYCLE
944 | npm ERR! errno 128
945 | npm ERR! @namespace/bui@2.0.308 publish:all: `lerna publish from-package --git-head ${CODEBUILD_RESOLVED_SOURCE_VERSION} --no-git-reset --no-push --yes --loglevel silly`
946 | npm ERR! Exit status 128
947 | npm ERR!
948 | npm ERR! Failed at the @namespace/bui@2.0.308 publish:all script.
949 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
950 |  
951 | npm ERR! A complete log of this run can be found in:
952 | npm ERR!     /root/.npm/_logs/2021-11-15T19_41_26_583Z-debug.log

Contents of /root/.npm/_logs/2021-11-15T19_41_26_583Z-debug.log:



0 info it worked if it ends with ok
--
960 | 1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'publish:all' ]
961 | 2 info using npm@6.14.13
962 | 3 info using node@v12.22.2
963 | 4 verbose run-script [ 'prepublish:all', 'publish:all', 'postpublish:all' ]
964 | 5 info lifecycle @namespace/bui@2.0.308~prepublish:all: @namespace/bui@2.0.308
965 | 6 info lifecycle @namespace/bui@2.0.308~publish:all: @namespace/bui@2.0.308
966 | 7 verbose lifecycle @namespace/bui@2.0.308~publish:all: unsafe-perm in lifecycle true
967 | 8 verbose lifecycle @namespace/bui@2.0.308~publish:all: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/codebuild/output/src125936439/src/node_modules/.bin:/codebuild/output/src125936439/src/build-tools/bin:/usr/local/bin/sbt/bin:/root/.phpenv/shims:/root/.phpenv/bin:/root/.goenv/shims:/root/.goenv/bin:/go/bin:/root/.phpenv/shims:/root/.phpenv/bin:/root/.pyenv/shims:/root/.pyenv/bin:/root/.rbenv/shims:/usr/local/rbenv/bin:/usr/local/rbenv/shims:/root/.dotnet/:/root/.dotnet/tools/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/tools:/usr/local/android-sdk-linux/tools:/usr/local/android-sdk-linux/tools/bin:/usr/local/android-sdk-linux/platform-tools:/codebuild/user/bin
968 | 9 verbose lifecycle @namespace/bui@2.0.308~publish:all: CWD: /codebuild/output/src125936439/src
969 | 10 silly lifecycle @namespace/bui@2.0.308~publish:all: Args: [
970 | 10 silly lifecycle   '-c',
971 | 10 silly lifecycle   'lerna publish from-package --git-head ${CODEBUILD_RESOLVED_SOURCE_VERSION} --no-git-reset --no-push --yes --loglevel silly'
972 | 10 silly lifecycle ]
973 | 11 silly lifecycle @namespace/bui@2.0.308~publish:all: Returned: code: 128  signal: null
974 | 12 info lifecycle @namespace/bui@2.0.308~publish:all: Failed to exec publish:all script
975 | 13 verbose stack Error: @namespace/bui@2.0.308 publish:all: `lerna publish from-package --git-head ${CODEBUILD_RESOLVED_SOURCE_VERSION} --no-git-reset --no-push --yes --loglevel silly`
976 | 13 verbose stack Exit status 128
977 | 13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
978 | 13 verbose stack     at EventEmitter.emit (events.js:314:20)
979 | 13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
980 | 13 verbose stack     at ChildProcess.emit (events.js:314:20)
981 | 13 verbose stack     at maybeClose (internal/child_process.js:1022:16)
982 | 13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
983 | 14 verbose pkgid @namespace/bui@2.0.308
984 | 15 verbose cwd /codebuild/output/src125936439/src
985 | 16 verbose Linux 4.14.248-189.473.amzn2.x86_64
986 | 17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "publish:all"
987 | 18 verbose node v12.22.2
988 | 19 verbose npm  v6.14.13
989 | 20 error code ELIFECYCLE
990 | 21 error errno 128
991 | 22 error @namespace/bui@2.0.308 publish:all: `lerna publish from-package --git-head ${CODEBUILD_RESOLVED_SOURCE_VERSION} --no-git-reset --no-push --yes --loglevel silly`
992 | 22 error Exit status 128
993 | 23 error Failed at the @namespace/bui@2.0.308 publish:all script.
994 | 23 error This is probably not a problem with npm. There is likely additional logging output above.
995 | 24 verbose exit [ 128, true ]

@signal-intrusion
Copy link

This is not going to be unique to CodeBuild. It will happen anywhere the consumer is not using git.

@paul-leo
Copy link
Contributor

It happend when i use lerna publish in ci , and i fixed it
#3327

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants