Skip to content

Commit 0cadb37

Browse files
npm registry
ISSUE: CLDSRVCLT-7
1 parent adc3ab3 commit 0cadb37

File tree

2 files changed

+88
-36
lines changed

2 files changed

+88
-36
lines changed

.github/workflows/release.yml

Lines changed: 84 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,114 @@
11
---
2-
name: release
3-
run-name: release ${{ inputs.tag }}
2+
name: Release
3+
run-name: Release ${{ github.event.inputs.tag || '0.0.0-test' }}
44

55
on:
6-
# Uncomment to test your work as a release before it's merged
7-
# push:
8-
# branches:
9-
# - improvement/CLDSRVCLT-X
6+
# For testing - remove before merging
7+
push:
8+
branches:
9+
- improvement/CLDSRVCLT-7
1010
workflow_dispatch:
1111
inputs:
1212
tag:
1313
description: 'Tag to be released (e.g., 1.0.0)'
1414
required: true
1515

16+
env:
17+
# Use input tag for workflow_dispatch, or test tag for push events
18+
RELEASE_TAG: ${{ github.event.inputs.tag || '0.0.0-test' }}
19+
1620
jobs:
17-
build-and-tag:
18-
name: Build and tag
21+
check:
22+
name: Preliminary checks
1923
runs-on: ubuntu-latest
20-
permissions:
21-
contents: write
22-
24+
# Only run check for manual workflow_dispatch (not for push events)
25+
if: github.event_name == 'workflow_dispatch'
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
30+
- name: Ensure version matches tag
31+
run: |
32+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
33+
if [ "$PACKAGE_VERSION" != "${{ env.RELEASE_TAG }}" ]; then
34+
echo "::error file=package.json::Version $PACKAGE_VERSION doesn't match tag ${{ env.RELEASE_TAG }}"
35+
exit 1
36+
fi
37+
38+
build:
39+
name: Build and test
40+
runs-on: ubuntu-latest
41+
# For workflow_dispatch: wait for check. For push: run immediately
42+
needs: check
43+
if: always() && (needs.check.result == 'success' || needs.check.result == 'skipped')
2344
steps:
2445
- name: Checkout code
2546
uses: actions/checkout@v4
2647

2748
- name: Setup and Build
2849
uses: ./.github/actions/setup-and-build
2950

30-
- name: Create Tag with Build Artifacts
31-
run: |
32-
# Configure git user to the GitHub Actions bot
33-
git config --global user.name "github-actions[bot]"
34-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
51+
- name: Run tests
52+
run: yarn test
3553

36-
# Force add the build folders (even if they are in .gitignore)
37-
git add -f dist build
54+
- name: Upload build artifacts
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: build-artifacts
58+
path: |
59+
dist/
60+
build/
3861
39-
# Determine tag name
40-
TAG_NAME="${{ inputs.tag }}"
41-
if [ -z "$TAG_NAME" ]; then
42-
TAG_NAME="test-${{ github.sha }}"
43-
fi
62+
publish-npm:
63+
name: Publish to npm registry
64+
runs-on: ubuntu-latest
65+
needs: build
66+
permissions:
67+
contents: read
68+
steps:
69+
- name: Checkout code
70+
uses: actions/checkout@v4
71+
72+
- name: Download build artifacts
73+
uses: actions/download-artifact@v4
74+
with:
75+
name: build-artifacts
4476

45-
# Commit the build artifacts
46-
git commit -m "Build artifacts for version $TAG_NAME"
77+
- name: Setup Node.js for npm registry
78+
uses: actions/setup-node@v4
79+
with:
80+
node-version: '20'
81+
registry-url: 'https://registry.npmjs.org'
4782

48-
# Create the tag
49-
git tag $TAG_NAME
83+
- name: Publish to npm
84+
run: npm publish
85+
env:
86+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5087

51-
# Push the tag to the repository
52-
git push origin $TAG_NAME
88+
create-release:
89+
name: Create GitHub Release
90+
runs-on: ubuntu-latest
91+
needs: publish-npm
92+
# Only create GitHub release for manual workflow_dispatch (not test pushes)
93+
if: github.event_name == 'workflow_dispatch'
94+
permissions:
95+
contents: write
96+
steps:
97+
- name: Checkout code
98+
uses: actions/checkout@v4
5399

54-
# Export tag name for next step
55-
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
56-
id: create_tag
100+
- name: Create Git Tag
101+
run: |
102+
git config --global user.name "github-actions[bot]"
103+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
104+
git tag ${{ env.RELEASE_TAG }}
105+
git push origin ${{ env.RELEASE_TAG }}
57106
58107
- name: Create GitHub Release
59108
uses: softprops/action-gh-release@v2
60109
with:
61-
tag_name: ${{ steps.create_tag.outputs.tag_name }}
62-
name: Release ${{ steps.create_tag.outputs.tag_name }}
63-
draft: false
64-
prerelease: false
110+
tag_name: ${{ env.RELEASE_TAG }}
111+
name: Release ${{ env.RELEASE_TAG }}
112+
generate_release_notes: true
65113
env:
66114
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"dist",
1212
"build/smithy/source/typescript-codegen"
1313
],
14+
"publishConfig": {
15+
"access": "public",
16+
"registry": "https://registry.npmjs.org"
17+
},
1418
"scripts": {
1519
"clean:build": "rm -rf build dist",
1620
"build:smithy": "smithy build",

0 commit comments

Comments
 (0)