From 64815729817523534090abe4fc48e6a69f9e1345 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Thu, 23 Oct 2025 16:17:30 +0000 Subject: [PATCH] fix(version): read current version from deno.json and latest version from Gitea API - Replace static commitinfo with dynamic deno.json import - Change version check from npm registry to Gitea releases API - Delete obsolete ts/00_commitinfo_data.ts - Ensures version consistency across updates --- .gitea/release-template.md | 31 +++++ .github/workflows/npm-publish.yml | 183 ------------------------------ deno.json | 2 +- install.sh | 2 +- package.json | 2 +- ts/00_commitinfo_data.ts | 8 -- ts/nupst.ts | 18 +-- 7 files changed, 45 insertions(+), 201 deletions(-) create mode 100644 .gitea/release-template.md delete mode 100644 .github/workflows/npm-publish.yml delete mode 100644 ts/00_commitinfo_data.ts diff --git a/.gitea/release-template.md b/.gitea/release-template.md new file mode 100644 index 0000000..7b9f724 --- /dev/null +++ b/.gitea/release-template.md @@ -0,0 +1,31 @@ +## NUPST {{VERSION}} + +Pre-compiled binaries for multiple platforms. + +### Installation + +#### Option 1: Via npm (recommended) +```bash +npm install -g @serve.zone/nupst +``` + +#### Option 2: Via installer script +```bash +curl -sSL https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh | sudo bash +``` + +#### Option 3: Direct binary download +Download the appropriate binary for your platform from the assets below and make it executable. + +### Supported Platforms +- Linux x86_64 (x64) +- Linux ARM64 (aarch64) +- macOS x86_64 (Intel) +- macOS ARM64 (Apple Silicon) +- Windows x86_64 + +### Checksums +SHA256 checksums are provided in `SHA256SUMS.txt` for binary verification. + +### npm Package +The npm package includes automatic binary detection and installation for your platform. diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml deleted file mode 100644 index abd220b..0000000 --- a/.github/workflows/npm-publish.yml +++ /dev/null @@ -1,183 +0,0 @@ -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" \ No newline at end of file diff --git a/deno.json b/deno.json index 2af1daa..759c885 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@serve.zone/nupst", - "version": "5.1.7", + "version": "5.1.8", "exports": "./mod.ts", "nodeModulesDir": "auto", "tasks": { diff --git a/install.sh b/install.sh index b59699c..7601019 100644 --- a/install.sh +++ b/install.sh @@ -249,7 +249,7 @@ echo "" # Restart service if it was running before update if [ $SERVICE_WAS_RUNNING -eq 1 ]; then echo "Restarting NUPST service..." - systemctl start nupst + systemctl restart nupst echo "Service restarted successfully." echo "" fi diff --git a/package.json b/package.json index 27f03b2..4374356 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@serve.zone/nupst", - "version": "5.1.7", + "version": "5.1.8", "description": "Network UPS Shutdown Tool - Monitor SNMP-enabled UPS devices and orchestrate graceful system shutdowns during power emergencies", "keywords": [ "ups", diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts deleted file mode 100644 index c68d86a..0000000 --- a/ts/00_commitinfo_data.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * autocreated commitinfo by @push.rocks/commitinfo - */ -export const commitinfo = { - name: '@serve.zone/nupst', - version: '5.1.2', - description: 'Network UPS Shutdown Tool - Monitor SNMP-enabled UPS devices and orchestrate graceful system shutdowns during power emergencies' -} diff --git a/ts/nupst.ts b/ts/nupst.ts index 2a3a95b..b3df72f 100644 --- a/ts/nupst.ts +++ b/ts/nupst.ts @@ -1,7 +1,7 @@ import { NupstSnmp } from './snmp/manager.ts'; import { NupstDaemon } from './daemon.ts'; import { NupstSystemd } from './systemd.ts'; -import { commitinfo } from './00_commitinfo_data.ts'; +import denoConfig from '../deno.json' with { type: 'json' }; import { logger } from './logger.ts'; import { UpsHandler } from './cli/ups-handler.ts'; import { GroupHandler } from './cli/group-handler.ts'; @@ -105,7 +105,7 @@ export class Nupst { * @returns The current version string */ public getVersion(): string { - return commitinfo.version; + return denoConfig.version; } /** @@ -153,8 +153,8 @@ export class Nupst { private getLatestVersion(): Promise { return new Promise((resolve, reject) => { const options = { - hostname: 'registry.npmjs.org', - path: '/@serve.zone/nupst', + hostname: 'code.foss.global', + path: '/api/v1/repos/serve.zone/nupst/releases/latest', method: 'GET', headers: { 'Accept': 'application/json', @@ -172,10 +172,14 @@ export class Nupst { res.on('end', () => { try { const response = JSON.parse(data); - if (response['dist-tags'] && response['dist-tags'].latest) { - resolve(response['dist-tags'].latest); + if (response.tag_name) { + // Strip 'v' prefix from tag name (e.g., "v5.1.7" -> "5.1.7") + const version = response.tag_name.startsWith('v') + ? response.tag_name.substring(1) + : response.tag_name; + resolve(version); } else { - reject(new Error('Failed to parse version from npm registry response')); + reject(new Error('Failed to parse version from Gitea API response')); } } catch (error) { reject(error);