Skip to content

Commit 9770fa8

Browse files
author
Fabiana Severin
committed
Testing npm publishing using codebuild
1 parent cdc0773 commit 9770fa8

File tree

1 file changed

+38
-132
lines changed

1 file changed

+38
-132
lines changed

.github/workflows/build-and-release.yml

Lines changed: 38 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,11 @@ on:
77
pull_request:
88
branches: [ main ]
99
workflow_dispatch:
10-
inputs:
11-
test_mode:
12-
description: 'Test mode (release, rc, or none)'
13-
required: true
14-
default: 'none'
15-
type: choice
16-
options:
17-
- none
18-
- release
19-
- rc
2010

2111
jobs:
22-
# Commenting out lint job as it's failing
23-
# lint:
24-
# runs-on: ubuntu-latest
25-
# steps:
26-
# - uses: actions/checkout@v4
27-
# - name: Setup Node.js
28-
# uses: actions/setup-node@v4
29-
# with:
30-
# node-version: '20'
31-
# cache: 'npm'
32-
# - name: Install and lint
33-
# run: |
34-
# npm ci
35-
# npm run lint
36-
# npm run format
37-
3812
build:
3913
runs-on:
40-
- codebuild-awsaws-lambda-nodejs-runtime-interface-client-${{ github.run_id }}-${{ github.run_attempt }}
41-
# Removed dependency on lint job
14+
- project-awsaws-lambda-nodejs-runtime-interface-client
4215
outputs:
4316
version: ${{ steps.version.outputs.version }}
4417
steps:
@@ -54,8 +27,7 @@ jobs:
5427
id: version
5528
run: |
5629
BASE_VERSION=$(node -p "require('./package.json').version")
57-
VERSION="${BASE_VERSION}"
58-
echo "version=$VERSION" >> $GITHUB_OUTPUT
30+
echo "version=$BASE_VERSION" >> $GITHUB_OUTPUT
5931
6032
- name: Cache native dependencies
6133
uses: actions/cache@v4
@@ -66,26 +38,24 @@ jobs:
6638
key: native-deps-${{ runner.os }}-${{ hashFiles('deps/versions', 'binding.gyp') }}
6739

6840
- name: Install build dependencies
69-
run: |
70-
yum install -y cmake make gcc-c++
41+
run: yum install -y cmake make gcc-c++
7142

7243
- name: Clean build directories
73-
run: |
74-
rm -rf deps/*/build
44+
run: rm -rf deps/*/build
7545

7646
- name: Install and build
7747
run: |
7848
npm ci
7949
npm run build
8050
npm pack
8151
82-
- name: Generate checksums and signatures
52+
- name: Generate checksums
8353
run: |
8454
PACKAGE_FILE=$(ls aws-lambda-ric-*.tgz)
8555
sha256sum $PACKAGE_FILE > checksums.sha256
8656
sha512sum $PACKAGE_FILE > checksums.sha512
8757
cat checksums.sha256 checksums.sha512 > checksums.txt
88-
echo "Package: $PACKAGE_FILE with version prefix: ${{ steps.version.outputs.version }}" >> checksums.txt
58+
echo "Package: $PACKAGE_FILE with version: ${{ steps.version.outputs.version }}" >> checksums.txt
8959
9060
- name: Upload artifacts
9161
uses: actions/upload-artifact@v4
@@ -98,7 +68,7 @@ jobs:
9868

9969
test:
10070
runs-on:
101-
- codebuild-awsaws-lambda-nodejs-runtime-interface-client-${{ github.run_id }}-${{ github.run_attempt }}
71+
- project-awsaws-lambda-nodejs-runtime-interface-client
10272
needs: [build]
10373
strategy:
10474
matrix:
@@ -112,9 +82,9 @@ jobs:
11282
docker run --rm unit/nodejs.${{ matrix.node-version }}x
11383
11484
publish:
115-
if: startsWith(github.ref, 'refs/tags/')
85+
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/fabisev/artifact-publishing'
11686
runs-on:
117-
- codebuild-awsaws-lambda-nodejs-runtime-interface-client-${{ github.run_id }}-${{ github.run_attempt }}
87+
- project-awsaws-lambda-nodejs-runtime-interface-client
11888
needs: [build, test]
11989
permissions:
12090
contents: write
@@ -136,52 +106,60 @@ jobs:
136106
with:
137107
node-version: '20'
138108

