@sudosf/npm-publish-sandbox 3.10.8 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/.gitlab-ci.yml +59 -36
  2. package/package.json +1 -1
package/.gitlab-ci.yml CHANGED
@@ -1,20 +1,9 @@
1
- include:
2
- - template: Jobs/SAST.gitlab-ci.yml
3
- - template: Jobs/Dependency-Scanning.v2.gitlab-ci.yml
4
- - template: Jobs/Code-Quality.gitlab-ci.yml
5
- - template: Jobs/Secret-Detection.gitlab-ci.yml
6
-
7
- variables:
8
- KIBANA_VERSION: 9.1.7
9
- KIBANA_IMAGE_TAG: "9.1.9"
10
-
11
1
  stages:
12
- - test
13
- - yarn_steps
14
2
  - deploy
15
3
 
16
- artifactory-push:
4
+ npm-publish:
17
5
  stage: deploy
6
+ image: node:22.17.1
18
7
  rules:
19
8
  - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
20
9
  when: never
@@ -24,15 +13,17 @@ artifactory-push:
24
13
  when: always
25
14
  - when: never
26
15
  script:
27
- - npm config set registry https://artifactory.orbit.prod.vodacom.co.za/artifactory/api/npm/vod-npm/
28
- - npm config set //artifactory.orbit.prod.vodacom.co.za/artifactory/api/npm/vod-npm/:_auth $(echo -n $ARTIFACTORY_USERNAME:$ARTIFACTORY_PASSWORD | base64)
16
+ - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
29
17
  - |
30
18
  BASE_NAME=$(node -p "require('./package.json').name")
31
19
  VERSION=$(node -p "require('./package.json').version")
32
- TAG="v$VERSION"
20
+ MAJOR_VERSION=$(echo "$VERSION" | grep -o '^[0-9]*')
33
21
 
34
- echo "Base package name: $BASE_NAME"
35
- echo "Version: $VERSION"
22
+ echo "========================================"
23
+ echo "Package : $BASE_NAME"
24
+ echo "Version : $VERSION"
25
+ echo "Branch : $CI_COMMIT_BRANCH"
26
+ echo "========================================"
36
27
 
37
28
  # Determine environment from branch
38
29
  if [[ $CI_COMMIT_BRANCH == "stable" || $CI_COMMIT_BRANCH =~ ^hotfix/stable- ]]; then
@@ -45,35 +36,67 @@ artifactory-push:
45
36
  ENV="staging"
46
37
  fi
47
38
 
48
- echo "Publishing to $ENV environment"
39
+ echo "Target environment: $ENV"
49
40
 
50
- # Configure git for tagging
41
+ # ----------------------------------------
42
+ # Git tagging
43
+ # ----------------------------------------
44
+ echo "[git] Configuring remote..."
51
45
  git config --global --add safe.directory $CI_PROJECT_DIR
52
46
  git remote set-url origin "https://oauth2:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
53
47
 
54
- # Create generic version tag only for stable releases
48
+ # Only create a clean vX.Y.Z git tag on stable
55
49
  if [[ "$ENV" == "stable" ]]; then
56
- if ! git rev-parse "$TAG" >/dev/null 2>&1; then
57
- git tag "$TAG"
58
- git push origin "$TAG"
50
+ if ! git rev-parse "v$VERSION" >/dev/null 2>&1; then
51
+ echo "[git] Creating stable release tag: v$VERSION"
52
+ git tag "v$VERSION"
53
+ git push origin "v$VERSION"
54
+ else
55
+ echo "[git] Tag v$VERSION already exists, skipping"
59
56
  fi
60
57
  fi
61
58
 
62
- # Create/update environment-specific tag
63
- git tag -f "$TAG-$ENV"
64
- git push origin "$TAG-$ENV" --force
59
+ # Create/update environment-version git tag e.g. dev-3.10.8, qa-3.10.8
60
+ echo "[git] Creating/updating environment git tag: $ENV-$VERSION"
61
+ git tag -f "$ENV-$VERSION"
62
+ git push origin "$ENV-$VERSION" --force
65
63
 
66
- # Publish to npm with mutable environment dist-tag
67
- npm publish --tag "$ENV"
64
+ # ----------------------------------------
65
+ # npm publish (ONLY on master/dev — first publish)
66
+ # All other environments just add dist-tags
67
+ # ----------------------------------------
68
+ if [[ "$ENV" == "dev" ]]; then
69
+ echo "[npm] Publishing $BASE_NAME@$VERSION with tag: dev-$VERSION"
70
+ npm publish --tag "dev-$VERSION" --access public
71
+ echo "[npm] Publish complete"
72
+ else
73
+ echo "[npm] Skipping publish — version $VERSION already published from master"
74
+ echo "[npm] Adding dist-tag '$ENV-$VERSION' to $BASE_NAME@$VERSION"
75
+ npm dist-tag add "$BASE_NAME@$VERSION" "$ENV-$VERSION"
76
+ fi
68
77
 
69
- # Extract major version for major-version-specific dist-tags
70
- MAJOR_VERSION=$(echo "$VERSION" | grep -o '^[0-9]*')
78
+ # ----------------------------------------
79
+ # Additional dist-tags
80
+ # ----------------------------------------
71
81
 
72
- # Add immutable version-specific dist-tag
73
- npm dist-tag add "$BASE_NAME@$VERSION" "$VERSION-$ENV"
82
+ # Mutable env tag e.g. dev, qa (always points to latest of that env)
83
+ echo "[npm] Adding mutable env dist-tag: $ENV"
84
+ npm dist-tag add "$BASE_NAME@$VERSION" "$ENV"
74
85
 
75
- # Add major-version-specific dist-tags
86
+ # Major version env tag e.g. dev-3, qa-3
87
+ echo "[npm] Adding major-version dist-tag: $ENV-$MAJOR_VERSION"
76
88
  npm dist-tag add "$BASE_NAME@$VERSION" "$ENV-$MAJOR_VERSION"
77
- npm dist-tag add "$BASE_NAME@$VERSION" "$VERSION-$ENV-$MAJOR_VERSION"
78
89
 
79
- echo "Published $BASE_NAME@$VERSION with tags @$ENV, @$VERSION-$ENV, @$ENV-$MAJOR_VERSION, @$VERSION-$ENV-$MAJOR_VERSION"
90
+ # On stable, also point 'latest' to this version
91
+ if [[ "$ENV" == "stable" ]]; then
92
+ echo "[npm] Stable release — updating 'latest' tag to $VERSION"
93
+ npm dist-tag add "$BASE_NAME@$VERSION" latest
94
+ fi
95
+
96
+ echo "========================================"
97
+ echo "Done! $BASE_NAME@$VERSION tagged as:"
98
+ echo " - $ENV-$VERSION (immutable, version-specific)"
99
+ echo " - $ENV (mutable, always latest of this env)"
100
+ echo " - $ENV-$MAJOR_VERSION (mutable, latest of this env in major v$MAJOR_VERSION)"
101
+ [[ "$ENV" == "stable" ]] && echo " - latest"
102
+ echo "========================================"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudosf/npm-publish-sandbox",
3
- "version": "3.10.8",
3
+ "version": "4.0.0",
4
4
  "description": "Sandbox package for testing npm publish to Artifactory",
5
5
  "main": "index.js",
6
6
  "license": "MIT",