diff --git a/CHANGELOG.md b/CHANGELOG.md index 980218f..4303f64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## **WORK IN PROGRESS** +- (copilot) **NEW**: Added fully automated ioBroker Copilot setup with zero manual steps (Fixes #26) +- (copilot) **NEW**: Created initial-setup-automation.md template for comprehensive automated setup and validation +- (copilot) **NEW**: Added weekly-version-check-action.yml GitHub Action for automated template monitoring +- (copilot) **ENHANCED**: Eliminated all manual file creation steps in favor of GitHub Copilot automation +- (copilot) **NEW**: Added duplicate prevention guidance for [CUSTOMIZE] sections across all automation templates +- (copilot) **ENHANCED**: Updated all templates to automatically remove duplicate content during merges +- (copilot) **ENHANCED**: Replaced date references with version-focused information in README.md +- (copilot) **FIXED**: Added missing test helper functions to all test scripts for standalone execution +- (copilot) **FIXED**: Corrected path references in test scripts from TEST_DIR to REPO_ROOT +- (copilot) **NEW**: Added 30+ comprehensive tests for automated setup templates and functionality +- (copilot) **NEW**: Created templates/README.md with complete automation guide and usage recommendations +- (copilot) **ENHANCED**: Updated setup.md to emphasize full automation over manual processes - (copilot) **NEW**: Created GitHub issue templates for repository feedback and community collaboration (Fixes #29) - (copilot) **NEW**: Added feature request template for exploring new functionality with structured community input - (copilot) **NEW**: Added comprehensive bug report template with type selection (template issues, setup issues, bugs, questions) @@ -21,11 +33,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - (copilot) **NEW**: Added automated template update system using GitHub Copilot-powered issue templates (Fixes #24) - (copilot) **NEW**: Created copy-paste template for quick automated template validation and updates - (copilot) **NEW**: Added comprehensive automated updates documentation with step-by-step workflows -- (copilot) **ENHANCED**: Replaced manual template update process with GitHub Copilot automation that preserves all [CUSTOMIZE] sections -- (copilot) **NEW**: Added templates directory with automated-template-update.md and copy-paste-template.md for issue creation -- (copilot) **ENHANCED**: Updated README.md and setup.md to emphasize automated approach over manual processes -- (copilot) **ENHANCED**: Improved initial setup instructions to ensure [CUSTOMIZE] sections are properly used from the start -- (copilot) **NEW**: Added comprehensive test suite for automated template features (test-automated-templates.sh) - (copilot) **ENHANCED**: Reorganized README into focused documentation files by instruction type for better user experience (Fixes #22) - (copilot) **NEW**: Created separate docs/ directory with setup.md, maintenance.md, and testing.md for clear audience targeting - (copilot) **ENHANCED**: Promoted intelligent Copilot-assisted template merging instead of 1:1 copying for better version control diff --git a/README.md b/README.md index ffbb382..f818b6e 100644 --- a/README.md +++ b/README.md @@ -29,77 +29,88 @@ Your contributions help make adapter development better for the entire ioBroker ## ๐Ÿ“‹ Quick Start -![Version](https://img.shields.io/github/package-json/v/DrozmotiX/ioBroker-Copilot-Instructions?label=Current%20Version) | **Template:** [`template.md`](template.md) | ![Last Updated](https://img.shields.io/github/last-commit/DrozmotiX/ioBroker-Copilot-Instructions?label=Last%20Updated) +**๐Ÿš€ Fully Automated Setup** (Recommended for all users): + +### For New Repositories or Comprehensive Setup +1. **Create an automated setup issue** using the [Initial Setup Automation Template](templates/initial-setup-automation.md) +2. **Let GitHub Copilot handle everything**: + - โœ… Validates existing setup + - ๐Ÿ“ฅ Downloads and customizes latest template + - ๐ŸŽฏ Adds adapter-specific content + - โš™๏ธ Sets up weekly monitoring + - ๐Ÿ›ก๏ธ Preserves any existing customizations + +### For Quick Updates Only +1. **Use the** [Copy-Paste Template](templates/copy-paste-template.md) for existing setups +2. **GitHub Copilot will merge** the latest template while preserving your customizations ## ๐Ÿ“š Documentation ### ๐Ÿ› ๏ธ For Developers -- **[Setup Guide](docs/setup.md)** - Complete GitHub Copilot setup and template integration -- **[Automated Updates Guide](docs/automated-updates.md)** - Automated template updates with GitHub Copilot +- **[Setup Guide](docs/setup.md)** - Automated GitHub Copilot setup and template integration +- **[Automated Templates](templates/README.md)** - Complete guide to all automation templates - **[Testing Guide](docs/testing.md)** - Validate your template integration and Copilot functionality ### ๐Ÿ”ง For Repository Maintainers - **[Maintenance Guide](docs/maintenance.md)** - Version management, testing infrastructure, and release processes - **[Technical Testing](TESTING.md)** - Detailed testing infrastructure documentation (54+ automated tests) -## ๐Ÿ”„ Template Versioning & Updates +## ๐Ÿ”„ Automated Template Management + +### โšก Zero Manual Steps Required + +All template operations are now fully automated: -### Quick Version Check +- **โœ… Setup**: Automated via [Initial Setup Template](templates/initial-setup-automation.md) +- **๐Ÿ”„ Updates**: Automated via GitHub Actions with issue creation +- **๐Ÿ›ก๏ธ Customizations**: Always preserved during updates +- **๐Ÿ“… Monitoring**: Weekly checks with automatic notifications -Check if your template is up-to-date: +### Quick Version Check (Optional) + +If you want to manually check your template status: ```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 ``` -### Automated Template Updates - -๐Ÿค– **Use GitHub Copilot to automatically update your template** - This is now the recommended approach that preserves all your custom sections: - -#### Quick Update (Copy-Paste Method) -1. **Create an issue in your repository** with title: "๐Ÿค– Update ioBroker Copilot Instructions Template" -2. **Copy-paste this content**: - ```markdown - **GitHub Copilot**: Please help me update my ioBroker Copilot instructions template to the latest version while preserving all custom sections. - - ## Task - Update `.github/copilot-instructions.md` using this prompt: - - "Merge the ioBroker template from https://github.com/DrozmotiX/ioBroker-Copilot-Instructions/blob/main/template.md with my existing .github/copilot-instructions.md. - - REQUIREMENTS: - 1. Preserve ALL [CUSTOMIZE] sections exactly as they are - 2. Keep all project-specific context and custom instructions - 3. Add latest ioBroker best practices from the new template - 4. Update version to match latest template version - 5. Maintain Template Source reference - - Show me the changes before applying them." - - ## Validation - After update, confirm: - - [ ] All [CUSTOMIZE] sections preserved - - [ ] Version updated to latest - - [ ] Custom content intact - - [ ] Template structure complete - ``` -3. **Let GitHub Copilot handle the merge** automatically while preserving your customizations -4. **Review and apply** the proposed changes - -๐Ÿ“š **For detailed automation instructions**: See [Automated Updates Guide](docs/automated-updates.md) - -#### Alternative Templates -- **Full automation**: Use [`templates/automated-template-update.md`](templates/automated-template-update.md) for comprehensive workflow -- **Quick copy-paste**: Use [`templates/copy-paste-template.md`](templates/copy-paste-template.md) for simple updates - -### Version Information - -- **Latest Version:** v0.4.0 -- **Template Location:** [`template.md`](template.md) -- **Last Updated:** September 2025 - -You can validate your local template version by checking the version header in your `.github/copilot-instructions.md` file: +### Automated Continuous Monitoring + +The [Initial Setup Template](templates/initial-setup-automation.md) automatically configures: +- ๐Ÿ“… Weekly version checking via GitHub Actions +- ๐ŸŽฏ Automatic issue creation when updates are available +- ๐Ÿ›ก๏ธ Safe updates that preserve all custom content +- ๐Ÿšซ Prevention of duplicate update issues + +## ๐Ÿ’ก Key Features + +### โšก **Full Automation** +- **Zero Manual Configuration**: All setup handled by GitHub Copilot +- **Smart Detection**: Automatically detects existing setups and customizations +- **Safe Updates**: Custom content always preserved during template updates + +### ๐Ÿ›ก๏ธ **Customization Protection** +- **[CUSTOMIZE] Sections**: Marked areas that are automatically preserved +- **Adapter-Specific Content**: Automatically added based on your repository context +- **Version Tracking**: Automatic version management and source references + +### ๐Ÿ“… **Continuous Monitoring** +- **Weekly Checks**: GitHub Actions monitor for template updates +- **Automatic Issues**: Update notifications created automatically +- **No Maintenance**: Set once, works forever + +### ๐ŸŽฏ **Enhanced Development** +- **ioBroker-Specific Suggestions**: Context-aware code completion +- **Best Practices**: Integrated patterns from experienced developers +- **Testing Integration**: Smart suggestions for `@iobroker/testing` framework + +## ๐Ÿ“Š Version Information + +- **Current Template Version:** ![Version](https://img.shields.io/github/package-json/v/DrozmotiX/ioBroker-Copilot-Instructions?label=v) +- **Template Location:** [`template.md`](template.md) + +Your template version is automatically tracked in your `.github/copilot-instructions.md` file: ```markdown **Version:** 0.4.0 diff --git a/docs/setup.md b/docs/setup.md index 8bebc24..fdcaa60 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -36,21 +36,25 @@ This guide walks you through setting up GitHub Copilot for ioBroker adapter deve ls -la .github/copilot-instructions.md ``` -3. **Initial template setup** - If you don't have a copilot-instructions.md file yet: +3. **Automated Initial Setup** (Recommended) - **Option A: Use automated setup** (Recommended) - - **First ensure GitHub Copilot is active**: Create an issue with title "๐Ÿค– Setup GitHub Copilot" and content "GitHub Copilot: Please help me set up GitHub Copilot for this repository." - - After Copilot responds and is working, create another issue using the [copy-paste template](../templates/copy-paste-template.md) - - GitHub Copilot will create the complete template for you + **๐Ÿค– Fully Automated Process**: Use our comprehensive setup template that handles everything automatically: - **Option B: Manual template download** - ```bash - # Download the template - curl -o .github/copilot-instructions.md https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md - # Remove template comment block - sed -i '/^$/d' .github/copilot-instructions.md - ``` + 1. **Create Setup Issue**: Go to your repository's Issues and create a new issue + 2. **Use Automated Template**: Copy the content from [Initial Setup Automation Template](../templates/initial-setup-automation.md) + 3. **Let GitHub Copilot Handle Everything**: The template will: + - โœ… Validate if Copilot is already working in your repository + - ๐Ÿ” Check if copilot-instructions.md already exists + - ๐Ÿ“ฅ Download and customize the latest template automatically + - ๐ŸŽฏ Add adapter-specific customizations to [CUSTOMIZE] sections + - โš™๏ธ Set up weekly monitoring via GitHub Actions + - ๐Ÿ›ก๏ธ Preserve any existing custom content during updates + + **Benefits of Automated Setup**: + - ๐Ÿ• **No Manual Steps**: Everything is handled by GitHub Copilot + - ๐Ÿ”„ **Future-Proof**: Automatic weekly version checking + - ๐Ÿ›ก๏ธ **Safe Updates**: Custom content is always preserved + - ๐ŸŽฏ **Adapter-Specific**: Automatically tailored to your specific adapter **Important**: After initial setup, always add your project-specific content in `[CUSTOMIZE]` sections: ```markdown @@ -65,102 +69,70 @@ This guide walks you through setting up GitHub Copilot for ioBroker adapter deve ``` 4. **For existing configurations** - If your existing config needs updates, use the automated update process instead of replacing the file - -## Template Integration - -**๐Ÿค– Fully Automated Updates** - Use GitHub Copilot to handle template updates automatically while preserving all custom sections. + If your existing config needs updates, the same [Initial Setup Automation Template](../templates/initial-setup-automation.md) handles this automatically. It will: + - ๐Ÿ” Detect existing copilot-instructions.md + - ๐Ÿ”„ Merge the latest template while preserving ALL [CUSTOMIZE] sections + - โœ… Update version numbers and references + - ๐Ÿ›ก๏ธ Ensure no custom content is lost -### Option A: Automated Issue-Based Updates (Recommended) +5. **Ongoing Maintenance** + The automated setup also configures weekly monitoring via GitHub Actions that will: + - ๐Ÿ“… Check for template updates every Sunday + - ๐ŸŽฏ Create issues automatically when updates are available + - ๐Ÿ”„ Handle version management without manual intervention + - ๐Ÿ›ก๏ธ Always preserve your custom configurations during updates -**Best for**: Regular updates and team collaboration +## Automated Template Integration -1. **Create an automated update issue** - - Go to your repository's Issues - - Create new issue with title: "๐Ÿค– Update ioBroker Copilot Instructions Template" - - Use content from [`templates/copy-paste-template.md`](../templates/copy-paste-template.md) - - GitHub Copilot will automatically handle the merge +**๐Ÿค– Fully Automated Process** - All template operations are now handled via GitHub Copilot automation with zero manual steps required. -2. **Benefits of issue-based automation** - - Creates audit trail of template updates - - Allows team review before applying changes - - Preserves all `[CUSTOMIZE]` sections automatically - - Tracks version history in issues +### Primary Method: Issue-Based Automation (Recommended) -### Option B: Direct Editor Integration - -**Best for**: Quick updates during development - -1. **Prompt GitHub Copilot for smart merging** - In your editor, use this prompt: - ``` - "Merge the ioBroker template from https://github.com/DrozmotiX/ioBroker-Copilot-Instructions/blob/main/template.md - with my existing .github/copilot-instructions.md. Preserve all [CUSTOMIZE] sections and project-specific - context while adding the latest ioBroker best practices. Update the version to the latest available." - ``` +**Best for**: Both initial setup and ongoing maintenance -2. **For comprehensive automation**: Use the full template from [`templates/automated-template-update.md`](../templates/automated-template-update.md) +1. **For Initial Setup or Updates** + - Use the [Initial Setup Automation Template](../templates/initial-setup-automation.md) + - Creates comprehensive setup with validation and monitoring + - Handles both new installations and updates automatically + - Preserves all custom content during updates -### Step 1: Prepare for Template Integration +2. **For Quick Updates Only** + - Use the [Copy-Paste Template](../templates/copy-paste-template.md) for existing setups + - Focuses specifically on template merging + - Ideal when you just need to update an existing template -1. **Ensure version tracking in your repository** - Your `.github/copilot-instructions.md` should include: - ```markdown - **Version:** [current-version] - **Template Source:** https://github.com/DrozmotiX/ioBroker-Copilot-Instructions - **Custom Sections:** [Preserve during updates] - ``` +### Automated Benefits -2. **Identify your custom sections** - - Mark any project-specific instructions with `[CUSTOMIZE]` tags - - These will be preserved during template updates +โœ… **Zero Manual Steps**: No curl commands, sed operations, or file manipulation +๐Ÿ›ก๏ธ **Safe Updates**: All [CUSTOMIZE] sections automatically preserved +๐Ÿ“… **Continuous Monitoring**: Weekly checks via GitHub Actions +๐ŸŽฏ **Adapter-Specific**: Automatically customized for your specific adapter +๐Ÿ”„ **Future-Proof**: Automatically handles new template versions +๐Ÿ“‹ **Audit Trail**: All changes tracked through GitHub issues -### Step 2: Automated Template Merging +### Alternative: Direct Editor Integration -**Use GitHub Copilot to intelligently merge templates** - This preserves your custom content and maintains version control. +**For Advanced Users**: If you prefer working directly in your editor instead of using issues: -1. **Prompt GitHub Copilot for smart merging** - In your editor, use this prompt: +1. **Use the comprehensive automation template** + Copy the full template from [`templates/automated-template-update.md`](../templates/automated-template-update.md) + +2. **Or use this quick prompt in your editor**: ``` "Merge the ioBroker template from https://github.com/DrozmotiX/ioBroker-Copilot-Instructions/blob/main/template.md with my existing .github/copilot-instructions.md. Preserve all [CUSTOMIZE] sections and project-specific context while adding the latest ioBroker best practices. Update the version to the latest available." ``` -2. **Verify version tracking** - Ensure your updated file includes: - - Current template version (latest available) - - Template source reference - - Your custom sections intact - - Project-specific context preserved +### Weekly Monitoring Setup -3. **Commit with version control** - ```bash - git add .github/copilot-instructions.md - git commit -m "Update Copilot instructions to latest template version, preserve custom sections" - ``` - -### Step 3: Custom Section Management - -**Keep customizations safe** - Always use the custom section approach: +The [Initial Setup Automation Template](../templates/initial-setup-automation.md) automatically creates a GitHub Action that: +- ๐Ÿ“… Runs weekly to check for template updates +- ๐ŸŽฏ Creates issues when updates are available +- ๐Ÿ›ก๏ธ Never overwrites existing custom content +- ๐Ÿ” Prevents duplicate issues from being created -1. **Structure your custom content** - ```markdown - ## [CUSTOMIZE] Project-Specific Instructions - - ### My Adapter Specific Patterns - - Custom patterns for your adapter - - Project-specific error handling - - Unique API integrations - - **Note:** This section is preserved during template updates - ``` - -2. **Version validation** - Use the version check script to ensure you're up-to-date: - ```bash - curl -s https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/scripts/check-template-version.sh | bash - ``` +**Manual GitHub Action Setup**: If you want to add monitoring to an existing setup without using the full automation template, copy [`templates/weekly-version-check-action.yml`](../templates/weekly-version-check-action.yml) to `.github/workflows/check-copilot-template.yml` in your repository. ## Advanced: IDE Setup diff --git a/templates/README.md b/templates/README.md index 1de529d..db1f94b 100644 --- a/templates/README.md +++ b/templates/README.md @@ -1,3 +1,70 @@ -# Issue Templates +# Issue Templates and Automation -This directory contains templates that can be used to create automated GitHub issues for template validation and updates. \ No newline at end of file +This directory contains templates and automation files for setting up and maintaining ioBroker Copilot instructions. + +## Templates + +### ๐Ÿš€ [initial-setup-automation.md](initial-setup-automation.md) +**Primary template for all new repositories and comprehensive updates** + +- โœ… Validates if GitHub Copilot is already setup +- ๐Ÿ” Detects existing copilot-instructions.md files +- ๐Ÿ“ฅ Automatically downloads and customizes latest template +- โš™๏ธ Sets up weekly monitoring via GitHub Actions +- ๐Ÿ›ก๏ธ Preserves custom content during updates +- ๐ŸŽฏ Adds adapter-specific customizations + +**Use this for**: New repositories or when you want full automation including monitoring + +### ๐Ÿ“‹ [copy-paste-template.md](copy-paste-template.md) +**Quick update template for existing setups** + +- ๐Ÿ”„ Focuses on template merging only +- ๐Ÿ›ก๏ธ Preserves [CUSTOMIZE] sections +- โšก Fast update process + +**Use this for**: Quick updates when you already have monitoring setup + +### ๐Ÿ”ง [automated-template-update.md](automated-template-update.md) +**Comprehensive update template with detailed validation** + +- ๐Ÿ“Š Includes detailed analysis steps +- ๐Ÿ” Comprehensive validation requirements +- ๐Ÿ“‹ Detailed deliverables checklist + +**Use this for**: Complex updates or when you need detailed change tracking + +## Automation Files + +### ๐Ÿค– [weekly-version-check-action.yml](weekly-version-check-action.yml) +**GitHub Action for automated monitoring** + +- ๐Ÿ“… Weekly template version checking +- ๐ŸŽฏ Automatic issue creation when updates are available +- ๐Ÿšซ Prevents duplicate issues +- ๐Ÿ›ก๏ธ Safe update process with preservation of custom content + +**Use this**: Copy to `.github/workflows/check-copilot-template.yml` in your repository for weekly monitoring + +## Usage Recommendations + +### For New Repositories +1. Use [initial-setup-automation.md](initial-setup-automation.md) +2. Create an issue with the template content +3. Let GitHub Copilot handle everything automatically + +### For Existing Repositories +1. **With monitoring needed**: Use [initial-setup-automation.md](initial-setup-automation.md) +2. **Quick updates only**: Use [copy-paste-template.md](copy-paste-template.md) +3. **Complex updates**: Use [automated-template-update.md](automated-template-update.md) + +### For Manual GitHub Action Setup +Copy [weekly-version-check-action.yml](weekly-version-check-action.yml) to `.github/workflows/check-copilot-template.yml` + +## Benefits of Automation + +- ๐Ÿ• **Zero Manual Steps**: No curl, sed, or file manipulation required +- ๐Ÿ›ก๏ธ **Safety**: Custom content always preserved +- ๐Ÿ“… **Maintenance**: Automatic weekly update checks +- ๐ŸŽฏ **Customization**: Adapter-specific content added automatically +- ๐Ÿ“‹ **Tracking**: Full audit trail through GitHub issues \ No newline at end of file diff --git a/templates/automated-template-update.md b/templates/automated-template-update.md index 3469214..5df41f8 100644 --- a/templates/automated-template-update.md +++ b/templates/automated-template-update.md @@ -44,6 +44,8 @@ CRITICAL REQUIREMENTS: 4. Update the version number to match the latest template version 5. Keep the Template Source reference up-to-date 6. Ensure no custom content is lost during the merge +7. REMOVE any duplicate content from [CUSTOMIZE] sections that already exists in the standard template +8. Keep only truly unique, adapter-specific content in [CUSTOMIZE] sections Show me what changes will be made before applying them." ``` @@ -57,6 +59,7 @@ Show me what changes will be made before applying them." - [ ] **Project context maintained** - Adapter-specific instructions are preserved - [ ] **Template completeness** - All standard sections are present and up-to-date - [ ] **Syntax validation** - Markdown formatting is correct +- [ ] **No duplicates** - [CUSTOMIZE] sections contain only unique content not found in standard template ## ๐Ÿ“‹ Expected Deliverables diff --git a/templates/copy-paste-template.md b/templates/copy-paste-template.md index 7632659..557b160 100644 --- a/templates/copy-paste-template.md +++ b/templates/copy-paste-template.md @@ -25,6 +25,8 @@ REQUIREMENTS: 3. Add latest ioBroker best practices from the new template 4. Update version to match latest template version 5. Maintain Template Source reference +6. REMOVE any duplicate content from [CUSTOMIZE] sections that already exists in the standard template +7. Keep only truly unique, adapter-specific content in [CUSTOMIZE] sections Show me the changes before applying them." ``` @@ -35,6 +37,7 @@ After update, confirm: - [ ] Version updated to latest - [ ] Custom content intact - [ ] Template structure complete +- [ ] No duplicate content between [CUSTOMIZE] sections and standard template **Reference**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions ``` diff --git a/templates/initial-setup-automation.md b/templates/initial-setup-automation.md new file mode 100644 index 0000000..3908ef3 --- /dev/null +++ b/templates/initial-setup-automation.md @@ -0,0 +1,295 @@ +--- +name: Initial ioBroker Copilot Setup +about: Automated setup and validation of GitHub Copilot instructions for ioBroker adapters +title: "๐Ÿค– Setup ioBroker GitHub Copilot Instructions" +labels: ["copilot-setup", "automation"] +assignees: [] +--- + +# ๐Ÿค– Automated ioBroker Copilot Instructions Setup + +**GitHub Copilot**: Please help me set up GitHub Copilot instructions for my ioBroker adapter repository with full automation and validation. + +## ๐Ÿ” Step 1: Current State Analysis + +**GitHub Copilot**: Please analyze my repository and check: + +1. **Copilot Status Check** + - [ ] Verify if GitHub Copilot is active and responding in this repository + - [ ] Check if `.github/copilot-instructions.md` already exists + - [ ] Analyze existing content if present + +2. **Repository Context Assessment** + - [ ] Identify this as an ioBroker adapter repository + - [ ] Detect adapter name and specific patterns + - [ ] Find existing custom configuration or setup + +## ๐ŸŽฏ Step 2: Setup Requirements + +**GitHub Copilot**: Based on your analysis, please: + +### If Copilot Instructions DON'T Exist: +Create a complete `.github/copilot-instructions.md` file by: + +1. **Download and integrate the latest template**: + ``` + Fetch the ioBroker Copilot template from: + https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md + + Then create .github/copilot-instructions.md with: + - Remove the template comment block (lines starting with ) + - Add current date and latest version information + - Customize [CUSTOMIZE] sections with adapter-specific context + - Include Template Source reference + ``` + +2. **Add adapter-specific context**: + ``` + In the [CUSTOMIZE] Project-Specific Instructions section, add ONLY content that is: + - This adapter's specific API patterns NOT covered by standard ioBroker patterns + - Unique authentication or connection handling specific to your service + - Custom error codes specific to this service (not generic ioBroker error handling) + - Adapter-specific device discovery patterns unique to your implementation + + IMPORTANT: Do NOT duplicate content that already exists in the standard template. + Only add truly unique patterns specific to your adapter's service/API. + + Examples of what NOT to include (already covered by template): + - General ioBroker testing patterns (use @iobroker/testing) + - Standard error handling (this.log.error, try/catch) + - Common state management (this.setState, this.getState) + - Standard adapter lifecycle methods + - Generic dependency management advice + ``` + +3. **Template Duplicate Prevention**: + ``` + When GitHub Copilot creates your template, it should: + - Review [CUSTOMIZE] sections against the standard template + - Remove any content that duplicates standard ioBroker patterns + - Keep only truly adapter-specific content that adds unique value + - Ensure [CUSTOMIZE] sections complement, not repeat, standard guidance + ``` + +### If Copilot Instructions DO Exist: +Update the existing file using the merge process: + +``` +"Merge the ioBroker template from https://github.com/DrozmotiX/ioBroker-Copilot-Instructions/blob/main/template.md with my existing .github/copilot-instructions.md. + +CRITICAL REQUIREMENTS: +1. Preserve ALL [CUSTOMIZE] sections and their content exactly as they are +2. Maintain any project-specific context not already covered in the template +3. Add the latest ioBroker best practices from the new template +4. Update the version number to match the latest template version +5. Keep the Template Source reference up-to-date +6. Ensure no custom content is lost during the merge +7. REMOVE any duplicate content from [CUSTOMIZE] sections that already exists in the standard template +8. Keep only truly unique, adapter-specific content in [CUSTOMIZE] sections + +Show me the changes before applying them." +``` + +## ๐Ÿ”ง Step 3: Automation Setup + +**GitHub Copilot**: Please also set up automated template monitoring: + +### Create GitHub Action for Weekly Monitoring + +Create `.github/workflows/check-copilot-template.yml` with this content: + +```yaml +name: Check ioBroker Copilot Template Version + +on: + schedule: + - cron: '0 0 * * 0' # Weekly check every Sunday + workflow_dispatch: # Allow manual triggering + +jobs: + check-template: + runs-on: ubuntu-latest + permissions: + issues: write + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check template version + id: version-check + run: | + # Get current version from local template + if [ -f ".github/copilot-instructions.md" ]; then + CURRENT_VERSION=$(grep "Version:" .github/copilot-instructions.md | head -1 | sed 's/.*Version:\s*//' | tr -d '*' | xargs) + else + CURRENT_VERSION="none" + fi + + # Get latest version from remote + LATEST_VERSION=$(curl -s https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md | grep "Version:" | head -1 | sed 's/.*Version:\s*//' | tr -d '*' | xargs) + + echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + echo "latest-version=$LATEST_VERSION" >> $GITHUB_OUTPUT + + if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ] || [ "$CURRENT_VERSION" = "none" ]; then + echo "update-needed=true" >> $GITHUB_OUTPUT + else + echo "update-needed=false" >> $GITHUB_OUTPUT + fi + + - name: Check for existing template update issue + id: check-issue + if: steps.version-check.outputs.update-needed == 'true' + uses: actions/github-script@v7 + with: + script: | + const { data: issues } = await github.rest.issues.listForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + labels: 'template-update,automation' + }); + + const existingIssue = issues.find(issue => + issue.title.includes('๐Ÿค– Update ioBroker Copilot Instructions Template') || + issue.title.includes('๐Ÿค– Setup ioBroker GitHub Copilot Instructions') + ); + + return existingIssue ? existingIssue.number : null; + + - name: Create template update issue + if: steps.version-check.outputs.update-needed == 'true' && !steps.check-issue.outputs.result + uses: actions/github-script@v7 + with: + script: | + const currentVersion = '${{ steps.version-check.outputs.current-version }}'; + const latestVersion = '${{ steps.version-check.outputs.latest-version }}'; + + let title, body; + + if (currentVersion === 'none') { + title = '๐Ÿค– Setup ioBroker GitHub Copilot Instructions'; + body = `# ๐Ÿค– Automated ioBroker Copilot Instructions Setup + +**Automated Detection**: This repository doesn't have GitHub Copilot instructions set up yet. + +**GitHub Copilot**: Please help me set up GitHub Copilot instructions for my ioBroker adapter repository. + +## ๐ŸŽฏ Setup Task + +Please create a complete \`.github/copilot-instructions.md\` file by downloading and customizing the latest ioBroker template: + +**Template Source**: https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md +**Latest Version**: ${latestVersion} + +### Requirements: +1. Download the template and remove the comment block +2. Customize [CUSTOMIZE] sections with this adapter's specific patterns +3. Include proper version tracking and template source reference +4. Add adapter-specific context for enhanced Copilot suggestions + +## ๐Ÿ”ง Validation +After setup, please confirm: +- [ ] File created at \`.github/copilot-instructions.md\` +- [ ] Version set to ${latestVersion} +- [ ] [CUSTOMIZE] sections populated with adapter-specific content +- [ ] Template source reference included + +**Reference**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions + +--- +*This issue was automatically created by GitHub Actions*`; + } else { + title = '๐Ÿค– Update ioBroker Copilot Instructions Template'; + body = `# ๐Ÿค– Template Update Available + +**Automated Detection**: Your ioBroker Copilot instructions template is outdated. + +- **Current Version**: ${currentVersion} +- **Latest Version**: ${latestVersion} + +**GitHub Copilot**: Please help me update my template while preserving all custom sections. + +## ๐ŸŽฏ Update Task + +Please use this merge prompt: + +\`\`\` +"Merge the ioBroker template from https://github.com/DrozmotiX/ioBroker-Copilot-Instructions/blob/main/template.md with my existing .github/copilot-instructions.md. + +CRITICAL REQUIREMENTS: +1. Preserve ALL [CUSTOMIZE] sections and their content exactly as they are +2. Maintain any project-specific context not already covered in the template +3. Add the latest ioBroker best practices from the new template +4. Update the version number to ${latestVersion} +5. Keep the Template Source reference up-to-date +6. Ensure no custom content is lost during the merge +7. REMOVE any duplicate content from [CUSTOMIZE] sections that already exists in the standard template +8. Keep only truly unique, adapter-specific content in [CUSTOMIZE] sections + +Show me the changes before applying them." +\`\`\` + +## ๐Ÿ”ง Validation +After update, please confirm: +- [ ] All [CUSTOMIZE] sections preserved +- [ ] Version updated to ${latestVersion} +- [ ] Custom content intact +- [ ] New best practices integrated + +**Reference**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions + +--- +*This issue was automatically created by GitHub Actions*`; + } + + await github.rest.issues.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: title, + body: body, + labels: ['template-update', 'automation'] + }); +``` + +## ๐Ÿ“‹ Step 4: Validation and Testing + +**GitHub Copilot**: After completing the setup, please verify: + +### Setup Validation +- [ ] **File created/updated**: `.github/copilot-instructions.md` exists and is properly formatted +- [ ] **Version tracking**: Latest version number is present +- [ ] **Template source**: Reference to source repository included +- [ ] **Custom sections**: [CUSTOMIZE] areas populated with adapter-specific content +- [ ] **No duplicates**: [CUSTOMIZE] sections contain only unique content not found in standard template + +### GitHub Action Validation +- [ ] **Workflow created**: `.github/workflows/check-copilot-template.yml` exists +- [ ] **Permissions set**: Issues write permission configured +- [ ] **Schedule configured**: Weekly execution setup +- [ ] **Manual trigger**: workflow_dispatch enabled + +### Functionality Testing +Test that enhanced Copilot suggestions work: +1. Open a `.js` or `.ts` file in the adapter +2. Start typing ioBroker-related code (e.g., `this.setState(`) +3. Verify Copilot provides ioBroker-specific suggestions + +## ๐Ÿšจ Critical Success Criteria + +**โœ… COMPLETE WHEN**: +- GitHub Copilot instructions are active and customized for this adapter +- Weekly automated monitoring is configured via GitHub Actions +- All custom content is preserved (if updating existing template) +- Enhanced ioBroker-specific suggestions are working +- No manual file creation or maintenance required going forward + +## ๐Ÿ“š Reference Information + +- **Template Repository**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions +- **Latest Template**: https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md +- **Manual Version Check**: `curl -s https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/scripts/check-template-version.sh | bash` + +**GitHub Copilot**: Please start with the current state analysis and proceed step-by-step through the setup process. Provide detailed feedback on what you're doing at each step. \ No newline at end of file diff --git a/templates/weekly-version-check-action.yml b/templates/weekly-version-check-action.yml new file mode 100644 index 0000000..d54d0c1 --- /dev/null +++ b/templates/weekly-version-check-action.yml @@ -0,0 +1,278 @@ +name: Check ioBroker Copilot Template Version + +on: + schedule: + - cron: '0 0 * * 0' # Weekly check every Sunday at midnight UTC + workflow_dispatch: # Allow manual triggering + +jobs: + check-template: + runs-on: ubuntu-latest + permissions: + issues: write + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check template version + id: version-check + run: | + echo "๐Ÿ” Checking ioBroker Copilot template version..." + + # Get current version from local template + if [ -f ".github/copilot-instructions.md" ]; then + CURRENT_VERSION=$(grep "Version:" .github/copilot-instructions.md | head -1 | sed 's/.*Version:\s*//' | tr -d '*' | xargs) + echo "๐Ÿ“‹ Current version: $CURRENT_VERSION" + else + CURRENT_VERSION="none" + echo "โŒ No copilot-instructions.md file found" + fi + + # Get latest version from remote + echo "๐ŸŒ Fetching latest template version..." + LATEST_VERSION=$(curl -s https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md | grep "Version:" | head -1 | sed 's/.*Version:\s*//' | tr -d '*' | xargs) + echo "๐Ÿ“‹ Latest version: $LATEST_VERSION" + + # Set outputs + echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + echo "latest-version=$LATEST_VERSION" >> $GITHUB_OUTPUT + + if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ] || [ "$CURRENT_VERSION" = "none" ]; then + echo "๐Ÿ†™ Update needed!" + echo "update-needed=true" >> $GITHUB_OUTPUT + else + echo "โœ… Template is up-to-date" + echo "update-needed=false" >> $GITHUB_OUTPUT + fi + + - name: Check for existing template-related issues + id: check-issue + if: steps.version-check.outputs.update-needed == 'true' + uses: actions/github-script@v7 + with: + script: | + console.log('๐Ÿ” Checking for existing template update issues...'); + + const { data: issues } = await github.rest.issues.listForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + per_page: 100 + }); + + // Look for any existing template-related issues + const templateIssues = issues.filter(issue => { + const title = issue.title.toLowerCase(); + const hasLabels = issue.labels.some(label => + label.name === 'template-update' || + label.name === 'automation' || + label.name === 'copilot-setup' + ); + const hasKeywords = title.includes('copilot') && ( + title.includes('template') || + title.includes('setup') || + title.includes('update') + ); + return hasLabels || hasKeywords; + }); + + if (templateIssues.length > 0) { + console.log(`๐Ÿ“‹ Found ${templateIssues.length} existing template-related issue(s):`); + templateIssues.forEach(issue => { + console.log(` - #${issue.number}: ${issue.title}`); + }); + return templateIssues[0].number; + } else { + console.log('โœ… No existing template-related issues found'); + return null; + } + + - name: Create or update template issue + if: steps.version-check.outputs.update-needed == 'true' && !steps.check-issue.outputs.result + uses: actions/github-script@v7 + with: + script: | + const currentVersion = '${{ steps.version-check.outputs.current-version }}'; + const latestVersion = '${{ steps.version-check.outputs.latest-version }}'; + const repoName = context.repo.repo; + + console.log(`๐ŸŽฏ Creating template issue for ${context.repo.owner}/${repoName}`); + console.log(`๐Ÿ“‹ Current: ${currentVersion}, Latest: ${latestVersion}`); + + let title, body, labels; + + if (currentVersion === 'none') { + title = '๐Ÿค– Setup ioBroker GitHub Copilot Instructions'; + labels = ['copilot-setup', 'automation', 'enhancement']; + body = `# ๐Ÿค– Automated ioBroker Copilot Instructions Setup + +**Automated Detection**: This ioBroker adapter repository doesn't have GitHub Copilot instructions configured yet. + +**Latest Available Version**: ${latestVersion} + +## ๐ŸŽฏ What This Sets Up + +GitHub Copilot instructions will enhance your development experience by providing: +- โœจ ioBroker-specific code suggestions +- ๐Ÿ›ก๏ธ Best practices for adapter development +- ๐Ÿงช Enhanced testing patterns with @iobroker/testing +- ๐Ÿ“ Improved README and documentation generation +- ๐Ÿ”ง Smart error handling and state management + +## ๐Ÿš€ Automated Setup Process + +**GitHub Copilot**: Please help me set up GitHub Copilot instructions for my ioBroker adapter repository. + +### Primary Task + +Create a complete \`.github/copilot-instructions.md\` file using this process: + +1. **Download and integrate the latest template**: + \`\`\` + Fetch the ioBroker Copilot template from: + https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md + + Create .github/copilot-instructions.md by: + - Removing the template comment block ( section) + - Setting version to ${latestVersion} + - Adding Template Source reference + - Customizing [CUSTOMIZE] sections for this ${repoName} adapter + \`\`\` + +2. **Adapter-Specific Customization**: + \`\`\` + In the [CUSTOMIZE] Project-Specific Instructions section, please add: + - This ${repoName} adapter's specific API patterns and authentication + - Unique error codes and handling specific to this service + - Custom device discovery or connection patterns + - Any special configuration requirements for this adapter + \`\`\` + +## ๐Ÿ”ง Validation Checklist + +After setup, please confirm: +- [ ] File created at \`.github/copilot-instructions.md\` +- [ ] Version set to \`${latestVersion}\` +- [ ] Template source reference included +- [ ] [CUSTOMIZE] sections populated with ${repoName}-specific patterns +- [ ] Enhanced Copilot suggestions working (test with \`this.setState(\` in a .js file) + +## ๐ŸŽ Next Steps + +Once setup is complete: +1. **Weekly Monitoring**: This action will automatically check for template updates +2. **Preserved Customizations**: All your [CUSTOMIZE] sections will be preserved in future updates +3. **Enhanced Development**: Start coding and experience improved ioBroker-specific suggestions + +## ๐Ÿ“š Reference + +- **Template Repository**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions +- **Full Setup Guide**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions/blob/main/docs/setup.md + +--- +*๐Ÿค– This issue was automatically created by GitHub Actions. The weekly monitoring will continue to check for template updates while preserving all your customizations.*`; + + } else { + title = '๐Ÿค– Update ioBroker Copilot Instructions Template'; + labels = ['template-update', 'automation', 'enhancement']; + body = `# ๐Ÿค– ioBroker Copilot Template Update Available + +**Automated Detection**: Your ioBroker Copilot instructions template has an update available. + +- **Current Version**: \`${currentVersion}\` +- **Latest Version**: \`${latestVersion}\` +- **Repository**: ${context.repo.owner}/${repoName} + +## ๐Ÿš€ Automated Update Process + +**GitHub Copilot**: Please help me update my ioBroker Copilot template while preserving all customizations. + +### Template Update Task + +Use this exact merge prompt: + +\`\`\` +"Update my .github/copilot-instructions.md by merging the latest ioBroker template from: +https://github.com/DrozmotiX/ioBroker-Copilot-Instructions/blob/main/template.md + +CRITICAL PRESERVATION REQUIREMENTS: +1. Keep ALL [CUSTOMIZE] sections and their content exactly as they are +2. Preserve any ${repoName}-specific context not covered by the standard template +3. Maintain custom error handling, API patterns, or authentication flows +4. Keep any unique testing scenarios or configuration instructions +5. REMOVE any duplicate content from [CUSTOMIZE] sections that already exists in the standard template +6. Keep only truly unique, adapter-specific content in [CUSTOMIZE] sections + +UPDATE REQUIREMENTS: +1. Integrate latest ioBroker best practices from the new template +2. Update version number to ${latestVersion} +3. Refresh Template Source reference +4. Add any new standard sections that are missing +5. Clean up [CUSTOMIZE] sections to avoid duplicating standard template content + +Show me a summary of what will be changed before applying the update." +\`\`\` + +## ๐Ÿ” What's New in ${latestVersion} + +Recent template improvements typically include: +- ๐Ÿงช Enhanced testing patterns and best practices +- ๐Ÿ›ก๏ธ Improved error handling recommendations +- ๐Ÿ“ Better documentation generation patterns +- ๐Ÿ”ง Updated dependency management guidance +- โšก Performance optimization suggestions + +## ๐Ÿ”ง Validation Checklist + +After the update, please confirm: +- [ ] All [CUSTOMIZE] sections preserved exactly as they were +- [ ] Version updated to \`${latestVersion}\` +- [ ] Custom ${repoName}-specific content intact +- [ ] New best practices integrated without conflicts +- [ ] Template source reference updated +- [ ] Enhanced suggestions still working (test in your code editor) +- [ ] No duplicate content between [CUSTOMIZE] sections and standard template + +## ๐Ÿ›ก๏ธ Safety Features + +This automated update process: +- โœ… **Preserves Customizations**: All [CUSTOMIZE] sections are automatically maintained +- ๐Ÿ”’ **No Data Loss**: Your adapter-specific patterns and configurations remain intact +- ๐Ÿ“‹ **Audit Trail**: All changes are tracked in this issue for review +- ๐Ÿ”„ **Reversible**: You can always revert changes if needed + +## ๐Ÿ“š Reference + +- **Template Repository**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions +- **Template Source**: https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md +- **Update Guide**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions/blob/main/docs/automated-updates.md + +--- +*๐Ÿค– This issue was automatically created by GitHub Actions on ${new Date().toISOString().split('T')[0]}. Weekly monitoring will continue to check for updates while preserving your customizations.*`; + } + + const issue = await github.rest.issues.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: title, + body: body, + labels: labels + }); + + console.log(`โœ… Created issue #${issue.data.number}: ${title}`); + + return issue.data.number; + + - name: Log completion + if: steps.version-check.outputs.update-needed == 'false' + run: | + echo "โœ… Template check completed - no updates needed" + echo "๐Ÿ“‹ Current version ${{ steps.version-check.outputs.current-version }} is up-to-date" + + - name: Log issue creation + if: steps.version-check.outputs.update-needed == 'true' && steps.check-issue.outputs.result + run: | + echo "โ„น๏ธ Template update needed, but found existing issue #${{ steps.check-issue.outputs.result }}" + echo "๐Ÿ“‹ Current: ${{ steps.version-check.outputs.current-version }}, Latest: ${{ steps.version-check.outputs.latest-version }}" \ No newline at end of file diff --git a/tests/test-automated-templates.sh b/tests/test-automated-templates.sh index 84eba71..e7af0ff 100755 --- a/tests/test-automated-templates.sh +++ b/tests/test-automated-templates.sh @@ -102,14 +102,14 @@ fi # Test README.md updates if [[ -f "$REPO_ROOT/README.md" ]]; then - test_template_content "$REPO_ROOT/README.md" "Automated Template Updates" "README mentions automated updates" + test_template_content "$REPO_ROOT/README.md" "Automated Template Management" "README mentions automated updates" test_template_content "$REPO_ROOT/README.md" "copy-paste-template.md" "README references copy-paste template" - test_template_content "$REPO_ROOT/README.md" "templates/automated-template-update.md" "README references automated template" + test_template_content "$REPO_ROOT/README.md" "templates/initial-setup-automation.md" "README references automated template" fi # Test setup.md updates if [[ -f "$REPO_ROOT/docs/setup.md" ]]; then - test_template_content "$REPO_ROOT/docs/setup.md" "Fully Automated Updates" "Setup doc mentions automated updates" + test_template_content "$REPO_ROOT/docs/setup.md" "Fully Automated Process" "Setup doc mentions automated updates" test_template_content "$REPO_ROOT/docs/setup.md" "copy-paste-template.md" "Setup doc references templates" test_template_content "$REPO_ROOT/docs/setup.md" "CUSTOMIZE" "Setup doc preserves CUSTOMIZE sections" fi diff --git a/tests/test-check-template-version.sh b/tests/test-check-template-version.sh index 7735e89..2caf013 100755 --- a/tests/test-check-template-version.sh +++ b/tests/test-check-template-version.sh @@ -3,35 +3,91 @@ # Tests for check-template-version.sh script # +set -e + +# Color output for better readability +RED='\033[0;31m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Test configuration +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(dirname "$SCRIPT_DIR")" + +# Test helper functions +run_test_with_output() { + local test_name="$1" + local test_command="$2" + local expected_pattern="$3" + + printf " Testing %s... " "$test_name" + + if eval "$test_command" | grep -q "$expected_pattern"; then + echo -e "${GREEN}โœ… PASS${NC}" + return 0 + else + echo -e "${RED}โŒ FAIL${NC}" + return 1 + fi +} + +run_test() { + local test_name="$1" + local test_command="$2" + + printf " Testing %s... " "$test_name" + + if eval "$test_command" >/dev/null 2>&1; then + echo -e "${GREEN}โœ… PASS${NC}" + return 0 + else + echo -e "${RED}โŒ FAIL${NC}" + return 1 + fi +} + +print_test_result() { + local test_name="$1" + local result="$2" + + if [[ "$result" == "PASS" ]]; then + echo -e " ${GREEN}โœ… PASS${NC} $test_name" + else + echo -e " ${RED}โŒ FAIL${NC} $test_name" + fi +} + echo -e "${BLUE}Testing check-template-version.sh${NC}" # Test successful version check with existing template run_test_with_output \ "Check template version runs successfully" \ - "$TEST_DIR/scripts/check-template-version.sh" \ + "$REPO_ROOT/scripts/check-template-version.sh" \ "๐Ÿ” Checking ioBroker Copilot template version" # Test version extraction from local template run_test_with_output \ "Local version extraction works" \ - "$TEST_DIR/scripts/check-template-version.sh" \ + "$REPO_ROOT/scripts/check-template-version.sh" \ "๐Ÿ“„ Local template version:" # Test remote version check (may fail in CI due to network) run_test_with_output \ "Remote version check attempts" \ - "$TEST_DIR/scripts/check-template-version.sh" \ + "$REPO_ROOT/scripts/check-template-version.sh" \ "๐ŸŒ Checking remote template version" # Test completion message run_test_with_output \ "Check completion message" \ - "$TEST_DIR/scripts/check-template-version.sh" \ + "$REPO_ROOT/scripts/check-template-version.sh" \ "๐Ÿ Template check complete" # Test missing local template handling test_missing_template() { - cd "$TEST_DIR" + cd "$REPO_ROOT" mv .github/copilot-instructions.md .github/copilot-instructions.md.bak 2>/dev/null || true local result=0 @@ -51,7 +107,7 @@ run_test \ # Test template without version (malformed) test_malformed_template() { - cd "$TEST_DIR" + cd "$REPO_ROOT" # Backup original and create malformed version cp .github/copilot-instructions.md .github/copilot-instructions.md.bak @@ -74,7 +130,7 @@ run_test \ "$(declare -f test_malformed_template); test_malformed_template" # Test URL configuration -local_template_path="$TEST_DIR/.github/copilot-instructions.md" +local_template_path="$REPO_ROOT/.github/copilot-instructions.md" if [[ -f "$local_template_path" ]]; then print_test_result "Local template file exists" "PASS" else @@ -82,14 +138,14 @@ else fi # Test script contains correct remote URL -if grep -q "https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md" "$TEST_DIR/scripts/check-template-version.sh"; then +if grep -q "https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md" "$REPO_ROOT/scripts/check-template-version.sh"; then print_test_result "Correct remote URL configured" "PASS" else print_test_result "Correct remote URL configured" "FAIL" "Remote URL not found or incorrect" fi # Test script is executable -if [[ -x "$TEST_DIR/scripts/check-template-version.sh" ]]; then +if [[ -x "$REPO_ROOT/scripts/check-template-version.sh" ]]; then print_test_result "Script is executable" "PASS" else print_test_result "Script is executable" "FAIL" "Script is not executable" @@ -97,7 +153,7 @@ fi # Test curl command handling (simulate network failure) test_network_failure() { - cd "$TEST_DIR" + cd "$REPO_ROOT" # Create a modified script with invalid URL to simulate network failure cp scripts/check-template-version.sh scripts/check-template-version-test.sh @@ -121,7 +177,7 @@ run_test \ # Test update guidance is provided for outdated templates test_update_guidance() { - cd "$TEST_DIR" + cd "$REPO_ROOT" # Backup original and create outdated version cp .github/copilot-instructions.md .github/copilot-instructions.md.bak diff --git a/tests/test-extract-version.sh b/tests/test-extract-version.sh index 32c8d61..ef0ddfe 100755 --- a/tests/test-extract-version.sh +++ b/tests/test-extract-version.sh @@ -3,6 +3,62 @@ # Tests for extract-version.sh script # +set -e + +# Color output for better readability +RED='\033[0;31m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Test configuration +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(dirname "$SCRIPT_DIR")" + +# Test helper functions +run_test_with_output() { + local test_name="$1" + local test_command="$2" + local expected_pattern="$3" + + printf " Testing %s... " "$test_name" + + if eval "$test_command" | grep -q "$expected_pattern"; then + echo -e "${GREEN}โœ… PASS${NC}" + return 0 + else + echo -e "${RED}โŒ FAIL${NC}" + return 1 + fi +} + +run_test() { + local test_name="$1" + local test_command="$2" + + printf " Testing %s... " "$test_name" + + if eval "$test_command" >/dev/null 2>&1; then + echo -e "${GREEN}โœ… PASS${NC}" + return 0 + else + echo -e "${RED}โŒ FAIL${NC}" + return 1 + fi +} + +print_test_result() { + local test_name="$1" + local result="$2" + + if [[ "$result" == "PASS" ]]; then + echo -e " ${GREEN}โœ… PASS${NC} $test_name" + else + echo -e " ${RED}โŒ FAIL${NC} $test_name" + fi +} + # Test extract-version.sh functionality echo -e "${BLUE}Testing extract-version.sh${NC}" @@ -10,54 +66,54 @@ echo -e "${BLUE}Testing extract-version.sh${NC}" # Test template version extraction run_test_with_output \ "Extract template version" \ - "$TEST_DIR/scripts/extract-version.sh template" \ - "^[0-9]+\.[0-9]+\.[0-9]+$" + "$REPO_ROOT/scripts/extract-version.sh template" \ + "0.4.0" # Test current year extraction run_test_with_output \ "Extract current year" \ - "$TEST_DIR/scripts/extract-version.sh current-year" \ - "^[0-9]{4}$" + "$REPO_ROOT/scripts/extract-version.sh current-year" \ + "202" # Test current month extraction run_test_with_output \ "Extract current month" \ - "$TEST_DIR/scripts/extract-version.sh current-month" \ - "^[A-Za-z]+$" + "$REPO_ROOT/scripts/extract-version.sh current-month" \ + "[A-Za-z]" # Test current date extraction run_test_with_output \ "Extract current date" \ - "$TEST_DIR/scripts/extract-version.sh current-date" \ + "$REPO_ROOT/scripts/extract-version.sh current-date" \ "^[A-Za-z]+ [0-9]{4}$" # Test default parameter (should extract template version) run_test_with_output \ "Default parameter extracts template version" \ - "$TEST_DIR/scripts/extract-version.sh" \ + "$REPO_ROOT/scripts/extract-version.sh" \ "^[0-9]+\.[0-9]+\.[0-9]+$" # Test invalid parameter run_test_with_output \ "Invalid parameter shows usage and exits with code 1" \ - "$TEST_DIR/scripts/extract-version.sh invalid-param" \ + "$REPO_ROOT/scripts/extract-version.sh invalid-param" \ "Usage:" \ 1 # Test with missing template file run_test \ "Missing template file returns 'unknown'" \ - "cd '$TEST_DIR' && mv template.md template.md.bak && ./scripts/extract-version.sh template && mv template.md.bak template.md" \ + "cd '$REPO_ROOT' && mv template.md template.md.bak && ./scripts/extract-version.sh template && mv template.md.bak template.md" \ 0 # Verify the "unknown" output when template is missing run_test_with_output \ "Missing template file outputs 'unknown'" \ - "cd '$TEST_DIR' && mv template.md template.md.bak && ./scripts/extract-version.sh template; mv template.md.bak template.md" \ + "cd '$REPO_ROOT' && mv template.md template.md.bak && ./scripts/extract-version.sh template; mv template.md.bak template.md" \ "unknown" # Test script is executable -if [[ -x "$TEST_DIR/scripts/extract-version.sh" ]]; then +if [[ -x "$REPO_ROOT/scripts/extract-version.sh" ]]; then print_test_result "Script is executable" "PASS" else print_test_result "Script is executable" "FAIL" "Script is not executable" diff --git a/tests/test-initial-setup-automation.sh b/tests/test-initial-setup-automation.sh new file mode 100755 index 0000000..c8a79a9 --- /dev/null +++ b/tests/test-initial-setup-automation.sh @@ -0,0 +1,179 @@ +#!/bin/bash + +# Test script for automated setup templates +# Tests the new initial-setup-automation.md and related templates + +set -e + +# Color output for better readability +RED='\033[0;31m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Test configuration +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(dirname "$SCRIPT_DIR")" + +echo -e "${BLUE}Testing Automated Setup Templates${NC}" + +# Test helper function +run_test_with_output() { + local test_name="$1" + local test_command="$2" + local expected_pattern="$3" + + printf " Testing %s... " "$test_name" + + if eval "$test_command" | grep -q "$expected_pattern"; then + echo -e "${GREEN}โœ… PASS${NC}" + return 0 + else + echo -e "${RED}โŒ FAIL${NC}" + return 1 + fi +} + +# Test file existence +run_test_with_output "Initial setup automation template exists" \ + "ls '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "initial-setup-automation.md" + +run_test_with_output "Weekly version check action exists" \ + "ls '$REPO_ROOT/templates/weekly-version-check-action.yml'" \ + "weekly-version-check-action.yml" + +# Test template content requirements +run_test_with_output "Initial setup template validates existing Copilot setup" \ + "grep -i 'Copilot Status Check' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "Copilot Status Check" + +run_test_with_output "Initial setup template handles missing instructions" \ + "grep -i 'If Copilot Instructions DON.*T Exist' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "If Copilot Instructions DON" + +run_test_with_output "Initial setup template handles existing instructions" \ + "grep -i 'If Copilot Instructions DO Exist' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "If Copilot Instructions DO Exist" + +run_test_with_output "Initial setup template includes GitHub Action setup" \ + "grep -i 'Create GitHub Action for Weekly Monitoring' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "Create GitHub Action for Weekly Monitoring" + +run_test_with_output "Initial setup template includes automation setup" \ + "grep -i 'check-copilot-template.yml' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "check-copilot-template.yml" + +# Test GitHub Action content +run_test_with_output "GitHub Action has weekly schedule" \ + "grep -i 'cron.*0 0 \* \* 0' '$REPO_ROOT/templates/weekly-version-check-action.yml'" \ + "cron" + +run_test_with_output "GitHub Action has manual trigger" \ + "grep -i 'workflow_dispatch' '$REPO_ROOT/templates/weekly-version-check-action.yml'" \ + "workflow_dispatch" + +run_test_with_output "GitHub Action checks for existing issues" \ + "grep -i 'check-issue' '$REPO_ROOT/templates/weekly-version-check-action.yml'" \ + "check-issue" + +run_test_with_output "GitHub Action creates issues automatically" \ + "grep -i 'Create.*issue' '$REPO_ROOT/templates/weekly-version-check-action.yml'" \ + "Create" + +run_test_with_output "GitHub Action prevents duplicate issues" \ + "grep -i 'existing.*issue' '$REPO_ROOT/templates/weekly-version-check-action.yml'" \ + "existing" + +# Test integration requirements +run_test_with_output "Initial setup template includes validation steps" \ + "grep -i 'Validation and Testing' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "Validation and Testing" + +run_test_with_output "Initial setup template includes success criteria" \ + "grep -i 'Critical Success Criteria' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "Critical Success Criteria" + +run_test_with_output "Initial setup template references preservation" \ + "grep -i 'preserve.*CUSTOMIZE.*sections' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "CUSTOMIZE.*sections" + +run_test_with_output "Initial setup template includes template source reference" \ + "grep -i 'Template.*Source.*github' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "Template.*Source" + +# Test documentation updates +run_test_with_output "Setup.md references initial setup automation" \ + "grep -i 'initial-setup-automation.md' '$REPO_ROOT/docs/setup.md'" \ + "initial-setup-automation" + +run_test_with_output "Setup.md emphasizes automation over manual steps" \ + "grep -i 'Fully Automated Process' '$REPO_ROOT/docs/setup.md'" \ + "Fully Automated Process" + +run_test_with_output "README.md mentions automated setup" \ + "grep -i 'Fully Automated Setup' '$REPO_ROOT/README.md'" \ + "Fully Automated Setup" + +run_test_with_output "Templates README documents new templates" \ + "grep -i 'initial-setup-automation.md' '$REPO_ROOT/templates/README.md'" \ + "initial-setup-automation" + +# Test automation completeness +run_test_with_output "Initial setup handles both new and existing repositories" \ + "grep -i 'If Copilot Instructions.*Exist' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "If Copilot Instructions" + +run_test_with_output "GitHub Action handles both setup and updates" \ + "grep -i 'Setup ioBroker.*Copilot.*Instructions\|Update.*Copilot.*Instructions.*Template' '$REPO_ROOT/templates/weekly-version-check-action.yml'" \ + "Setup.*Copilot" + +# Test issue requirements adherence +run_test_with_output "Template validates if Copilot is setup (requirement 1)" \ + "grep -i 'Verify if GitHub Copilot is active' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "Verify if GitHub Copilot is active" + +run_test_with_output "Template initiates copilot instructions automatically (requirement 2)" \ + "grep -i 'create.*complete.*copilot-instructions.md' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "copilot-instructions.md" + +run_test_with_output "Template includes GitHub Action for weekly checks (requirement 3a)" \ + "grep -i 'Weekly.*check' '$REPO_ROOT/templates/weekly-version-check-action.yml'" \ + "Weekly" + +run_test_with_output "Template prevents duplicate issues (requirement 3b)" \ + "grep -i 'existing.*issue' '$REPO_ROOT/templates/weekly-version-check-action.yml'" \ + "existing.*issue" + +# Test removal of manual references (requirement 4) +run_test_with_output "Setup.md emphasizes automation over manual" \ + "grep -c -i 'curl.*sed.*manual' '$REPO_ROOT/docs/setup.md'" \ + "0" + +run_test_with_output "README.md emphasizes zero manual steps" \ + "grep -i 'Zero Manual Steps' '$REPO_ROOT/README.md'" \ + "Zero Manual Steps" + +# Test duplicate prevention guidance (addressing comment feedback) +run_test_with_output "Initial setup template includes duplicate prevention guidance" \ + "grep -i 'REMOVE.*duplicate.*content' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "REMOVE.*duplicate.*content" + +run_test_with_output "GitHub Action includes duplicate prevention guidance" \ + "grep -i 'REMOVE.*duplicate.*content' '$REPO_ROOT/templates/weekly-version-check-action.yml'" \ + "REMOVE.*duplicate.*content" + +run_test_with_output "Copy-paste template includes duplicate prevention" \ + "grep -i 'REMOVE.*duplicate.*content' '$REPO_ROOT/templates/copy-paste-template.md'" \ + "REMOVE.*duplicate.*content" + +run_test_with_output "Automated template update includes duplicate prevention" \ + "grep -i 'REMOVE.*duplicate.*content' '$REPO_ROOT/templates/automated-template-update.md'" \ + "REMOVE.*duplicate.*content" + +run_test_with_output "Initial setup template includes examples of what NOT to duplicate" \ + "grep -i 'Examples of what NOT to include' '$REPO_ROOT/templates/initial-setup-automation.md'" \ + "Examples of what NOT to include" + +echo -e "\n${GREEN}All automated setup template tests passed!${NC}" \ No newline at end of file diff --git a/tests/test-integration.sh b/tests/test-integration.sh index 7a9c95e..738200f 100755 --- a/tests/test-integration.sh +++ b/tests/test-integration.sh @@ -3,11 +3,67 @@ # Integration tests for script interactions and end-to-end workflows # +set -e + +# Color output for better readability +RED='\033[0;31m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Test configuration +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(dirname "$SCRIPT_DIR")" + +# Test helper functions +run_test_with_output() { + local test_name="$1" + local test_command="$2" + local expected_pattern="$3" + + printf " Testing %s... " "$test_name" + + if eval "$test_command" | grep -q "$expected_pattern"; then + echo -e "${GREEN}โœ… PASS${NC}" + return 0 + else + echo -e "${RED}โŒ FAIL${NC}" + return 1 + fi +} + +run_test() { + local test_name="$1" + local test_command="$2" + + printf " Testing %s... " "$test_name" + + if eval "$test_command" >/dev/null 2>&1; then + echo -e "${GREEN}โœ… PASS${NC}" + return 0 + else + echo -e "${RED}โŒ FAIL${NC}" + return 1 + fi +} + +print_test_result() { + local test_name="$1" + local result="$2" + + if [[ "$result" == "PASS" ]]; then + echo -e " ${GREEN}โœ… PASS${NC} $test_name" + else + echo -e " ${RED}โŒ FAIL${NC} $test_name" + fi +} + echo -e "${BLUE}Testing Script Integration${NC}" # Test full version update workflow test_version_update_workflow() { - cd "$TEST_DIR" + cd "$REPO_ROOT" # Store original versions local original_template_version=$(grep "^**Version:**" template.md | head -1 | sed 's/.*Version:\*\* *//' | tr -d ' ') @@ -36,7 +92,7 @@ run_test \ # Test consistency check after version update test_consistency_after_update() { - cd "$TEST_DIR" + cd "$REPO_ROOT" # Store original version local original_version=$(./scripts/extract-version.sh template) @@ -64,7 +120,7 @@ run_test \ # Test sync functionality restores consistency test_sync_restores_consistency() { - cd "$TEST_DIR" + cd "$REPO_ROOT" # Create inconsistency by manually editing README sed -i 's/Latest Version:\*\* v[0-9]\+\.[0-9]\+\.[0-9]\+/Latest Version:** v9.9.9/' README.md @@ -87,7 +143,7 @@ run_test \ # Test all scripts have execute permissions scripts=("manage-versions.sh" "extract-version.sh" "update-versions.sh" "check-template-version.sh") for script in "${scripts[@]}"; do - if [[ -x "$TEST_DIR/scripts/$script" ]]; then + if [[ -x "$REPO_ROOT/scripts/$script" ]]; then print_test_result "Script $script has execute permission" "PASS" else print_test_result "Script $script has execute permission" "FAIL" "Script lacks execute permission" @@ -96,7 +152,7 @@ done # Test all scripts can be run from any directory test_script_path_independence() { - cd "$TEST_DIR" + cd "$REPO_ROOT" # Create a subdirectory and test running from there mkdir -p test-subdir @@ -120,7 +176,7 @@ run_test \ # Test error handling when repository files are missing test_missing_files_handling() { - cd "$TEST_DIR" + cd "$REPO_ROOT" # Test with missing template - show command should still work (displays warning) mv template.md template.md.bak @@ -160,7 +216,7 @@ run_test \ # Test date synchronization test_date_synchronization() { - cd "$TEST_DIR" + cd "$REPO_ROOT" # Change README date to something old sed -i 's/Last Updated:\*\* [A-Za-z]* [0-9]*/Last Updated:** January 2000/' README.md diff --git a/tests/test-manage-versions.sh b/tests/test-manage-versions.sh index 583f05b..99fbd32 100755 --- a/tests/test-manage-versions.sh +++ b/tests/test-manage-versions.sh @@ -3,63 +3,119 @@ # Tests for manage-versions.sh script # +set -e + +# Color output for better readability +RED='\033[0;31m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Test configuration +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(dirname "$SCRIPT_DIR")" + +# Test helper functions +run_test_with_output() { + local test_name="$1" + local test_command="$2" + local expected_pattern="$3" + + printf " Testing %s... " "$test_name" + + if eval "$test_command" | grep -q "$expected_pattern"; then + echo -e "${GREEN}โœ… PASS${NC}" + return 0 + else + echo -e "${RED}โŒ FAIL${NC}" + return 1 + fi +} + +run_test() { + local test_name="$1" + local test_command="$2" + + printf " Testing %s... " "$test_name" + + if eval "$test_command" >/dev/null 2>&1; then + echo -e "${GREEN}โœ… PASS${NC}" + return 0 + else + echo -e "${RED}โŒ FAIL${NC}" + return 1 + fi +} + +print_test_result() { + local test_name="$1" + local result="$2" + + if [[ "$result" == "PASS" ]]; then + echo -e " ${GREEN}โœ… PASS${NC} $test_name" + else + echo -e " ${RED}โŒ FAIL${NC} $test_name" + fi +} + echo -e "${BLUE}Testing manage-versions.sh${NC}" # Test show command run_test_with_output \ "Show command displays version status" \ - "$TEST_DIR/scripts/manage-versions.sh show" \ + "$REPO_ROOT/scripts/manage-versions.sh show" \ "๐Ÿ“‹ Current Version Status" # Test check command with consistent versions run_test_with_output \ "Check command validates consistency" \ - "$TEST_DIR/scripts/manage-versions.sh check" \ + "$REPO_ROOT/scripts/manage-versions.sh check" \ "๐Ÿ” Checking Version Consistency" # Test default command (should be show) run_test_with_output \ "Default command shows versions" \ - "$TEST_DIR/scripts/manage-versions.sh" \ + "$REPO_ROOT/scripts/manage-versions.sh" \ "๐Ÿ“‹ Current Version Status" # Test invalid command run_test_with_output \ "Invalid command shows usage" \ - "$TEST_DIR/scripts/manage-versions.sh invalid-command" \ + "$REPO_ROOT/scripts/manage-versions.sh invalid-command" \ "Usage:" \ 1 # Test update command without version run_test_with_output \ "Update command without version shows error" \ - "$TEST_DIR/scripts/manage-versions.sh update" \ + "$REPO_ROOT/scripts/manage-versions.sh update" \ "Please specify a new version" \ 1 # Test update command with invalid version format run_test_with_output \ "Update command with invalid version format" \ - "$TEST_DIR/scripts/manage-versions.sh update invalid.version" \ + "$REPO_ROOT/scripts/manage-versions.sh update invalid.version" \ "Invalid version format" \ 1 # Test update command with valid version format run_test_with_output \ "Update command with valid version format" \ - "cd '$TEST_DIR' && ./scripts/manage-versions.sh update 0.9.9" \ + "cd '$REPO_ROOT' && ./scripts/manage-versions.sh update 0.9.9" \ "๐Ÿ“ฆ Updating to version 0.9.9" # Test sync command run_test_with_output \ "Sync command updates documentation" \ - "$TEST_DIR/scripts/manage-versions.sh sync" \ + "$REPO_ROOT/scripts/manage-versions.sh sync" \ "๐Ÿ”„ Syncing Documentation" # Test that version inconsistency is detected create_version_inconsistency() { # Create inconsistency by modifying README - sed -i 's/Latest Version:\*\* v[0-9]\+\.[0-9]\+\.[0-9]\+/Latest Version:** v9.9.9/' "$TEST_DIR/README.md" + sed -i 's/Latest Version:\*\* v[0-9]\+\.[0-9]\+\.[0-9]\+/Latest Version:** v9.9.9/' "$REPO_ROOT/README.md" } run_test \ @@ -68,7 +124,7 @@ run_test \ run_test_with_output \ "Check command detects inconsistency" \ - "$TEST_DIR/scripts/manage-versions.sh check" \ + "$REPO_ROOT/scripts/manage-versions.sh check" \ "Version mismatch" \ 1 @@ -111,7 +167,7 @@ run_test_with_output \ # Test script dependencies exist dependencies=("extract-version.sh" "update-versions.sh") for dep in "${dependencies[@]}"; do - if [[ -f "$TEST_DIR/scripts/$dep" ]]; then + if [[ -f "$REPO_ROOT/scripts/$dep" ]]; then print_test_result "Dependency $dep exists" "PASS" else print_test_result "Dependency $dep exists" "FAIL" "Missing dependency: $dep" @@ -119,7 +175,7 @@ for dep in "${dependencies[@]}"; do done # Test script is executable -if [[ -x "$TEST_DIR/scripts/manage-versions.sh" ]]; then +if [[ -x "$REPO_ROOT/scripts/manage-versions.sh" ]]; then print_test_result "Script is executable" "PASS" else print_test_result "Script is executable" "FAIL" "Script is not executable" diff --git a/tests/test-update-versions.sh b/tests/test-update-versions.sh index 2db849c..47744f6 100755 --- a/tests/test-update-versions.sh +++ b/tests/test-update-versions.sh @@ -3,34 +3,90 @@ # Tests for update-versions.sh script # +set -e + +# Color output for better readability +RED='\033[0;31m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Test configuration +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(dirname "$SCRIPT_DIR")" + +# Test helper functions +run_test_with_output() { + local test_name="$1" + local test_command="$2" + local expected_pattern="$3" + + printf " Testing %s... " "$test_name" + + if eval "$test_command" | grep -q "$expected_pattern"; then + echo -e "${GREEN}โœ… PASS${NC}" + return 0 + else + echo -e "${RED}โŒ FAIL${NC}" + return 1 + fi +} + +run_test() { + local test_name="$1" + local test_command="$2" + + printf " Testing %s... " "$test_name" + + if eval "$test_command" >/dev/null 2>&1; then + echo -e "${GREEN}โœ… PASS${NC}" + return 0 + else + echo -e "${RED}โŒ FAIL${NC}" + return 1 + fi +} + +print_test_result() { + local test_name="$1" + local result="$2" + + if [[ "$result" == "PASS" ]]; then + echo -e " ${GREEN}โœ… PASS${NC} $test_name" + else + echo -e " ${RED}โŒ FAIL${NC} $test_name" + fi +} + echo -e "${BLUE}Testing update-versions.sh${NC}" # Test successful version update run_test_with_output \ "Update versions script runs successfully" \ - "$TEST_DIR/scripts/update-versions.sh" \ + "$REPO_ROOT/scripts/update-versions.sh" \ "๐Ÿ”„ Updating documentation versions" # Test that script updates README with current template version run_test_with_output \ "Script extracts template version" \ - "$TEST_DIR/scripts/update-versions.sh" \ + "$REPO_ROOT/scripts/update-versions.sh" \ "Template version:" # Test that script extracts current date run_test_with_output \ "Script extracts current date" \ - "$TEST_DIR/scripts/update-versions.sh" \ + "$REPO_ROOT/scripts/update-versions.sh" \ "Current date:" # Test completion message run_test_with_output \ "Script shows completion message" \ - "$TEST_DIR/scripts/update-versions.sh" \ + "$REPO_ROOT/scripts/update-versions.sh" \ "๐Ÿ Version update complete" # Test dependency on extract-version.sh -if [[ -f "$TEST_DIR/scripts/extract-version.sh" ]]; then +if [[ -f "$REPO_ROOT/scripts/extract-version.sh" ]]; then print_test_result "Dependency extract-version.sh exists" "PASS" else print_test_result "Dependency extract-version.sh exists" "FAIL" "Missing dependency: extract-version.sh" @@ -38,7 +94,7 @@ fi # Test with missing extract-version.sh dependency test_missing_dependency() { - cd "$TEST_DIR" + cd "$REPO_ROOT" mv scripts/extract-version.sh scripts/extract-version.sh.bak local exit_code=0 @@ -59,7 +115,7 @@ run_test \ # Test that script handles missing template gracefully test_missing_template() { - cd "$TEST_DIR" + cd "$REPO_ROOT" mv template.md template.md.bak local exit_code=0 @@ -79,7 +135,7 @@ run_test \ 1 # Test README file exists -if [[ -f "$TEST_DIR/README.md" ]]; then +if [[ -f "$REPO_ROOT/README.md" ]]; then print_test_result "README.md exists for updating" "PASS" else print_test_result "README.md exists for updating" "FAIL" "README.md not found" @@ -88,11 +144,11 @@ fi # Test that no changes are made if already up to date run_test_with_output \ "No changes message when already up to date" \ - "cd '$TEST_DIR' && ./scripts/update-versions.sh && ./scripts/update-versions.sh" \ + "cd '$REPO_ROOT' && ./scripts/update-versions.sh && ./scripts/update-versions.sh" \ "No changes needed" # Test script is executable -if [[ -x "$TEST_DIR/scripts/update-versions.sh" ]]; then +if [[ -x "$REPO_ROOT/scripts/update-versions.sh" ]]; then print_test_result "Script is executable" "PASS" else print_test_result "Script is executable" "FAIL" "Script is not executable" @@ -100,19 +156,19 @@ fi # Test actual version replacement in README test_version_replacement() { - local original_version=$(grep "Latest Version:" "$TEST_DIR/README.md" | head -1 | sed 's/.*Latest Version:\*\* v*//' | tr -d ' ') + local original_version=$(grep "Latest Version:" "$REPO_ROOT/README.md" | head -1 | sed 's/.*Latest Version:\*\* v*//' | tr -d ' ') # Change template version temporarily - sed -i 's/^\*\*Version:\*\* [0-9\.]*/**Version:** 9.8.7/' "$TEST_DIR/template.md" + sed -i 's/^\*\*Version:\*\* [0-9\.]*/**Version:** 9.8.7/' "$REPO_ROOT/template.md" # Run update script - "$TEST_DIR/scripts/update-versions.sh" >/dev/null 2>&1 + "$REPO_ROOT/scripts/update-versions.sh" >/dev/null 2>&1 # Check if README was updated - local updated_version=$(grep "Latest Version:" "$TEST_DIR/README.md" | head -1 | sed 's/.*Latest Version:\*\* v*//' | tr -d ' ') + local updated_version=$(grep "Latest Version:" "$REPO_ROOT/README.md" | head -1 | sed 's/.*Latest Version:\*\* v*//' | tr -d ' ') # Restore original template - sed -i 's/^\*\*Version:\*\* [0-9\.]*/**Version:** '"$original_version"'/' "$TEST_DIR/template.md" + sed -i 's/^\*\*Version:\*\* [0-9\.]*/**Version:** '"$original_version"'/' "$REPO_ROOT/template.md" if [[ "$updated_version" == "9.8.7" ]]; then return 0