mirror of
https://github.com/robertstettner/drone-npm-auth.git
synced 2026-06-04 18:23:58 +08:00
ab05668267
The fix is to append the contents of ~/.npmrc to the local /npmrc rather than overwrite it. Also, this fixes an issue where only the first line would be appended (`always-auth` etc was getting lost). This was caused by echo only printing to the first carriage return. I've also stopped replacing whitespace with newlines as it seems error prone.
52 lines
1.2 KiB
Bash
Executable File
52 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
starttime=$(date +%s.%N)
|
|
username="${NPM_USERNAME:-$PLUGIN_USERNAME}"
|
|
password="${NPM_PASSWORD:-$PLUGIN_PASSWORD}"
|
|
email="${NPM_EMAIL:-$PLUGIN_EMAIL}"
|
|
registry="${NPM_REGISTRY:-$PLUGIN_REGISTRY}"
|
|
scope="${NPM_SCOPE:-$PLUGIN_SCOPE}"
|
|
path="${PLUGIN_PATH:-./}"
|
|
token="${NPM_TOKEN:-$PLUGIN_TOKEN}"
|
|
|
|
set -e
|
|
|
|
echo "-- Setting up authentication from NPM..."
|
|
|
|
if [ -z "$registry" ]; then
|
|
registry="registry.npmjs.org"
|
|
fi
|
|
if [ -z "$token" ]; then
|
|
if [ -z "$username" ]; then
|
|
echo "-- Username is not set!"
|
|
exit 1
|
|
fi
|
|
if [ -z "$password" ]; then
|
|
echo "-- Password is not set!"
|
|
exit 1
|
|
fi
|
|
if [ -z "$email" ]; then
|
|
echo "-- Email is not set!"
|
|
exit 1
|
|
fi
|
|
if [ -z "$scope" ]; then
|
|
scope_option=""
|
|
else
|
|
scope_option="--scope=$scope"
|
|
fi
|
|
|
|
expect-npm-auth "npm login --registry $registry $scope_option" $username $password $email >/dev/null 2>&1
|
|
else
|
|
echo "//$registry/:_authToken=$token" > ~/.npmrc
|
|
fi
|
|
|
|
endtime=$(date +%s.%N)
|
|
echo "duration: $(echo "$endtime $starttime" | awk '{printf "%f", $1 - $2}')s"
|
|
|
|
if [ ! -e ~/.npmrc ]; then
|
|
echo "-- Error logging into NPM"
|
|
exit 1
|
|
else
|
|
cat ~/.npmrc >> $path.npmrc
|
|
echo "-- NPM authentication done!"
|
|
fi |