feat(packaging): Add npm packaging and installer: wrapper, postinstall downloader, publish workflow, and packaging files
This commit is contained in:
183
.github/workflows/npm-publish.yml
vendored
Normal file
183
.github/workflows/npm-publish.yml
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
name: Publish to npm
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Version to publish (e.g., 5.0.6)'
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
build-and-publish:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
# Checkout the repository
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Setup Deno
|
||||
- name: Setup Deno
|
||||
uses: denoland/setup-deno@v1
|
||||
with:
|
||||
deno-version: v1.x
|
||||
|
||||
# Setup Node.js for npm publishing
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18.x'
|
||||
registry-url: 'https://registry.npmjs.org/'
|
||||
|
||||
# Compile binaries for all platforms
|
||||
- name: Compile binaries
|
||||
run: |
|
||||
echo "Compiling binaries for all platforms..."
|
||||
deno task compile
|
||||
echo ""
|
||||
echo "Binary sizes:"
|
||||
ls -lh dist/binaries/
|
||||
|
||||
# Update version in package.json if triggered manually
|
||||
- name: Update version in package.json
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
run: |
|
||||
VERSION=${{ github.event.inputs.version }}
|
||||
echo "Updating package.json to version ${VERSION}"
|
||||
npm version ${VERSION} --no-git-tag-version
|
||||
|
||||
# Extract version from tag if triggered by tag push
|
||||
- name: Extract version from tag
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: |
|
||||
VERSION=${GITHUB_REF#refs/tags/v}
|
||||
echo "VERSION=${VERSION}" >> $GITHUB_ENV
|
||||
echo "Extracted version: ${VERSION}"
|
||||
|
||||
# Ensure versions are synchronized
|
||||
- name: Sync versions
|
||||
run: |
|
||||
if [ -n "${VERSION}" ]; then
|
||||
echo "Syncing version ${VERSION} across files..."
|
||||
|
||||
# Update deno.json
|
||||
sed -i "s/\"version\": \".*\"/\"version\": \"${VERSION}\"/" deno.json
|
||||
|
||||
# Update package.json
|
||||
npm version ${VERSION} --no-git-tag-version --allow-same-version
|
||||
|
||||
echo "Updated versions:"
|
||||
echo "deno.json: $(grep '"version"' deno.json)"
|
||||
echo "package.json: $(grep '"version"' package.json | head -1)"
|
||||
fi
|
||||
|
||||
# Generate SHA256 checksums for binaries
|
||||
- name: Generate checksums
|
||||
run: |
|
||||
cd dist/binaries
|
||||
sha256sum * > SHA256SUMS
|
||||
echo "Checksums generated:"
|
||||
cat SHA256SUMS
|
||||
cd ../..
|
||||
|
||||
# Create npm package
|
||||
- name: Create npm package
|
||||
run: |
|
||||
echo "Creating npm package..."
|
||||
npm pack
|
||||
echo ""
|
||||
echo "Package created:"
|
||||
ls -lh *.tgz
|
||||
|
||||
# Test package installation locally
|
||||
- name: Test local installation
|
||||
run: |
|
||||
echo "Testing local package installation..."
|
||||
PACKAGE_FILE=$(ls *.tgz)
|
||||
npm install -g ${PACKAGE_FILE}
|
||||
|
||||
echo ""
|
||||
echo "Testing nupst command:"
|
||||
nupst --version || echo "Note: Binary execution may fail in CI environment"
|
||||
|
||||
echo ""
|
||||
echo "Checking installed files:"
|
||||
npm ls -g @serve.zone/nupst
|
||||
|
||||
# Publish to npm (only on tag push or manual trigger)
|
||||
- name: Publish to npm
|
||||
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
echo "Publishing to npm registry..."
|
||||
npm publish --access public
|
||||
|
||||
echo ""
|
||||
echo "✅ Successfully published @serve.zone/nupst to npm!"
|
||||
echo ""
|
||||
echo "Package info:"
|
||||
npm view @serve.zone/nupst
|
||||
|
||||
# Create GitHub Release (only on tag push)
|
||||
- name: Create GitHub Release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
dist/binaries/nupst-*
|
||||
dist/binaries/SHA256SUMS
|
||||
*.tgz
|
||||
generate_release_notes: true
|
||||
body: |
|
||||
## NUPST ${{ env.VERSION }}
|
||||
|
||||
### Installation
|
||||
|
||||
#### Via npm (recommended)
|
||||
```bash
|
||||
npm install -g @serve.zone/nupst
|
||||
```
|
||||
|
||||
#### Direct download
|
||||
Download the appropriate binary for your platform from the assets below.
|
||||
|
||||
### Platform Support
|
||||
- Linux x64 / ARM64
|
||||
- macOS x64 / ARM64 (Apple Silicon)
|
||||
- Windows x64
|
||||
|
||||
### Checksums
|
||||
SHA256 checksums are available in `SHA256SUMS` file.
|
||||
|
||||
# Verify the published package
|
||||
verify:
|
||||
needs: build-and-publish
|
||||
runs-on: ubuntu-latest
|
||||
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
|
||||
|
||||
steps:
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18.x'
|
||||
|
||||
- name: Wait for npm propagation
|
||||
run: sleep 30
|
||||
|
||||
- name: Verify npm package
|
||||
run: |
|
||||
echo "Verifying published package..."
|
||||
npm view @serve.zone/nupst
|
||||
|
||||
echo ""
|
||||
echo "Testing installation from npm:"
|
||||
npm install -g @serve.zone/nupst
|
||||
|
||||
echo ""
|
||||
echo "Package installed successfully!"
|
||||
which nupst || echo "Binary location check skipped"
|
||||
Reference in New Issue
Block a user