How to use npm version to increment the counter behind the prepatch / preid suffix - npm

I'm trying to find out how to correctly use npm version with prepatch (also premajor or preminor) / preid options to increment the counter behind the suffix.
e.g.:
I have a v.0.5.22 and want to append -rc
I used the command npm version prepatch --preid rc
then I get v.0.5.23-rc.0, fine so far.
but the next time I'm using the same command I end up with v.0.5.24-rc.0,
what I want is to get v.0.5.23-rc.1 instead
How can I only increment the counter behind -rc. and keep the patch number?
Or am I misunderstanding the purpose of prepatch / preid?

Alright, I'll answer my own question for future reference.
After having v.0.5.23-rc.0 the command to only bump the number behind the . has to be:
npm version prerelease
Then I would get v.0.5.23-rc.1.

An alternative to npm version would be to write a bash script.
Ended up with this, fetching the version from the package.json
#!/usr/bin/env bash
set -e
packageJsonLocation="../package.json"
current_version=$(grep '"version":' $packageJsonLocation | cut -d\" -f4)
pre=0
if [ -z "${current_version}" ]; then
echo "No version found in package.json"
exit 1
fi
if [[ $current_version =~ ^.*-.* ]]; then
# increment prerelease version
IFS='-' read -ra array_pre <<< "$current_version"
IFS='.' read -ra array <<< "${array_pre[0]}"
pre=$(( ${array_pre[1]} + 1))
else
IFS='.' read -ra array <<< "${current_version}"
fi
new_version="${array[0]}.${array[1]}.${array[2]}-${pre}"
echo "Pre version: ${current_version} -> ${new_version}"
# Output
2.9.3 -> 2.9.3-0
and
2.9.3-1 -> 2.9.3-2

Related

Node reverts to old version and NVM disappears when I close terminal and restart

Issue
I have installed NVM. Each time I close the terminal and open it back up, NVM disappears and my node version rolls back from 14 to 12.
Every time I open my terminal back up, I notice the node version rolls back. I try to use nvm, and will get bash: nvm: command not found. I have to run this script again to get it working every time.
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
I noticed the meta description when you google NVM says it's designed to be used per-user and invoked per shell. However, the setup article linked in the first SO post below mentioned installing, killing the terminal, and opening it back up with nvm still being loaded.
Anyone know what I can do so that I don't have to reinstall nvm every time I open the terminal?
Steps taken to resolve
I have reviewed this SO post and also this one. From those two I have tried the following suggestions:
I have run nvm alias default v14.17.1 in my root directory
I have pasted the following script into both .zshrc and .bashrc
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Edit: I am on MacOS Big Sur 11.5.2

CI-pipeline ignore any commands that fail in a given step

I'm trying to debug a CI pipeline and want to create a custom logger stage that dumps a bunch of information about the environment in which the pipeline is running.
I tried adding this:
stages:
- logger
logger-commands:
stage: logger
allow_failure: true
script:
- echo 'Examining environment'
- echo PWD=$(pwd) Using image ${CI_JOB_IMAGE}
- git --version
- echo --------------------------------------------------------------------------------
- env
- echo --------------------------------------------------------------------------------
- npm --version
- node --version
- echo java -version
- mvn --version
- kanico --version
- echo --------------------------------------------------------------------------------
The problem is that the Java command is failing because java isn't installed. The error says:
/bin/sh: eval: line 217: java: not found
I know I could remove the line java -version, but I'm trying to come up with a canned logger that I could use in all my CI-Pipelines, so it would include: Java, Maven, Node, npm, python, and whatever else I want to include and I realize that some of those commands will fail because some of the commands are not found.
Searching for the above solution got me close.
GitLab CI: How to continue job even when script fails - Which did help. By adding allow_failure: true I found that even if the logger job failed the remaining stages would run (which is desirable). The answer also suggests a syntax to wrap commands in which is:
./script_that_fails.sh > /dev/null 2>&1 || FAILED=true
if [ $FAILED ]
then ./do_something.sh
fi
So that is helpful, but my question is this.
Is there anything built into gitlab's CI-pipeline syntax (or bash syntax) that allows all commands in a given step to run even if one command fails?
Is it possible to allow for a script in a CI/CD job to fail? - suggests adding the UNIX bash OR syntax as shown below:
- npm --version || echo nmp failed
- node --version || echo node failed
- echo java -version || echo java failed
That is a little cleaner (syntax) but I'm trying to make it simpler.
The answers already mentioned are good, but I was looking for something simpler so I wrote the following bash script. The script always returns a zero exit code so the CI-pipeline always thinks the command was successful.
If the command did fail, the command is printed along with the non-zero exit code.
# File: runit
#!/bin/sh
"$#"
EXITCODE=$?
if [ $EXITCODE -ne 0 ]
then
echo "CMD: $#"
echo "Ignored exit code ($EXITCODE)"
fi
exit 0
Testing it as follows:
./runit ls "/bad dir"
echo "ExitCode = $?"
Gives this output:
ls: cannot access /bad dir: No such file or directory
CMD: ls /bad dir
Ignored exit code (2)
ExitCode=0
Notice even though the command failed the ExitCode=0 shows what the ci-pipeline will see.
To use it in the pipeline, I have to have that shell script available. I'll research how to include it, but it must be in the CI runner job. For example,
stages:
- logger-safe
logger-safe-commands:
stage: logger-safe
allow_failure: true
script:
- ./runit npm --version
- ./runit java -version
- ./runit mvn --version
I don't like this solution because it requires extra file in the repo but this is in the spirit of what I'm looking for. So far the simplest built in solution is:
- some_command || echo command failed $?

How do I find the currently activated version with nvm?

I use nvm and want to find out which version of node is currently running.
If the system version is being used, I want to see the string system.
Ideally, I'm looking for a string to put in my prompt.
run this in terminal
nvm current
or
node -v
nvm ls
for list all version
nvm use version_name
for use that version
In bash:
[[ $NVM_BIN =~ ([^/]+)/bin$ ]] && echo "${BASH_REMATCH[2]}" || echo "system"
For zsh, first do:
setopt BASH_REMATCH
This is much faster than using nvm current, especially for use in a prompt:
$ time nvm current
system
real 0m0.188s
user 0m0.149s
sys 0m0.042s
Compared with:
$ time [[ $NVM_BIN =~ ([^/]+)/bin$ ]] && echo "${BASH_REMATCH[2]}" || echo "system"
real 0m0.009s
user 0m0.002s
sys 0m0.007s
system
Almost 0.2 seconds vs only 0.009 seconds.

Syntax error in rvm bash scripts

My rvm is not working, probably due to an error. When I open new console, it says:
-bash: /Users/amorfis/.rvm/scripts/cd: line 14: syntax error near unexpected token `('
-bash: /Users/amorfis/.rvm/scripts/cd: line 14: ` cd() { __zsh_like_cd cd "$#" ; }'
It's hard to say where the script .rvm/scripts/cd is called. When I remove this line from ~/.bash_profile:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
there is no error. But when I issue source $HOME/.rvm/scripts/rvm... still there is no error.
My system is Mac OS X 10.9.4
rvm --version:
rvm 1.25.29 (stable) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]
UPDATE
Other scripts in ~/.rvm/scripts:
alias
aliases
autolibs
base
cd
cleanup
cli
completion
cron
db
disk-usage
docs
env
extras
fetch
fix-permissions
functions
gemsets
group
hash
help
hook
info
initialize
install
irbrc
irbrc.rb
list
maglev
manage
migrate
monitor
mount
notes
osx-ssl-certs
override_gem
patches
pkg
prepare
repair
requirements
rtfm
rubygems
rvm
set
snapshot
tools
upgrade
version
wrapper
zsh
My ~/.bash_profile looks like this:
#...not important stuff
source ~/.bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
And in my ~/.bashrc I have this line (and few others):
[ -s "/Users/amorfis/.scm_breeze/scm_breeze.sh" ] && source "/Users/amorfis/.scm_breeze/scm_breeze.sh"
When I remove this line, the error is also gone. And again, it still doesn't show when I run source ~/.scm_breeze/scm_breeze.sh
Scm breeze is installed from here: https://github.com/ndbroadbent/scm_breeze
In source ~/.scm_breeze/scm_breeze.sh there is such piece of code:
if ! type ruby > /dev/null 2>&1; then
echo "Now in if"
# If Ruby is not installed, fall back to the
# slower bash/zsh implementation of 'git_status_shortcuts'
source "$scmbDir/lib/git/fallback/status_shortcuts_shell.sh"
fi
I expected the "if" statement is the problem. So I did this. Added such code before the if:
echo "Now lets try"
if ! type ruby > /dev/null 2>&1; then
echo "trying"
fi
echo "tried"
and inside if, as the first line in the block:
echo "Now in if"
This was the output:
Now lets try
tried
-bash: /Users/amorfis/.rvm/scripts/cd: line 14: syntax error near unexpected token `('
-bash: /Users/amorfis/.rvm/scripts/cd: line 14: ` cd() { __zsh_like_cd cd "$#" ; }'
So it looks like scm_breeze.sh is ok. The problem must be in .rvm, but only when scm_breeze.sh is run.
UPDATE 2:
The beginning of the .rvm/scripts/cd script looks like this:
#!/usr/bin/env bash
# Source a .rvmrc file in a directory after changing to it, if it exists. To
# disable this feature, set rvm_project_rvmrc=0 in /etc/rvmrc or $HOME/.rvmrc
case "${rvm_project_rvmrc:-1}" in
1|cd)
# clonned from git#github.com:mpapis/bash_zsh_support.git
source "$rvm_scripts_path/extras/bash_zsh_support/chpwd/function.sh"
# not using default loadign to support older Zsh
[[ -n "${ZSH_VERSION:-}" ]] &&
__rvm_version_compare "$ZSH_VERSION" -gt 4.3.4 ||
{
cd() { __zsh_like_cd cd "$#" ; }
popd() { __zsh_like_cd popd "$#" ; }
pushd() { __zsh_like_cd pushd "$#" ; }
}
I'd add this in as a comment, but I don't have the reputation to do so. I tried the answer from blob, but it didn't work.
I don't see the "scm_breeze-line", that Riaan Burger was talking about. Has anyone figured out an answer to this?
My error is pretty much the same:
/Users/myusername/.rvm/scripts/cd:14: defining function based on alias `cd' [ruby-2.3.3]
/Users/myusername/.rvm/scripts/cd:14: parse error near `()'
and line #14 says the same:
11 [[ -n "${ZSH_VERSION:-}" ]] &&
12 __rvm_version_compare "$ZSH_VERSION" -gt 4.3.4 ||
13 {
14 cd() { __zsh_like_cd cd "$#" ; }
15 popd() { __zsh_like_cd popd "$#" ; }
16 pushd() { __zsh_like_cd pushd "$#" ; }
17 }
I just ran into the same problem. The solution was to ensure the scm_breeze line executes after all the rvm ones.
Hit the same problem today, but the problem had nothing to do with scm_breeze in my case. If anyone stumbled onto this answer from google or some other place, maybe it'll help you.
Shortly after switching to OSX from Win7 I've been happily modifying anything and everything without necessarily understanding what I'm doing. Amongst other things, I've edited .bashrc as root (not the one from profile, rather the one located in /etc/.bashrc) and aliased cd like that:
alias cd='cd -P'
Never had problems with it before installing RVM, so if you were as root-happy as I once was, it might be worth checking whether you left yourself such a gift in the past.
I've moved said line into ~/.bash_profile and since then RVM happily runs without errors.
So basically what I did,
Step 1) Get a clone from SCM_BREEZE :-
git clone https://github.com/scmbreeze/scm_breeze.git
Step 2) Get a reference from Author's Doc (Link for Docs) and wrote few commands inside my local git repository's terminal,
. "$HOME/.scm_breeze/scm_breeze.sh"
update_scm_breeze
gs
It will update you scm breeze from github and patch your files if any
Your Git Status Command
N you are good to go...
Hope so it would help you now :)

