-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
65 lines (60 loc) · 1.74 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
variables:
NODE_IMAGE: "node:18" # Node.js version, adjust as needed
PACKAGE_NAME: "s4-shell-tools" # Replace with your tool's name
VERSION: 1.0.7
stages:
- build
- dockerize
- publish_module
# Build the Node.js project
build:
stage: build
image: node:18
script:
- npm install
- npm run build
artifacts:
paths:
- node_modules
- dist
# Build Docker image
build_docker_image:
stage: dockerize
image: docker:24 # Use a Docker-in-Docker image
dependencies:
- build
services:
- docker:24-dind
before_script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
script:
- docker build -t "$CI_REGISTRY_IMAGE:latest" -t "$CI_REGISTRY_IMAGE:$VERSION" .
- docker push "$CI_REGISTRY_IMAGE:$VERSION"
- docker push "$CI_REGISTRY_IMAGE:latest"
only:
- main # Only run this stage for the main branch
publish_module:
stage: publish_module
image: $NODE_IMAGE
script:
# Configure GitLab registry authentication
- echo "@simsonianlibrary:registry=https://${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/" > .npmrc
- echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}" >> .npmrc
- npm run build
- npm publish
dependencies:
- build # Ensure it uses the built files
rules:
- if: '$CI_COMMIT_BRANCH == "main"' # Only publish from the main branch
when: manual
publish_npm:
stage: publish_module
image: $NODE_IMAGE
script:
# Configure GitLab registry authentication
- npm publish --access public
dependencies:
- build # Ensure it uses the built files
rules:
- if: '$CI_COMMIT_BRANCH == "main"' # Only publish from the main branch
when: manual