Skip to content

hotifx oscal_server_path #1140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/scripts/ci-get-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// get-version.mjs
import { readFileSync, existsSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join, resolve } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// Function to find repository root (where package.json lives)
function findRepoRoot(startDir) {
let currentDir = startDir;
while (currentDir !== '/') {
const packagePath = join(currentDir, 'package.json');
if (existsSync(packagePath)) {
return currentDir;
}
currentDir = dirname(currentDir);
}
throw new Error('Could not find repository root (no package.json found)');
}

// Get repo root
const repoRoot = findRepoRoot(__dirname);

// Get source, name and default version from command line arguments
const [source, name, defaultVersion = '0.5.0'] = process.argv.slice(2);

if (!source || !name) {
console.error('Usage: node ci-get-version.js [package|tool] [name] [defaultVersion]');
process.exit(1);
}

try {
if (source === 'package') {
const packagePath = join(repoRoot, 'package.json');
const packageJson = JSON.parse(readFileSync(packagePath, 'utf8'));
const version = packageJson.dependencies?.[name] || defaultVersion;
console.log(version)
} else if (source === 'tool') {
const toolPath = join(repoRoot, '.tool-versions');
const content = readFileSync(toolPath, 'utf8');
const lines = content.split('\n').map(line => line.trim());
const matchingLines = lines.filter(line => line.startsWith(name));
const version = matchingLines[0]?.split(/\s+/)[1] || defaultVersion;
console.log(version)
} else {
console.error('Invalid source. Use "package" or "tool"');
process.exit(1);
}
} catch (error) {
console.log(defaultVersion);
}
22 changes: 16 additions & 6 deletions src/validations/module.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# Variables
OSCAL_VERSION = $(shell jq -r .dependencies.oscal package.json)
OSCAL_CLI_VERSION = $(shell awk '/^oscal-cli/ {print $$2}' .tool-versions)
OSCAL_SERVER_VERSION = $(shell awk '/^oscal-server/ {print $$2}' .tool-versions)

# Get tool versions using Node script
OSCAL_VERSION := $(shell node src/scripts/ci-get-version.js package oscal)
OSCAL_CLI_VERSION := $(shell node src/scripts/ci-get-version.js tool oscal-cli)
OSCAL_SERVER_VERSION := $(shell node src/scripts/ci-get-version.js tool oscal-server)
OSCAL_SERVER_PATH := $(shell node -e "console.log(process.cwd())")

# Optional: Add version checking targets
check-versions:
@echo "Using versions:"
@echo "OSCAL CLI: $(OSCAL_CLI_VERSION)"
@echo "OSCAL Server: $(OSCAL_SERVER_VERSION)"
@echo "OSCAL JS: $(OSCAL_VERSION)"
@echo "OSCAL SERVER ALLOWED DIR: $(OSCAL_SERVER_PATH)"
OSCAL_CLI = npx oscal@$(OSCAL_VERSION)
SRC_DIR = ./src
DIST_DIR = ./dist
Expand All @@ -14,7 +24,7 @@ init-validations:
@echo "Installing node modules..."
npm install
$(OSCAL_CLI) use $(OSCAL_CLI_VERSION)
$(OSCAL_CLI) server update $(OSCAL_SERVER_VERSION)
$(OSCAL_CLI) server update -t $(OSCAL_SERVER_VERSION)

# Style lint
.PHONY: lint-style
Expand All @@ -27,7 +37,7 @@ lint-validations:
build-validations:
@echo "Running Cucumber Tests"
$(OSCAL_CLI) server stop
$(OSCAL_CLI) server start -bg
npx cross-env OSCAL_SERVER_PATH=$(OSCAL_SERVER_PATH) $(OSCAL_CLI) server start -bg
@npm run test:server
$(OSCAL_CLI) server stop

Expand Down
Loading