Fix npm registry auth: use scoped //host/:_auth in .npmrc
npm rejects a bare _auth key (ERR_INVALID_AUTH) against a private registry; derive the host from NPM_REPO_URL and write //<host>/:_auth=<base64> instead.
This commit is contained in:
@@ -29,8 +29,9 @@ steps:
|
||||
echo "Tag '$DRONE_TAG' does not match package.json version '$VERSION'; refusing to publish."
|
||||
exit 1
|
||||
fi
|
||||
- NPM_HOST=$(echo "$NPM_REPO_URL" | sed -E 's|^[a-z]+://||; s|/*$||')
|
||||
- echo "registry=$NPM_REPO_URL" > /tmp/.npmrc
|
||||
- echo "_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> /tmp/.npmrc
|
||||
- echo "//$NPM_HOST/:_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> /tmp/.npmrc
|
||||
- echo "Checking if $PACKAGE_NAME@$VERSION exists on $NPM_REPO_URL ..."
|
||||
- |
|
||||
if npm view "$PACKAGE_NAME@$VERSION" version --userconfig /tmp/.npmrc >/dev/null 2>&1; then
|
||||
@@ -55,8 +56,9 @@ steps:
|
||||
echo "NPM_REPO_URL / NPM_USERNAME / NPM_PASSWORD are not set" >&2
|
||||
exit 1
|
||||
fi
|
||||
- NPM_HOST=$(echo "$NPM_REPO_URL" | sed -E 's|^[a-z]+://||; s|/*$||')
|
||||
- echo "registry=$NPM_REPO_URL" > .npmrc
|
||||
- echo "_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> .npmrc
|
||||
- echo "//$NPM_HOST/:_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> .npmrc
|
||||
- npm install
|
||||
- echo "Running quality gate..."
|
||||
- npm run quality-gate
|
||||
@@ -79,8 +81,9 @@ steps:
|
||||
NPM_PASSWORD:
|
||||
from_secret: NPM_PASSWORD
|
||||
commands:
|
||||
- NPM_HOST=$(echo "$NPM_REPO_URL" | sed -E 's|^[a-z]+://||; s|/*$||')
|
||||
- echo "registry=$NPM_REPO_URL" > .npmrc
|
||||
- echo "_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> .npmrc
|
||||
- echo "//$NPM_HOST/:_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> .npmrc
|
||||
- echo "Publishing to private npm at $NPM_REPO_URL ..."
|
||||
- npm publish --access restricted
|
||||
|
||||
@@ -117,8 +120,9 @@ steps:
|
||||
from_secret: NPM_PASSWORD
|
||||
commands:
|
||||
- apk add --no-cache git
|
||||
- NPM_HOST=$(echo "$NPM_REPO_URL" | sed -E 's|^[a-z]+://||; s|/*$||')
|
||||
- echo "registry=$NPM_REPO_URL" > /tmp/.npmrc
|
||||
- echo "_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> /tmp/.npmrc
|
||||
- echo "//$NPM_HOST/:_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> /tmp/.npmrc
|
||||
- |
|
||||
set -e
|
||||
|
||||
|
||||
@@ -29,8 +29,9 @@ steps:
|
||||
echo "Tag '$DRONE_TAG' does not match package.json version '$VERSION'; refusing to publish."
|
||||
exit 1
|
||||
fi
|
||||
- NPM_HOST=$(echo "$NPM_REPO_URL" | sed -E 's|^[a-z]+://||; s|/*$||')
|
||||
- echo "registry=$NPM_REPO_URL" > /tmp/.npmrc
|
||||
- echo "_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> /tmp/.npmrc
|
||||
- echo "//$NPM_HOST/:_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> /tmp/.npmrc
|
||||
- echo "Checking if $PACKAGE_NAME@$VERSION exists on $NPM_REPO_URL ..."
|
||||
- |
|
||||
if npm view "$PACKAGE_NAME@$VERSION" version --userconfig /tmp/.npmrc >/dev/null 2>&1; then
|
||||
@@ -55,8 +56,9 @@ steps:
|
||||
echo "NPM_REPO_URL / NPM_USERNAME / NPM_PASSWORD are not set" >&2
|
||||
exit 1
|
||||
fi
|
||||
- NPM_HOST=$(echo "$NPM_REPO_URL" | sed -E 's|^[a-z]+://||; s|/*$||')
|
||||
- echo "registry=$NPM_REPO_URL" > .npmrc
|
||||
- echo "_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> .npmrc
|
||||
- echo "//$NPM_HOST/:_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> .npmrc
|
||||
- npm install
|
||||
- echo "Running quality gate..."
|
||||
- npm run quality-gate
|
||||
@@ -79,8 +81,9 @@ steps:
|
||||
NPM_PASSWORD:
|
||||
from_secret: NPM_PASSWORD
|
||||
commands:
|
||||
- NPM_HOST=$(echo "$NPM_REPO_URL" | sed -E 's|^[a-z]+://||; s|/*$||')
|
||||
- echo "registry=$NPM_REPO_URL" > .npmrc
|
||||
- echo "_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> .npmrc
|
||||
- echo "//$NPM_HOST/:_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> .npmrc
|
||||
- echo "Publishing to private npm at $NPM_REPO_URL ..."
|
||||
- npm publish --access restricted
|
||||
|
||||
@@ -117,8 +120,9 @@ steps:
|
||||
from_secret: NPM_PASSWORD
|
||||
commands:
|
||||
- apk add --no-cache git
|
||||
- NPM_HOST=$(echo "$NPM_REPO_URL" | sed -E 's|^[a-z]+://||; s|/*$||')
|
||||
- echo "registry=$NPM_REPO_URL" > /tmp/.npmrc
|
||||
- echo "_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> /tmp/.npmrc
|
||||
- echo "//$NPM_HOST/:_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> /tmp/.npmrc
|
||||
- |
|
||||
set -e
|
||||
|
||||
|
||||
Reference in New Issue
Block a user