feat: add npm-lib Drone template for private npm publishing
This commit is contained in:
89
standards/src/templates/drone/npm-lib.yaml
Normal file
89
standards/src/templates/drone/npm-lib.yaml
Normal file
@@ -0,0 +1,89 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: build-and-publish-npm
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: arm64
|
||||
|
||||
workspace:
|
||||
path: /drone/src
|
||||
|
||||
steps:
|
||||
- name: check-version
|
||||
image: node:22-alpine
|
||||
environment:
|
||||
NPM_REPO_URL:
|
||||
from_secret: NPM_REPO_URL
|
||||
NPM_USERNAME:
|
||||
from_secret: NPM_USERNAME
|
||||
NPM_PASSWORD:
|
||||
from_secret: NPM_PASSWORD
|
||||
commands:
|
||||
- apk add --no-cache curl
|
||||
- PACKAGE_NAME=$(node -p "require('./package.json').name")
|
||||
- VERSION=$(node -p "require('./package.json').version")
|
||||
- |
|
||||
if [ "$DRONE_TAG" != "$VERSION" ]; then
|
||||
echo "Tag '$DRONE_TAG' does not match package.json version '$VERSION'; refusing to publish."
|
||||
exit 1
|
||||
fi
|
||||
- echo "registry=$NPM_REPO_URL" > /tmp/.npmrc
|
||||
- echo "_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
|
||||
echo "$PACKAGE_NAME@$VERSION already exists; skipping build."
|
||||
exit 78
|
||||
else
|
||||
echo "New version detected: $PACKAGE_NAME@$VERSION"
|
||||
fi
|
||||
|
||||
- name: quality-gate
|
||||
image: node:22-alpine
|
||||
environment:
|
||||
NPM_REPO_URL:
|
||||
from_secret: NPM_REPO_URL
|
||||
NPM_USERNAME:
|
||||
from_secret: NPM_USERNAME
|
||||
NPM_PASSWORD:
|
||||
from_secret: NPM_PASSWORD
|
||||
commands:
|
||||
- |
|
||||
if [ -z "$NPM_REPO_URL" ] || [ -z "$NPM_USERNAME" ] || [ -z "$NPM_PASSWORD" ]; then
|
||||
echo "NPM_REPO_URL / NPM_USERNAME / NPM_PASSWORD are not set" >&2
|
||||
exit 1
|
||||
fi
|
||||
- echo "registry=$NPM_REPO_URL" > .npmrc
|
||||
- echo "_auth=$(echo -n "$NPM_USERNAME:$NPM_PASSWORD" | base64 | tr -d '\n')" >> .npmrc
|
||||
- npm install
|
||||
- echo "Running quality gate..."
|
||||
- npm run quality-gate
|
||||
|
||||
- name: build-package
|
||||
image: node:22-alpine
|
||||
commands:
|
||||
- npm install
|
||||
- echo "Building npm package..."
|
||||
- npm run build
|
||||
- ls -l dist
|
||||
|
||||
- name: publish-to-private-npm
|
||||
image: node:22-alpine
|
||||
environment:
|
||||
NPM_REPO_URL:
|
||||
from_secret: NPM_REPO_URL
|
||||
NPM_USERNAME:
|
||||
from_secret: NPM_USERNAME
|
||||
NPM_PASSWORD:
|
||||
from_secret: NPM_PASSWORD
|
||||
commands:
|
||||
- echo "registry=$NPM_REPO_URL" > .npmrc
|
||||
- echo "_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
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- tag
|
||||
Reference in New Issue
Block a user