Skip to content

Commit e101143

Browse files
Add npm publish flow with DK CI
1 parent 8b54a67 commit e101143

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

.github/workflows/publish-npm.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
11+
permissions:
12+
contents: read
13+
id-token: write # required for Trusted Publishing
14+
15+
env:
16+
CODEARTIFACT_DOMAIN: main
17+
CODEARTIFACT_REPOSITORY: vtex-npm
18+
NPM_PACKAGE_NAME: "vtex"
19+
AWS_REGION: us-east-1
20+
21+
jobs:
22+
publish:
23+
runs-on: ubuntu-latest
24+
25+
env:
26+
CODEARTIFACT_TOKEN: ${{ secrets.CODEARTIFACT_TOKEN }}
27+
CODEARTIFACT_DOMAIN_OWNER: ${{ secrets.CODEARTIFACT_DOMAIN_OWNER_MAIN }}
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Setup Node
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: '22'
37+
38+
- name: Configure npm for CodeArtifact
39+
run: |
40+
set -euo pipefail
41+
42+
if [ -z "${CODEARTIFACT_TOKEN:-}" ]; then
43+
echo "CODEARTIFACT_TOKEN not set"; exit 1
44+
fi
45+
46+
CODEARTIFACT_URL="https://${CODEARTIFACT_DOMAIN}-${CODEARTIFACT_DOMAIN_OWNER}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/"
47+
48+
echo "Configuring npm to use ${CODEARTIFACT_URL}"
49+
50+
npm config set registry "${CODEARTIFACT_URL}"
51+
npm config set "//${CODEARTIFACT_DOMAIN}-${CODEARTIFACT_DOMAIN_OWNER}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/:_authToken" "${CODEARTIFACT_TOKEN}"
52+
npm config set "//${CODEARTIFACT_DOMAIN}-${CODEARTIFACT_DOMAIN_OWNER}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/:always-auth" true
53+
54+
- name: Download package from CodeArtifact
55+
run: |
56+
set -euo pipefail
57+
VERSION="${{ inputs.version }}"
58+
59+
echo "Downloading ${NPM_PACKAGE_NAME}@${VERSION} from CodeArtifact..."
60+
npm pack "${NPM_PACKAGE_NAME}@${VERSION}"
61+
62+
echo "Generated files:"
63+
ls -1 *.tgz
64+
65+
- name: Set npm registry to npmjs
66+
run: |
67+
set -euo pipefail
68+
npm config set registry https://registry.npmjs.org
69+
70+
- name: Publish tarball to npmjs
71+
run: |
72+
set -euo pipefail
73+
TARBALL=$(ls -1 *.tgz | head -n 1)
74+
echo "Publishing ${TARBALL} to npmjs..."
75+
npm publish "${TARBALL}" --provenance --access public

.vtex/deployment.yaml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@
33
build:
44
provider: dkcicd
55
pipelines:
6+
- name: node-ci-v2
7+
parameters:
8+
nodeVersion: "22-bookworm"
9+
packageManager: yarn
10+
skipInstall: true
11+
nodeCommands:
12+
- yarn install --ignore-scripts
13+
- yarn run lint
14+
- yarn run ci:test
15+
when:
16+
- event: push
17+
source: branch
18+
19+
- name: npm-publish-v1
20+
parameters:
21+
nodeVersion: "22-bookworm"
22+
packageManager: yarn
23+
skipInstall: true
24+
nodeCommands:
25+
- yarn install --ignore-scripts
26+
- yarn ci:build
27+
publishViaGithubWorkflow: true
28+
workflowFile: publish-npm.yml
29+
workflowVersion: '{{ ref_name }}'
30+
when:
31+
- event: push
32+
source: tag
33+
634
- name: techdocs-v1
735
parameters:
836
entityReference: default/component/node-vtex-api
@@ -14,4 +42,4 @@
1442
path:
1543
- "docs/**"
1644
- README.md
17-
- .vtex/deployment.yaml
45+
- .vtex/deployment.yaml

0 commit comments

Comments
 (0)