Updating files after RVM install

I have installed RVM enroute to updating and running different ruby and rails. After install I received message to update shell's loading files.
1) Place the folowing line at the end of your shell's loading files
(.bashrc or .bash_profile for bash and .zshrc for zsh),
after all PATH/variable settings:
[[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm" # This loads RVM into a shell session.
You only need to add this line the first time you install rvm.
I typed [[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm"
and hit enter. Does this update my files? Or do I have to open some type of file and cut and paste code?
Since I did not see any notice as stated below from part 2 of the post install, I closed the shell and opened a new one. but the RVM command does not seem to work. Part 2 of the instructions post install was:
2) Ensure that there is no 'return' from inside the ~/.bashrc file,
otherwise rvm may be prevented from working properly.
This means that if you see something like:
'[ -z "$PS1" ] && return'
then you change this line to:
if [[ -n "$PS1" ]] ; then
# ... original content that was below the '&& return' line ...
fi # <= be sure to close the if at the end of the .bashrc.
# This is a good place to source rvm v v v
[[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm" # This loads RVM into a shell session.
EOF - This marks the end of the .bashrc file
Be absolutely *sure* to REMOVE the '&& return'.
If you wish to DRY up your config you can 'source ~/.bashrc' at the bottom of your .bash_profile.
Placing all non-interactive (non login) items in the .bashrc,
including the 'source' line above and any environment settings.
Thanks for the help as I am very new and trying to learn RoR but so far have not been able to get past the setup in many of the tutorials I've attempted. It seems many [
1 2 are out of date with new software or I get error messages before I can even attempt to learn the code. If someone knows of a good beginner tutorial that would be great. Thanks again!
The snippet that the installer gives you need to go in a file called the bashrc. The file lives in your home directory: /Users/eric/.bashrc
You need to edit this file and add the line from rvm and then you should be good to go.
As for getting rolling with rails I'd recommend The Pragmatic Programmers book on rails. You can find their books at pragprog.com
If you're on Ubuntu, my tutorial on setting rvm will get you roll all the way up to rails installation:
http://blog.dcxn.com/2011/06/20/setting-up-rvm-on-ubuntu-11-04/