Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
119 changes: 119 additions & 0 deletions .github/workflows/validate-consistency.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Validate Repository Consistency

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
validate-consistency:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Validate metadata and version consistency
run: |
echo "🔍 Validating repository consistency..."

# Check if metadata file exists and is valid JSON
if [[ ! -f "config/metadata.json" ]]; then
echo "❌ Metadata file not found: config/metadata.json"
exit 1
fi

if ! jq empty config/metadata.json 2>/dev/null; then
echo "❌ Invalid JSON in metadata file"
exit 1
fi

echo "✅ Metadata file is valid JSON"

# Extract versions from different sources
METADATA_VERSION=$(jq -r '.version' config/metadata.json)
TEMPLATE_VERSION=$(grep "^**Version:**" template.md | head -1 | sed 's/.*Version:\*\* *//' | tr -d ' ' || echo "unknown")
PACKAGE_VERSION=$(grep '"version":' package.json | head -1 | sed 's/.*"version": *"//;s/".*//' || echo "unknown")

echo "📋 Version Comparison:"
echo " Metadata: $METADATA_VERSION"
echo " Template: $TEMPLATE_VERSION"
echo " Package: $PACKAGE_VERSION"

# Check version consistency
INCONSISTENT=false

if [[ "$METADATA_VERSION" != "$TEMPLATE_VERSION" && "$TEMPLATE_VERSION" != "unknown" ]]; then
echo "❌ Metadata version ($METADATA_VERSION) doesn't match template version ($TEMPLATE_VERSION)"
INCONSISTENT=true
fi

if [[ "$METADATA_VERSION" != "$PACKAGE_VERSION" && "$PACKAGE_VERSION" != "unknown" ]]; then
echo "❌ Metadata version ($METADATA_VERSION) doesn't match package.json version ($PACKAGE_VERSION)"
INCONSISTENT=true
fi

if [[ "$INCONSISTENT" == "true" ]]; then
echo ""
echo "💡 Run './scripts/manage-versions.sh sync' or './scripts/manage-versions.sh update <version>' to fix inconsistencies"
exit 1
fi

echo "✅ All versions are consistent!"

- name: Validate snippet files exist
run: |
echo "📄 Validating snippet files..."

required_snippets=(
"snippets/version-check-command.md"
"snippets/github-action-version-check.yml"
"snippets/version-management-commands.md"
)

for snippet in "${required_snippets[@]}"; do
if [[ -f "$snippet" ]]; then
echo "✅ $snippet exists"
else
echo "❌ Missing required snippet: $snippet"
exit 1
fi
done

- name: Validate documentation references snippets
run: |
echo "🔗 Validating documentation uses centralized snippets..."

# Check that docs reference snippets instead of duplicating content
duplicated_content_count=0

# Count GitHub Action YAML duplications (should be minimal now)
yaml_duplications=$(grep -r -l "name:.*Check.*Template.*Version" docs/ templates/ 2>/dev/null | wc -l)
echo "GitHub Action YAML references in docs/templates: $yaml_duplications"

if [[ $yaml_duplications -gt 1 ]]; then
echo "⚠️ Consider further consolidation of GitHub Action YAML content"
fi

# Check that curl commands are referenced via snippets
snippet_references=$(grep -r "snippets/" docs/ templates/ 2>/dev/null | wc -l)
echo "Snippet references found: $snippet_references"

if [[ $snippet_references -lt 3 ]]; then
echo "❌ Documentation should reference more centralized snippets"
exit 1
fi

echo "✅ Documentation properly references centralized snippets"

- name: Run centralized metadata tests
run: |
echo "🧪 Running centralized metadata tests..."
if [[ -f "tests/test-centralized-metadata.sh" ]]; then
chmod +x tests/test-centralized-metadata.sh
./tests/test-centralized-metadata.sh
else
echo "⚠️ Centralized metadata tests not found"
fi
5 changes: 5 additions & 0 deletions README.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the script is for advanced users, move to that section. regular and best practise should stick to the automation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the manual version check script to the new "Advanced Usage" section in the README. Regular users are now guided to use the automated processes first, with manual commands available for advanced users who need more control. Commit: 9a667c5

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ If you want to manually check your template status:
curl -s https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/scripts/check-template-version.sh | bash
```

This script will:
- Compare your local template version with the latest available
- Provide update guidance if your template is outdated
- Show you what's changed in newer versions

### Automated Continuous Monitoring

The [Initial Setup Template](templates/initial-setup-automation.md) automatically configures:
Expand Down
149 changes: 149 additions & 0 deletions config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Centralized Configuration and Snippets

This directory contains the centralized configuration and reusable content snippets for the ioBroker Copilot Instructions repository.

## Directory Structure

```
config/
├── metadata.json # Centralized repository metadata and configuration
└── README.md # This file