139-
# Handle release candidate version if needed
140-
- name: Determine version
109+
- name: Setup NPM authentication
110+
run: |
111+
NPM_TOKEN=$(aws secretsmanager get-secret-value --secret-id aws-lambda-runtimes/github/nodejs/npm-token --query SecretString --output text)
112+
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
113+
114+
- name: Determine version and package name
141115
id: version
142116
run: |
143-
if [[ "${{ github.ref }}" == refs/tags/rc-* ]]; then
117+
if [[ "${{ github.ref }}" == refs/heads/fabisev/artifact-publishing ]]; then
118+
# For branch testing, use a scoped package name and test version
119+
PACKAGE_VERSION="${{ needs.build.outputs.version }}-test.$(date +%s)"
120+
echo "package_version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
121+
echo "is_test=true" >> $GITHUB_OUTPUT
122+
echo "is_rc=false" >> $GITHUB_OUTPUT
123+
# Change package name to avoid conflicts
124+
npm pkg set name="avocado-toast"
125+
npm version $PACKAGE_VERSION --no-git-tag-version
126+
elif [[ "${{ github.ref }}" == refs/tags/rc-* ]]; then
144127
RC_NUMBER=${GITHUB_REF#refs/tags/rc-}
145128
PACKAGE_VERSION="${{ needs.build.outputs.version }}-rc.${RC_NUMBER}"
146129
echo "package_version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
130+
echo "is_test=false" >> $GITHUB_OUTPUT
147131
echo "is_rc=true" >> $GITHUB_OUTPUT
148-
# Update package.json version to include RC suffix
149132
npm version $PACKAGE_VERSION --no-git-tag-version
150133
else
151134
echo "package_version=${{ needs.build.outputs.version }}" >> $GITHUB_OUTPUT
135+
echo "is_test=false" >> $GITHUB_OUTPUT
152136
echo "is_rc=false" >> $GITHUB_OUTPUT
153137
fi
154138
155-
# Commented out npm publishing until token is available
156-
# - name: Publish to npm
157-
# run: |
158-
# if [[ "${{ steps.version.outputs.is_rc }}" == "true" ]]; then
159-
# npm publish aws-lambda-ric-*.tgz --tag rc
160-
# else
161-
# npm publish aws-lambda-ric-*.tgz
162-
# fi
163-
# env:
164-
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
139+
- name: Publish to npm
140+
run: |
141+
if [[ "${{ steps.version.outputs.is_test }}" == "true" ]]; then
142+
npm publish aws-lambda-ric-*.tgz --tag test
143+
elif [[ "${{ steps.version.outputs.is_rc }}" == "true" ]]; then
144+
npm publish aws-lambda-ric-*.tgz --tag rc
145+
else
146+
npm publish aws-lambda-ric-*.tgz
147+
fi
165148
166149
- name: Generate and Update Changelog
150+
if: startsWith(github.ref, 'refs/tags/')
167151
run: |
168-
# Generate changelog entry for this release
169152
node scripts/generate-changelog.js --output release-notes.md
170-
171-
# Update RELEASE.CHANGELOG.md with the new entry
172153
node scripts/generate-changelog.js --update
173-
174-
# Commit the updated changelog
175154
git config --local user.email "[email protected]"
176155
git config --local user.name "GitHub Action"
177156
git add RELEASE.CHANGELOG.md
178157
git commit -m "Update changelog for ${{ steps.version.outputs.package_version }}" || echo "No changes to commit"
179-
180-
# Show the generated release notes
181158
echo "Generated release notes:"
182159
cat release-notes.md
183160
184161
- name: Create GitHub Release
162+
if: startsWith(github.ref, 'refs/tags/')
185163
uses: softprops/action-gh-release@v2
186164
with:
187165
files: |
@@ -192,75 +170,3 @@ jobs:
192170
prerelease: ${{ steps.version.outputs.is_rc }}
193171
name: ${{ steps.version.outputs.is_rc == 'true' && format('Release Candidate {0}', steps.version.outputs.package_version) || '' }}
194172
body_path: release-notes.md
195-
196-
test-publish:
197-
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.test_mode != 'none') || github.ref == 'refs/heads/fabisev/artifact-publishing'
198-
runs-on:
199-
- codebuild-awsaws-lambda-nodejs-runtime-interface-client-${{ github.run_id }}-${{ github.run_attempt }}
200-
needs: [build, test]
201-
steps:
202-
- uses: actions/checkout@v4
203-
204-
- name: Download artifacts
205-
uses: actions/download-artifact@v4
206-
with:
207-
name: package-${{ needs.build.outputs.version }}
208-
209-
- name: Verify checksums
210-
run: |
211-
sha256sum -c checksums.sha256
212-
sha512sum -c checksums.sha512
213-
214-
- name: Setup Node.js
215-
uses: actions/setup-node@v4
216-
with:
217-
node-version: '20'
218-
219-
- name: Get NPM token from AWS Secrets Manager
220-
run: |
221-
NPM_TOKEN=$(aws secretsmanager get-secret-value --secret-id aws-lambda-runtimes/github/nodejs/npm-token --query SecretString --output text | jq -r .token)
222-
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
223-
echo "registry=https://registry.npmjs.org/" >> ~/.npmrc
224-
echo "Authenticated as: $(npm whoami)"
225-
226-
- name: Test Release Publishing
227-
if: github.event.inputs.test_mode == 'release' || github.ref == 'refs/heads/fabisev/artifact-publishing'
228-
run: |
229-
echo "=== TESTING RELEASE PUBLISHING ==="
230-
# Extract and modify package for testing
231-
tar -xzf aws-lambda-ric-*.tgz
232-
cd package
233-
234-
PACKAGE_NAME="icecream-shop"
235-
npm pkg set name="${PACKAGE_NAME}"
236-
237-
echo "Package name: ${PACKAGE_NAME}"
238-
echo "Publishing to npm with version: ${{ needs.build.outputs.version }}"
239-
240-
if ! npm publish --access public; then
241-
echo "❌ Publish failed, showing debug logs:"
242-
echo "=== NPM DEBUG LOG ==="
243-
find /root/.npm/_logs -name "*debug*.log" -exec cat {} \; 2>/dev/null || echo "No debug logs found"
244-
echo "=== END DEBUG LOG ==="
245-
exit 1
246-
fi
247-
248-
echo "✅ Successfully published test package to npm!"
249-
250-
- name: Test RC Publishing
251-
if: github.event.inputs.test_mode == 'rc'
252-
run: |
253-
echo "=== TESTING RC PUBLISHING ==="
254-
# Extract and modify package for testing
255-
tar -xzf aws-lambda-ric-*.tgz
256-
cd package
257-
PACKAGE_NAME="icecream-shop"
258-
npm pkg set name=PACKAGE_NAME
259-
# Simulate RC version
260-
RC_NUMBER="1"
261-
PACKAGE_VERSION="${{ needs.build.outputs.version }}-rc.${RC_NUMBER}"
262-
echo "Publishing RC to npm with version: ${PACKAGE_VERSION}"
263-
# Update version for RC
264-
npm version ${PACKAGE_VERSION} --no-git-tag-version
265-
npm publish --tag rc --access public
266-
echo "✅ Successfully published RC test package to npm!"

0 commit comments

Comments
 (0)