Skip to content

Commit fcd9ba6

Browse files
committed
Add dk-cicd pipeline to publish on npm
1 parent 1bd2895 commit fcd9ba6

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

.github/workflows/publish-npm.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Publish from CodeArtifact to npm
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Package Version (ex: 1.2.3)'
8+
required: true
9+
type: string
10+
environment:
11+
description: 'Environment (production or beta)'
12+
required: true
13+
type: choice
14+
options:
15+
- production
16+
- beta
17+
CA_TOKEN:
18+
description: 'CodeArtifact Token'
19+
required: true
20+
type: string
21+
CA_OWNER:
22+
description: 'CodeArtifact Domain Owner'
23+
required: true
24+
type: string
25+
26+
permissions:
27+
contents: read
28+
id-token: write # required for Trusted Publishing
29+
30+
env:
31+
CODEARTIFACT_DOMAIN: main
32+
CODEARTIFACT_REPOSITORY: internal-npm
33+
NPM_PACKAGE_NAME: "@vtex/api"
34+
AWS_REGION: us-east-1
35+
36+
jobs:
37+
publish:
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
43+
- name: Setup Node
44+
uses: actions/setup-node@v4
45+
with:
46+
node-version: '22'
47+
48+
- name: Configure npm for CodeArtifact
49+
run: |
50+
set -euo pipefail
51+
52+
export CODEARTIFACT_TOKEN="${{ github.event.inputs.CA_TOKEN}}"
53+
echo "::add-mask::${{ github.event.inputs.CA_TOKEN}}"
54+
export CODEARTIFACT_DOMAIN_OWNER="${{ github.event.inputs.CA_OWNER}}"
55+
echo "::add-mask::${{ github.event.inputs.CA_OWNER}}"
56+
57+
if [ -z "${CODEARTIFACT_TOKEN:-}" ]; then
58+
echo "CODEARTIFACT_TOKEN not set"; exit 1
59+
fi
60+
61+
CODEARTIFACT_URL="https://${CODEARTIFACT_DOMAIN}-${CODEARTIFACT_DOMAIN_OWNER}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/"
62+
63+
echo "Configuring npm to use ${CODEARTIFACT_URL}"
64+
65+
npm config set registry "${CODEARTIFACT_URL}"
66+
npm config set "//${CODEARTIFACT_DOMAIN}-${CODEARTIFACT_DOMAIN_OWNER}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/:_authToken" "${CODEARTIFACT_TOKEN}"
67+
68+
- name: Download package from CodeArtifact
69+
run: |
70+
set -euo pipefail
71+
VERSION="${{ github.event.inputs.version }}"
72+
73+
echo "Downloading ${NPM_PACKAGE_NAME}@${VERSION} from CodeArtifact..."
74+
npm pack "${NPM_PACKAGE_NAME}@${VERSION}"
75+
76+
echo "Generated files:"
77+
ls -1 *.tgz
78+
79+
- name: Set npm registry to npmjs
80+
run: |
81+
set -euo pipefail
82+
npm config set registry https://registry.npmjs.org
83+
npm install -g npm@latest
84+
85+
- name: Publish tarball to npmjs
86+
run: |
87+
set -euo pipefail
88+
89+
TARBALL=$(ls -1 *.tgz | head -n 1)
90+
TAG_FLAG=""
91+
if [ "${{ github.event.inputs.environment }}" = "beta" ]; then
92+
TAG_FLAG="--tag beta"
93+
fi
94+
echo "Publishing ${TARBALL} to npmjs..."
95+
npm publish "${TARBALL}" --provenance --access public ${TAG_FLAG}

.vtex/deployment.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
- name: node-vtex-api
2+
referenceId: SHSTJA2W
3+
build:
4+
provider: dkcicd
5+
pipelines:
6+
- name: node-ci-v2
7+
parameters:
8+
nodeVersion: "22-bookworm"
9+
packageManager: yarn
10+
skipInstall: false
11+
nodeCommands:
12+
- lint
13+
- ci:test
14+
when:
15+
- event: push
16+
source: branch
17+
18+
- name: npm-publish-v1
19+
parameters:
20+
nodeVersion: "22-bookworm"
21+
packageManager: yarn
22+
skipInstall: false
23+
nodeCommands:
24+
- ci:build
25+
publishViaGithubWorkflow: true
26+
workflowFile: publish-npm.yml
27+
workflowVersion: '{{ ref_name }}'
28+
when:
29+
- event: push
30+
source: tag

0 commit comments

Comments
 (0)