Checking npm publishing #30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release | |
on: | |
push: | |
branches: [ fabisev/artifact-publishing ] | |
tags: [ 'v*', 'rc-*' ] | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
inputs: | |
test_mode: | |
description: 'Test mode (release, rc, or none)' | |
required: true | |
default: 'none' | |
type: choice | |
options: | |
- none | |
- release | |
- rc | |
jobs: | |
# Commenting out lint job as it's failing | |
# lint: | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v4 | |
# - name: Setup Node.js | |
# uses: actions/setup-node@v4 | |
# with: | |
# node-version: '20' | |
# cache: 'npm' | |
# - name: Install and lint | |
# run: | | |
# npm ci | |
# npm run lint | |
# npm run format | |
build: | |
runs-on: | |
- codebuild-fabisev-nodejs-test-${{ github.run_id }}-${{ github.run_attempt }} | |
# Removed dependency on lint job | |
outputs: | |
version: ${{ steps.version.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
- name: Get version | |
id: version | |
run: | | |
BASE_VERSION=$(node -p "require('./package.json').version") | |
VERSION="${BASE_VERSION}" | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Cache native dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
deps/ | |
build/ | |
key: native-deps-${{ runner.os }}-${{ hashFiles('deps/versions', 'binding.gyp') }} | |
- name: Install build dependencies | |
run: | | |
yum install -y cmake make gcc-c++ | |
- name: Clean build directories | |
run: | | |
rm -rf deps/*/build | |
- name: Install and build | |
run: | | |
npm ci | |
npm run build | |
npm pack | |
- name: Generate checksums and signatures | |
run: | | |
PACKAGE_FILE=$(ls aws-lambda-ric-*.tgz) | |
sha256sum $PACKAGE_FILE > checksums.sha256 | |
sha512sum $PACKAGE_FILE > checksums.sha512 | |
cat checksums.sha256 checksums.sha512 > checksums.txt | |
echo "Package: $PACKAGE_FILE with version prefix: ${{ steps.version.outputs.version }}" >> checksums.txt | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: package-${{ steps.version.outputs.version }} | |
path: | | |
aws-lambda-ric-*.tgz | |
checksums.* | |
retention-days: 30 | |
test: | |
runs-on: | |
- codebuild-fabisev-nodejs-test-${{ github.run_id }}-${{ github.run_attempt }} | |
needs: [build] | |
strategy: | |
matrix: | |
node-version: [18, 20, 22] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run unit tests - Node ${{ matrix.node-version }} | |
run: | | |
docker build -f test/unit/Dockerfile.nodejs${{ matrix.node-version }}.x -t unit/nodejs.${{ matrix.node-version }}x . | |
docker run --rm unit/nodejs.${{ matrix.node-version }}x | |
publish: | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: | |
- codebuild-fabisev-nodejs-test-${{ github.run_id }}-${{ github.run_attempt }} | |
needs: [build, test] | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: package-${{ needs.build.outputs.version }} | |
- name: Verify checksums | |
run: | | |
sha256sum -c checksums.sha256 | |
sha512sum -c checksums.sha512 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
# Handle release candidate version if needed | |
- name: Determine version | |
id: version | |
run: | | |
if [[ "${{ github.ref }}" == refs/tags/rc-* ]]; then | |
RC_NUMBER=${GITHUB_REF#refs/tags/rc-} | |
PACKAGE_VERSION="${{ needs.build.outputs.version }}-rc.${RC_NUMBER}" | |
echo "package_version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT | |
echo "is_rc=true" >> $GITHUB_OUTPUT | |
# Update package.json version to include RC suffix | |
npm version $PACKAGE_VERSION --no-git-tag-version | |
else | |
echo "package_version=${{ needs.build.outputs.version }}" >> $GITHUB_OUTPUT | |
echo "is_rc=false" >> $GITHUB_OUTPUT | |
fi | |
# Commented out npm publishing until token is available | |
# - name: Publish to npm | |
# run: | | |
# if [[ "${{ steps.version.outputs.is_rc }}" == "true" ]]; then | |
# npm publish aws-lambda-ric-*.tgz --tag rc | |
# else | |
# npm publish aws-lambda-ric-*.tgz | |
# fi | |
# env: | |
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Generate and Update Changelog | |
run: | | |
# Generate changelog entry for this release | |
node scripts/generate-changelog.js --output release-notes.md | |
# Update RELEASE.CHANGELOG.md with the new entry | |
node scripts/generate-changelog.js --update | |
# Commit the updated changelog | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add RELEASE.CHANGELOG.md | |
git commit -m "Update changelog for ${{ steps.version.outputs.package_version }}" || echo "No changes to commit" | |
# Show the generated release notes | |
echo "Generated release notes:" | |
cat release-notes.md | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: | | |
aws-lambda-ric-*.tgz | |
checksums.sha256 | |
checksums.sha512 | |
checksums.txt | |
prerelease: ${{ steps.version.outputs.is_rc }} | |
name: ${{ steps.version.outputs.is_rc == 'true' && format('Release Candidate {0}', steps.version.outputs.package_version) || '' }} | |
body_path: release-notes.md | |
test-publish: | |
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.test_mode != 'none') || github.ref == 'refs/heads/fabisev/artifact-publishing' | |
runs-on: | |
- codebuild-fabisev-nodejs-test-${{ github.run_id }}-${{ github.run_attempt }} | |
needs: [build, test] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: package-${{ needs.build.outputs.version }} | |
- name: Verify checksums | |
run: | | |
sha256sum -c checksums.sha256 | |
sha512sum -c checksums.sha512 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Get NPM token from AWS Secrets Manager | |
run: | | |
NPM_TOKEN=$(aws secretsmanager get-secret-value --secret-id NPM-TOKEN --region eu-north-1 --query SecretString --output text | jq -r .token) | |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc | |
echo "registry=https://registry.npmjs.org/" >> ~/.npmrc | |
echo "Authenticated as: $(npm whoami)" | |
- name: Test Release Publishing | |
if: github.event.inputs.test_mode == 'release' || github.ref == 'refs/heads/fabisev/artifact-publishing' | |
run: | | |
echo "=== TESTING RELEASE PUBLISHING ===" | |
# Extract and modify package for testing | |
tar -xzf aws-lambda-ric-*.tgz | |
cd package | |
# Use a simple package name to avoid spam detection | |
PACKAGE_NAME="icecream-shop" | |
npm pkg set name="${PACKAGE_NAME}" | |
echo "Package name: ${PACKAGE_NAME}" | |
echo "Publishing to npm with version: ${{ needs.build.outputs.version }}" | |
# Try to publish and capture error details | |
if ! npm publish --access public; then | |
echo "❌ Publish failed, showing debug logs:" | |
echo "=== NPM DEBUG LOG ===" | |
find /root/.npm/_logs -name "*debug*.log" -exec cat {} \; 2>/dev/null || echo "No debug logs found" | |
echo "=== END DEBUG LOG ===" | |
exit 1 | |
fi | |
echo "✅ Successfully published test package to npm!" | |
- name: Test RC Publishing | |
if: github.event.inputs.test_mode == 'rc' | |
run: | | |
echo "=== TESTING RC PUBLISHING ===" | |
# Extract and modify package for testing | |
tar -xzf aws-lambda-ric-*.tgz | |
cd package | |
# Use a completely random package name to avoid conflicts | |
RANDOM_ID=$(openssl rand -hex 8) | |
TIMESTAMP=$(date +%s) | |
npm pkg set name="test-lambda-ric-${RANDOM_ID}-${TIMESTAMP}" | |
# Simulate RC version | |
RC_NUMBER="1" | |
PACKAGE_VERSION="${{ needs.build.outputs.version }}-rc.${RC_NUMBER}" | |
echo "Publishing RC to npm with version: ${PACKAGE_VERSION}" | |
# Update version for RC | |
npm version ${PACKAGE_VERSION} --no-git-tag-version | |
npm publish --tag rc --access public | |
echo "✅ Successfully published RC test package to npm!" |