Skip to content

Commit 3d96b48

Browse files
[LG-5520] chore: Add AWS CodeArtifact publishing (#3125)
* feat(scripts): add login script for AWS CodeArtifact authentication * feat(release): update AWS CodeArtifact publishing workflow and npm configuration * fix(settings): add CODEARTIFACT to cSpell words for spell checking * add todo * Update .github/workflows/release.yml Co-authored-by: Copilot <[email protected]> * Update .gitignore --------- Co-authored-by: Copilot <[email protected]>
1 parent 579e8c7 commit 3d96b48

File tree

4 files changed

+134
-9
lines changed

4 files changed

+134
-9
lines changed

.github/workflows/release.yml

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,6 @@ jobs:
160160
- name: Install Dependencies
161161
run: pnpm install --frozen-lockfile --prefer-offline
162162

163-
- name: Updating .npmrc
164-
run: |
165-
cat << EOF > "$HOME/.npmrc"
166-
//registry.npmjs.org/:_authToken=$NPM_TOKEN
167-
EOF
168-
env:
169-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
170-
171163
- uses: actions/cache/restore@v4
172164
name: Restore build cache
173165
id: build-cache
@@ -187,6 +179,14 @@ jobs:
187179
tools/*/stories.js
188180
key: ${{needs.build.outputs.cache-primary-key}}
189181

182+
- name: Updating .npmrc
183+
run: |
184+
cat << EOF > "$HOME/.npmrc"
185+
//registry.npmjs.org/:_authToken=$NPM_TOKEN
186+
EOF
187+
env:
188+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
189+
190190
- name: Version packages
191191
id: changesets
192192
uses: changesets/action@v1
@@ -198,6 +198,61 @@ jobs:
198198
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
199199
NPM_TOKEN: '${{ secrets.NPM_TOKEN }}'
200200

201+
release-aws:
202+
name: Publish to AWS CodeArtifact
203+
runs-on: ubuntu-latest
204+
needs: [build, release]
205+
if: ${{ needs.release.outputs.published == 'true' }}
206+
steps:
207+
- uses: actions/checkout@v4
208+
209+
- name: pnpm
210+
uses: pnpm/action-setup@v4
211+
with:
212+
version: 9.15.0
213+
214+
- name: Use Node 18
215+
uses: actions/setup-node@v4
216+
with:
217+
node-version: 18
218+
cache: 'pnpm'
219+
cache-dependency-path: 'pnpm-lock.yaml'
220+
221+
- name: Install Dependencies
222+
run: pnpm install --frozen-lockfile --prefer-offline
223+
224+
- uses: actions/cache/restore@v4
225+
name: Restore build cache
226+
id: build-cache
227+
with:
228+
path: |
229+
charts/*/dist/*
230+
charts/*/tsdoc.json
231+
charts/*/stories.js
232+
chat/*/dist/*
233+
chat/*/tsdoc.json
234+
chat/*/stories.js
235+
packages/*/dist/*
236+
packages/*/tsdoc.json
237+
packages/*/stories.js
238+
tools/*/dist/*
239+
tools/*/tsdoc.json
240+
tools/*/stories.js
241+
key: ${{needs.build.outputs.cache-primary-key}}
242+
243+
- name: Configure AWS credentials
244+
uses: aws-actions/configure-aws-credentials@v4
245+
with:
246+
aws-access-key-id: ${{ secrets.AWS_CODEARTIFACT_ACCESS_KEY_ID }}
247+
aws-secret-access-key: ${{ secrets.AWS_CODEARTIFACT_SECRET_ACCESS_KEY }}
248+
aws-region: us-east-1
249+
250+
- name: Login to CodeArtifact
251+
run: scripts/login-codeartifact.sh
252+
253+
- name: Publish to CodeArtifact
254+
run: pnpm publish -r --no-git-checks
255+
201256
notify:
202257
name: Notify Slack & Website
203258
runs-on: ubuntu-latest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ts-trace/
2929

3030
# Environment variables
3131
.env
32+
.secrets
3233

3334
# test coverage
3435
coverage/
@@ -55,3 +56,4 @@ TODO.md
5556
# PR train config (https://github.com/realyze/pr-train)
5657
.pr-train.yml
5758
migration-storybook.log
59+

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
"eslint.runtime": "node",
1515
"eslint.workingDirectories": ["./"],
1616
"typescript.preferences.importModuleSpecifier": "project-relative",
17-
"cSpell.words": ["leafygreen", "svgrrc"],
17+
"cSpell.words": [
18+
"CODEARTIFACT",
19+
"leafygreen",
20+
"svgrrc"
21+
],
1822
"workbench.editorAssociations": {
1923
"*.svg": "default"
2024
},

scripts/login-codeartifact.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# Based on https://docs.aws.amazon.com/codeartifact/latest/ug/npm-auth.html#configuring-npm-without-using-the-login-command
3+
4+
# TODO: Create a shared script for lg-private
5+
6+
# Declare our scope, domain, and repository
7+
DOMAIN="mongodb"
8+
REPOSITORY="leafygreen-ui"
9+
# Define our scopes
10+
SCOPES=(
11+
"@leafygreen-ui"
12+
"@lg-charts"
13+
"@lg-chat"
14+
"@lg-tools"
15+
)
16+
17+
# Check if aws command is available
18+
if ! command -v aws &> /dev/null; then
19+
echo "Error: aws CLI is not installed or not in PATH"
20+
exit 1
21+
fi
22+
23+
echo "Logging into CodeArtifact repository $REPOSITORY..."
24+
25+
CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain $DOMAIN --query authorizationToken --output text`
26+
27+
# Check if the token retrieval was successful
28+
if [ -z "$CODEARTIFACT_AUTH_TOKEN" ] || [ "$CODEARTIFACT_AUTH_TOKEN" == "None" ]; then
29+
echo "\nFailed to retrieve authorization token from AWS"
30+
echo "Ensure that your AWS profile is configured correctly in ~/.aws/config (and has access to CodeArtifact)"
31+
echo "Login to AWS in OKTA to get your current credentials: https://corp.mongodb.com/"
32+
exit 1
33+
fi
34+
35+
# Get the endpoint data, and extract the repository URL from the JSON output
36+
CODEARTIFACT_ENDPOINT_JSON=`aws codeartifact get-repository-endpoint --domain $DOMAIN --repository $REPOSITORY --format npm`
37+
CODEARTIFACT_REGISTRY=$(echo $CODEARTIFACT_ENDPOINT_JSON | jq -r '.repositoryEndpoint')
38+
39+
# Check if jq extraction was successful
40+
if [ -z "$CODEARTIFACT_REGISTRY" ] || [ "$CODEARTIFACT_REGISTRY" == "null" ]; then
41+
echo "Error: Failed to extract repository endpoint from AWS response"
42+
exit 1
43+
fi
44+
45+
# Remove the https:// prefix from the endpoint URL for npm config
46+
CODEARTIFACT_REGISTRY_URI=$(echo $CODEARTIFACT_REGISTRY | sed 's|^https:||')
47+
48+
echo "CodeArtifact Endpoint: $CODEARTIFACT_REGISTRY"
49+
50+
# Update the user's global npm config (~/.npmrc) with the new registry and auth token
51+
52+
# Configure each scope to use our CodeArtifact registry
53+
for SCOPE in "${SCOPES[@]}"; do
54+
echo "Configuring $SCOPE to use CodeArtifact registry..."
55+
npm config set "${SCOPE}:registry" $CODEARTIFACT_REGISTRY
56+
done
57+
58+
npm config set $CODEARTIFACT_REGISTRY_URI:_authToken=$CODEARTIFACT_AUTH_TOKEN
59+
echo "Updated global ~/.npmrc"
60+
61+
# Verify by pinging the registry
62+
npm -d ping --registry=$CODEARTIFACT_REGISTRY
63+
64+
echo "✅ Successfully logged into CodeArtifact repository"

0 commit comments

Comments
 (0)