question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve compatibility with CI/CD

See original GitHub issue

Context

I have setup lerna and I want to use lerna version/ lerna publish within my CI/CD pipeline in GitLab.

Expected Behavior

Get branch name correctly.

Current Behavior

In GitLab the branch is checked out as detached HEAD state so currentBranch is always HEAD which leads to issues:

Possible Solution

semantic-release is using env-ci to determine the correct branch name: https://github.com/semantic-release/semantic-release/blob/7a939a897097a730f1579002ed641a583d3381c4/index.js#L6-L26

lerna is using an own git command instead of using env-ci:

https://github.com/lerna/lerna/blob/5344820fc65da081d17f7fd2adb50ffe7101905b/commands/version/lib/get-current-branch.js#L11

I am open to create another PR (beside my others https://github.com/lerna/lerna/issues/2333) for this solution.

A solution for this is to use env-ci additionally, and use the git command if the returned branch is undefined

Apart from that I found another code where is-ci is used:

https://github.com/lerna/lerna/blob/5344820fc65da081d17f7fd2adb50ffe7101905b/core/command/index.js#L129

Perhaps it should be considered to remove that package and also replace it with env-ci. But there are breaking changes because both packages support different CI systems:

env-ci is-ci (ci-info)
AWS CodeBuild AWS CodeBuild
AppVeyor AppVeyor
Azure Pipelines
Bamboo Bambooby Atlassian
Bitbucket Bitbucket Pipelines
Bitrise Bitrise
Buddy Buddy
Buildkite Buildkite
CircleCI CircleCI
Cirrus CI Cirrus CI
Codeship Codeship
Codefresh
Drone Drone
dsari
GitHub Actions
GitLab CI/CD GitLab CI
GoCD
Hudson
Jenkins Jenkins CI
Magnum CI
Netlify CI
Nevercode
Puppet
Sail CI Sail CI
Scrutinizer
Semaphore Semaphore
Shippable Shippable
Solano CI
Strider CD
TaskCluster
TeamCity TeamCityby JetBrains
Travis CI Travis CI
Visual Studio Team Services
Wercker

Your Environment

Executable Version
lerna --version 3.18.4
npm --version 6.4.1
yarn --version 1.19.1
node --version v10.15.3
OS Version
WSL On Windows 10

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:11
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
matzeeablecommented, Dec 17, 2019

Another issue on GitLab CI, that postversion lifecycle could not run:

 lerna WARN lifecycle @wp-reactjs-multi-starter/wp-reactjs-starter@1.2.0~version: cannot run in wd @wp-reactjs-multi-starter/wp-reactjs-starter@1.2.0 yarn grunt postversion (wd=/builds/devowl.io/wp-reactjs-starter/plugins/wp-reactjs-starter)

Has anyone experienced this before?

EDIT:

If your CI docker container runs as root user, you must add below line before all your lerna version or lerna publish commands. Afterwards lifecycle events will work.

yarn config set unsafe-perm true

Why this is needed for root users you can read here: What-does-unsafe-perm-in-npm-actually-do

How to push back to repository? I have found also a way to use lerna in GitLab CI. Please refer to this link or shortly said, use a GITLAB_TOKEN variable:

variables:
    GL_TOKEN: $GITLAB_TOKEN

    # [...]
    script:
        - git remote set-url origin "https://gitlab-ci-token:$GITLAB_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git"
        - lerna publish --yes
0reactions
jenniferphamcommented, Jul 13, 2020

I think you may need to checkout to master branch.
I was able to get my CI to work and publish through Github Actions. Even if you’re not using Github Actions, maybe this could give you an idea of what to do. I added SSH-key and Github token which had write access to the repo.

    steps:
      - name: Copy repo code
        uses: actions/checkout@v2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}

     - name: Configure git credentials
        uses: OleksiyRudenko/gha-git-credentials@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Publish New Version and Release
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
          GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
        run: |
          lerna publish --yes
Read more comments on GitHub >

github_iconTop Results From Across the Web

A Guide for Improving CI/CD Pipelines and More Successful ...
A Guide for Improving CI/CD Pipelines and More Successful Deployments · Definition Refresh: · Tip #1: Be Specific on Testing · Tip #2:...
Read more >
How to keep up with CI/CD best practices - GitLab
In this post, we lookat Continuous Integration/Continuous Delivery (CI/CD), how to implement some best practices and why it is important.
Read more >
Best Practices for Successful CI/CD | TeamCity CI/CD Guide
Use the opportunity to improve your CI/CD practice and make it more robust and effective. By allowing team members to experiment and innovate...
Read more >
CI/CD pipelines explained: Everything you need to know
Better software maintenance. Bugs can take weeks or months to fix in traditional software development, but the constant flow of a CI/CD ......
Read more >
CI/CD Pipeline: A Gentle Introduction - Semaphore
CI, short for Continuous Integration, is a software development practice in which all developers merge code changes in a central repository ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found