snippets/
├── version-check-command.md # Reusable version check command
├── github-action-version-check.yml # GitHub Action template for version monitoring
└── version-management-commands.md # Version management script commands
```

## Metadata Configuration (metadata.json)

The `metadata.json` file serves as the single source of truth for:

- **Version Information**: Current template version
- **Repository URLs**: GitHub repository and raw content URLs
- **Script Paths**: Locations of management scripts
- **Automation Config**: GitHub Action settings and schedules

### Schema

```json
{
"version": "X.Y.Z", // Current template version
"repository": {
"url": "https://github.com/...", // Repository homepage URL
"raw_base": "https://raw.github..." // Raw content base URL
},
"template": {
"file": "template.md", // Template filename
"target_path": ".github/..." // Target installation path
},
"scripts": {
"check_template_version": "scripts/...", // Version check script path
"manage_versions": "scripts/..." // Version management script path
},
"automation": {
"workflow_file": ".github/workflows/...", // GitHub Action filename
"cron_schedule": "0 0 * * 0", // Weekly schedule
"labels": ["template-update", ...] // Issue labels
}
}
```

## Reusable Snippets

### Version Check Command (`version-check-command.md`)

Contains the standardized curl command for checking template versions. Referenced throughout documentation instead of duplicating the command.

**Usage in Documentation**:
```markdown
<!-- Include version check instructions -->
```

### GitHub Action Template (`github-action-version-check.yml`)

Complete GitHub Action workflow for automated template version monitoring. Used by templates and documentation instead of duplicating the YAML.

**Features**:
- Weekly automated checks
- Automatic issue creation
- Custom content preservation
- Both setup and update scenarios

### Version Management Commands (`version-management-commands.md`)

Standard documentation for the version management script commands and their functions.

## Integration with Scripts

The centralized metadata is used by:

- **`scripts/shared-utils.sh`**: Utility functions for accessing metadata
- **`scripts/extract-version.sh`**: Enhanced with metadata fallback
- **`scripts/manage-versions.sh`**: Updates metadata when versions change
- **`scripts/check-template-version.sh`**: Uses metadata for URL generation

## Benefits of Centralization

### Before (Duplicated Content)
- Version check curl command duplicated in 6+ files
- GitHub Action YAML duplicated in 3+ files
- Version management instructions repeated across docs
- Manual updates required in multiple locations

### After (Centralized System)
- **Single Source of Truth**: All metadata in one place
- **Automatic Consistency**: Scripts sync versions across files
- **Reusable Snippets**: Documentation references shared content
- **Easier Maintenance**: Update once, apply everywhere
- **Version Validation**: Automated consistency checking

## Validation and Testing

The centralized system includes:

- **JSON Schema Validation**: Metadata file structure validation
- **Consistency Checks**: Version synchronization across files
- **Integration Tests**: Script and documentation integration
- **GitHub Action**: Automated validation in CI/CD
- **Comprehensive Test Suite**: `tests/test-centralized-metadata.sh`

## Usage for Documentation

When writing documentation, reference snippets instead of duplicating content:

```markdown
### Version Check

Use our [version check command](../snippets/version-check-command.md).

### GitHub Action Setup

For automated monitoring, see our [GitHub Action template](../snippets/github-action-version-check.yml).
```

## Updating the System

### Adding New Metadata
1. Update `config/metadata.json` with new fields
2. Update `scripts/shared-utils.sh` accessor functions
3. Add validation to `tests/test-centralized-metadata.sh`
4. Update this README with schema documentation

### Creating New Snippets
1. Create snippet file in `snippets/` directory
2. Update documentation to reference the snippet
3. Remove duplicated content from existing files
4. Add tests for snippet usage and content

### Version Updates
Use the centralized version management:
```bash
./scripts/manage-versions.sh update X.Y.Z
```

This automatically updates:
- `config/metadata.json`
- `template.md`
- `package.json`
- All derived documentation
20 changes: 20 additions & 0 deletions config/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.4.0",
"repository": {
"url": "https://github.com/DrozmotiX/ioBroker-Copilot-Instructions",
"raw_base": "https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main"
},
"template": {
"file": "template.md",
"target_path": ".github/copilot-instructions.md"
},
"scripts": {
"check_template_version": "scripts/check-template-version.sh",
"manage_versions": "scripts/manage-versions.sh"
},
"automation": {
"workflow_file": ".github/workflows/check-copilot-template.yml",
"cron_schedule": "0 0 * * 0",
"labels": ["template-update", "automation"]
}
}
5 changes: 5 additions & 0 deletions docs/automated-updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ Check if your template needs updating:
curl -s https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/scripts/check-template-version.sh | bash
```

This script will:
- Compare your local template version with the latest available
- Provide update guidance if your template is outdated
- Show you what's changed in newer versions

## 🛠️ Advanced Automated Method

For repositories with existing automation workflows, use the full template:
Expand Down
42 changes: 16 additions & 26 deletions docs/maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This repository includes comprehensive version management scripts that automatic
./scripts/manage-versions.sh sync

# Update to a new version across all files
./scripts/manage-versions.sh update 0.3.2
./scripts/manage-versions.sh update 0.4.1
```

### What the Scripts Do
Expand All @@ -68,39 +68,29 @@ These scripts ensure that:

### Version Check for Users

Users can validate their local template version with our provided script:
Use the provided script to check if your template is up-to-date:

```bash
# Download and run the version check script
curl -s https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/scripts/check-template-version.sh | bash
```

This script will:
- Compare your local template version with the latest available
- Provide update guidance if your template is outdated
- Show you what's changed in newer versions

### GitHub Action for Continuous Monitoring

You can set up a GitHub Action to periodically check if templates are up-to-date:

```yaml
# .github/workflows/check-copilot-template.yml
name: Check Copilot Template Version
on:
schedule:
- cron: '0 0 * * 0' # Weekly check
workflow_dispatch:

jobs:
check-template:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check template version
run: |
CURRENT_VERSION=$(grep "Version:" .github/copilot-instructions.md | head -1 | sed 's/.*Version:\s*//')
LATEST_VERSION=$(curl -s https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md | grep "Version:" | head -1 | sed 's/.*Version:\s*//')
if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then
echo "Template is outdated. Current: $CURRENT_VERSION, Latest: $LATEST_VERSION"
exit 1
fi
```
For automated template monitoring, copy the GitHub Action from our centralized template:

**Reference**: [GitHub Action Template](../snippets/github-action-version-check.yml)

This action will:
- Check for template updates weekly
- Automatically create GitHub issues when updates are available
- Handle both initial setup and update scenarios
- Preserve custom content during updates

## Automated Testing Infrastructure

Expand Down
Loading
Loading