131 lines
4.7 KiB
YAML
131 lines
4.7 KiB
YAML
# Triggered on v*.*.* tags or manual dispatch. Builds all projects then
|
||
# publishes each one to npm in a parallel matrix.
|
||
|
||
labels:
|
||
platform: linux/amd64
|
||
|
||
when:
|
||
- event: tag
|
||
ref: refs/tags/v*.*.*
|
||
|
||
variables:
|
||
- &default_projects "reviews-stars"
|
||
- &node_image "node:22"
|
||
|
||
# Perform a full clone with all tags so Nx affected and versioning work
|
||
# correctly.
|
||
clone:
|
||
git:
|
||
image: woodpeckerci/plugin-git
|
||
settings:
|
||
depth: 0
|
||
tags: true
|
||
|
||
steps:
|
||
# -------------------------------------------------------------------------
|
||
# 1. Install dependencies
|
||
# -------------------------------------------------------------------------
|
||
- name: install
|
||
image: *node_image
|
||
commands:
|
||
- npm ci --legacy-peer-deps
|
||
|
||
# -------------------------------------------------------------------------
|
||
# 2. Build all projects
|
||
# PUBLISH_PROJECTS can be overridden at dispatch time via the Woodpecker
|
||
# UI / API by setting the environment variable.
|
||
# -------------------------------------------------------------------------
|
||
- name: build
|
||
image: *node_image
|
||
environment:
|
||
PUBLISH_PROJECTS: *default_projects
|
||
commands:
|
||
- PROJECTS="${PUBLISH_PROJECTS:-reviews-stars}"
|
||
- echo "Projects to build $PROJECTS"
|
||
- npx nx run-many --target=build --projects="$PROJECTS"
|
||
|
||
# -------------------------------------------------------------------------
|
||
# 3. Run tests and collect coverage for SonarQube
|
||
# -------------------------------------------------------------------------
|
||
- name: test
|
||
image: *node_image
|
||
environment:
|
||
PUBLISH_PROJECTS: *default_projects
|
||
commands:
|
||
- PROJECTS="${PUBLISH_PROJECTS:-reviews-stars}"
|
||
- npx nx run-many -t test --code-coverage --passWithNoTests --projects="$PROJECTS"
|
||
|
||
# -------------------------------------------------------------------------
|
||
# 4. SonarQube analysis (runs against the tag/branch being released)
|
||
# -------------------------------------------------------------------------
|
||
- name: sonar
|
||
image: sonarsource/sonar-scanner-cli:latest
|
||
environment:
|
||
SONAR_HOST_URL:
|
||
from_secret: SONAR_HOST_URL
|
||
SONAR_TOKEN:
|
||
from_secret: SONAR_TOKEN
|
||
commands:
|
||
- sonar-scanner
|
||
-Dsonar.projectVersion=${CI_COMMIT_TAG#v}
|
||
|
||
# -------------------------------------------------------------------------
|
||
# 5. Determine the version and npm dist-tag, then publish every project.
|
||
#
|
||
# For tag events : version is derived from the tag (strips leading "v").
|
||
# For manual runs : VERSION env-var must be supplied via the Woodpecker
|
||
# UI / API (Settings → Secrets or the trigger form).
|
||
#
|
||
# NPM_TAG logic:
|
||
# - Explicit NPM_TAG env-var overrides everything.
|
||
# - A version containing "-" (pre-release) defaults to "next".
|
||
# - Otherwise defaults to "latest".
|
||
#
|
||
# Matrix: one step instance per project in PUBLISH_PROJECTS.
|
||
# Add more projects to the matrix list as the monorepo grows.
|
||
# -------------------------------------------------------------------------
|
||
- name: publish
|
||
image: *node_image
|
||
environment:
|
||
# Supplied as a Woodpecker secret – never hard-code the token.
|
||
NODE_AUTH_TOKEN:
|
||
from_secret: NPM_TOKEN
|
||
# Optional overrides settable at dispatch time.
|
||
PUBLISH_PROJECTS: *default_projects
|
||
# VERSION and NPM_TAG can be injected via the Woodpecker UI / API at
|
||
# manual-dispatch time.
|
||
VERSION: ""
|
||
NPM_TAG: ""
|
||
matrix:
|
||
PROJECT:
|
||
- reviews-stars
|
||
commands:
|
||
# --- Resolve version ---------------------------------------------------
|
||
- |
|
||
if [ -n "$VERSION" ]; then
|
||
RESOLVED_VERSION="$VERSION"
|
||
elif [ "$CI_PIPELINE_EVENT" = "tag" ]; then
|
||
# Strip the leading "v" from the tag name.
|
||
RESOLVED_VERSION="${CI_COMMIT_TAG#v}"
|
||
else
|
||
echo "No version provided for manual dispatch. Set the VERSION environment variable." >&2
|
||
exit 1
|
||
fi
|
||
|
||
# --- Resolve npm dist-tag ----------------------------------------------
|
||
- |
|
||
if [ -n "$NPM_TAG" ]; then
|
||
RESOLVED_NPM_TAG="$NPM_TAG"
|
||
elif echo "$RESOLVED_VERSION" | grep -q "-"; then
|
||
RESOLVED_NPM_TAG="next"
|
||
else
|
||
RESOLVED_NPM_TAG="latest"
|
||
fi
|
||
|
||
# --- Configure npm authentication -------------------------------------
|
||
- echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc
|
||
|
||
# --- Publish ----------------------------------------------------------
|
||
- echo "Publishing ${PROJECT} @ ${RESOLVED_VERSION} with tag ${RESOLVED_NPM_TAG}"
|
||
- node tools/scripts/publish.mjs "$PROJECT" "$RESOLVED_VERSION" "$RESOLVED_NPM_TAG"
|