# Centralized GitHub Action for ioBroker Copilot Template Version Management # Version: 0.5.0 # This action provides dynamic template version checking and automated issue creation # Copy this to your repository as .github/workflows/check-copilot-template.yml name: Check ioBroker Copilot Template Version on: schedule: - cron: '23 3 * * 0' # Weekly check optimized for off-peak hours (3:23 AM UTC 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: Dynamic template version check id: version-check run: | echo "๐Ÿ” Starting dynamic ioBroker Copilot template version check..." # Get current version from local copilot instructions if [ -f ".github/copilot-instructions.md" ]; then CURRENT_VERSION=$(awk '/Version:|Template Version:/ {match($0, /([0-9]+(\.[0-9]+)*)/, arr); if (arr[1] != "") print arr[1]}' .github/copilot-instructions.md | head -1) if [ -z "$CURRENT_VERSION" ]; then CURRENT_VERSION="unknown"; fi echo "๐Ÿ“‹ Current local version: $CURRENT_VERSION" else CURRENT_VERSION="none" echo "โŒ No .github/copilot-instructions.md file found" fi # Get latest version from centralized metadata echo "๐ŸŒ Fetching latest template version from centralized config..." LATEST_VERSION=$(curl -s https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/config/metadata.json | jq -r '.version' 2>/dev/null || echo "unknown") if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" = "null" ]; then LATEST_VERSION="unknown" fi echo "๐Ÿ“‹ Latest available version: $LATEST_VERSION" # Determine repository status COPILOT_INITIALIZED="false" UPDATE_NEEDED="false" SETUP_NEEDED="false" if [ "$CURRENT_VERSION" = "none" ]; then echo "๐Ÿšจ Repository not initialized for GitHub Copilot" SETUP_NEEDED="true" UPDATE_NEEDED="true" elif [ "$CURRENT_VERSION" = "unknown" ] || [ "$LATEST_VERSION" = "unknown" ]; then echo "โš ๏ธ Version detection issue - assuming update needed" COPILOT_INITIALIZED="true" UPDATE_NEEDED="true" elif [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then echo "๐Ÿ†™ Update available!" COPILOT_INITIALIZED="true" UPDATE_NEEDED="true" else echo "โœ… Template is up-to-date" COPILOT_INITIALIZED="true" UPDATE_NEEDED="false" fi # Set outputs for subsequent steps echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT echo "latest-version=$LATEST_VERSION" >> $GITHUB_OUTPUT echo "update-needed=$UPDATE_NEEDED" >> $GITHUB_OUTPUT echo "setup-needed=$SETUP_NEEDED" >> $GITHUB_OUTPUT echo "copilot-initialized=$COPILOT_INITIALIZED" >> $GITHUB_OUTPUT echo "๐Ÿ“Š Analysis complete:" echo " - Copilot Initialized: $COPILOT_INITIALIZED" echo " - Setup Needed: $SETUP_NEEDED" echo " - Update Needed: $UPDATE_NEEDED" - name: Check for and close existing Copilot-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 Copilot-related issues...'); const { data: issues } = await github.rest.issues.listForRepo({ owner: context.repo.owner, repo: context.repo.repo, state: 'open', per_page: 100, creator: 'github-actions[bot]' }); // Look for existing Copilot template-related issues created by github-actions // Check only creator and title pattern (not labels) const copilotIssues = issues.filter(issue => { const title = issue.title.toLowerCase(); const hasKeywords = title.includes('copilot') && ( title.includes('template') || title.includes('setup') || title.includes('update') || title.includes('instructions') ); return hasKeywords; }); if (copilotIssues.length > 0) { console.log(`๐Ÿ“‹ Found ${copilotIssues.length} existing Copilot-related issue(s):`); // Close ALL existing issues with a comment for (const issue of copilotIssues) { console.log(` - Closing #${issue.number}: ${issue.title}`); await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issue.number, body: '๐Ÿค– Closing this issue as a new version check has been triggered. A new issue will be created with the latest information.' }); await github.rest.issues.update({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issue.number, state: 'closed' }); } console.log(`โœ… Closed ${copilotIssues.length} existing issue(s)`); return null; } else { console.log('โœ… No existing Copilot-related issues found'); return null; } - name: Create automated setup or update issue if: steps.version-check.outputs.update-needed == 'true' uses: actions/github-script@v7 with: script: | const currentVersion = '${{ steps.version-check.outputs.current-version }}'; const latestVersion = '${{ steps.version-check.outputs.latest-version }}'; const setupNeeded = '${{ steps.version-check.outputs.setup-needed }}' === 'true'; const repoName = context.repo.repo; console.log(`๐ŸŽฏ Creating automated issue for ${context.repo.owner}/${repoName}`); console.log(`๐Ÿ“‹ Current: ${currentVersion}, Latest: ${latestVersion}, Setup needed: ${setupNeeded}`); let title, body, labels; if (setupNeeded) { // Initial setup case title = '๐Ÿค– Setup ioBroker GitHub Copilot Instructions'; labels = ['copilot-setup', 'automation', 'enhancement']; body = `# ๐Ÿค– Automated ioBroker Copilot Instructions Setup **Automated Detection**: This ioBroker adapter repository is not set up for GitHub Copilot yet. **Latest Available Version**: ${latestVersion} **Repository**: ${context.repo.owner}/${repoName} ## ๐ŸŽฏ What This Sets Up GitHub Copilot instructions will enhance your development experience by providing: - โœจ ioBroker-specific code suggestions and best practices - ๐Ÿงช Enhanced testing patterns with @iobroker/testing framework - ๐Ÿ“ Improved README and documentation generation - ๐Ÿ”ง Smart error handling and state management patterns - ๐Ÿ›ก๏ธ Security and performance optimization guidance ## ๐Ÿš€ Automated Setup Process **GitHub Copilot**: Please help me set up GitHub Copilot instructions for my ioBroker adapter repository. ### ๐Ÿ” Step 1: Repository Analysis Please start by analyzing this repository: 1. **Repository Status**: Confirm this is an ioBroker adapter repository 2. **Existing Configuration**: Check if any Copilot configuration already exists 3. **Adapter Type**: Identify the type of adapter (device, service, etc.) 4. **Dependencies**: Review package.json for existing patterns ### ๐Ÿ”ง Step 2: Template Setup Create a complete \`.github/copilot-instructions.md\` file using: 1. **Download latest template**: \`\`\` Template source: https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md Version: ${latestVersion} Metadata: https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/config/metadata.json \`\`\` 2. **Template processing**: - Remove template comment block (\`\` section) - Set version to **${latestVersion}** (store in copilot instructions, NOT package.json) - Add template source reference - Customize all \`[CUSTOMIZE]\` sections for this ${repoName} adapter 3. **Adapter-specific customization**: In the \`[CUSTOMIZE] Project-Specific Instructions\` section, add: - ${repoName} adapter's specific API patterns and authentication - Unique error codes and handling for this service - Custom device discovery or connection patterns - Special configuration requirements - Testing scenarios specific to this adapter ### โš™๏ธ Step 3: Weekly Monitoring Setup Create \`.github/workflows/check-copilot-template.yml\` using: \`\`\` Template: https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/templates/centralized-version-check-action.yml \`\`\` This will provide: - ๐Ÿ“… Weekly automated version checking - ๐ŸŽฏ Automatic issue creation for updates - ๐Ÿ›ก๏ธ Preservation of custom sections during updates ## ๐Ÿ”ง Validation Checklist After setup, please confirm: - [ ] File created at \`.github/copilot-instructions.md\` - [ ] **Version ${latestVersion} stored in copilot-instructions.md** (NOT in package.json) - [ ] Template source reference included - [ ] \`[CUSTOMIZE]\` sections populated with ${repoName}-specific content - [ ] Weekly monitoring workflow created - [ ] Enhanced Copilot suggestions working (test with \`this.setState(\` in code) ## ๐ŸŽ Next Steps Once complete: 1. **Test Integration**: Verify enhanced ioBroker suggestions in your IDE 2. **Custom Content**: All \`[CUSTOMIZE]\` sections preserved in future updates 3. **Automated Maintenance**: Weekly checks ensure you stay up-to-date 4. **Development Boost**: Experience improved code suggestions and best practices ## ๐Ÿ“š References - **Template Repository**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions - **Setup Documentation**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions/blob/main/docs/setup.md - **Centralized Config**: https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/config/metadata.json --- *๐Ÿค– This issue was automatically created by the centralized GitHub Actions workflow. Weekly monitoring will continue while preserving all your customizations.*`; } else { // Update case title = '๐Ÿค– Update ioBroker Copilot Instructions Template'; labels = ['template-update', 'automation', 'enhancement']; body = `# ๐Ÿค– ioBroker Copilot Template Update Available **Automated Detection**: Your ioBroker Copilot instructions have 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 process: \`\`\` Update my .github/copilot-instructions.md by merging the latest ioBroker template. TEMPLATE SOURCE: - Template: https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/template.md - Version: ${latestVersion} - Metadata: https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/config/metadata.json CRITICAL PRESERVATION REQUIREMENTS: 1. Keep ALL [CUSTOMIZE] sections and their content exactly as they are 2. Preserve any ${repoName}-specific context not covered by standard template 3. Maintain custom error handling, API patterns, authentication flows 4. Keep unique testing scenarios and configuration instructions 5. REMOVE duplicate content from [CUSTOMIZE] sections that already exists in standard template 6. Keep only truly unique, adapter-specific content in [CUSTOMIZE] sections UPDATE REQUIREMENTS: 1. Integrate latest ioBroker best practices from new template 2. Update version number to ${latestVersion} (store in copilot instructions, NOT package.json) 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 changes 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 - ๐ŸŽฏ More precise ioBroker-specific code patterns ## ๐Ÿ”ง Validation Checklist After update, confirm: - [ ] All \`[CUSTOMIZE]\` sections preserved exactly - [ ] **Version ${latestVersion} stored in copilot-instructions.md** (NOT package.json) - [ ] Custom ${repoName}-specific content intact - [ ] New best practices integrated without conflicts - [ ] Template source reference updated - [ ] Enhanced suggestions working (test in your code editor) - [ ] No duplicate content between \`[CUSTOMIZE]\` and standard sections ## ๐Ÿ›ก๏ธ Safety Features This automated process: - โœ… **Preserves Customizations**: All \`[CUSTOMIZE]\` sections automatically maintained - ๐Ÿ”’ **No Data Loss**: Your adapter-specific patterns remain intact - ๐Ÿ“‹ **Audit Trail**: All changes tracked in this issue - ๐Ÿ”„ **Reversible**: Changes can be reverted if needed - ๐ŸŽฏ **Version Control**: Template version stored in copilot instructions (not package.json) ## ๐Ÿ“š References - **Template Repository**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions - **Centralized Config**: https://raw.githubusercontent.com/DrozmotiX/ioBroker-Copilot-Instructions/main/config/metadata.json - **Update Guide**: https://github.com/DrozmotiX/ioBroker-Copilot-Instructions/blob/main/docs/automated-updates.md --- *๐Ÿค– This issue was automatically created by the centralized GitHub Actions workflow on ${new Date().toISOString().split('T')[0]}. Weekly monitoring continues 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 status run: | echo "๐Ÿ Centralized template check completed!" echo "๐Ÿ“Š Status Summary:" echo " - Current Version: ${{ steps.version-check.outputs.current-version }}" echo " - Latest Version: ${{ steps.version-check.outputs.latest-version }}" echo " - Copilot Initialized: ${{ steps.version-check.outputs.copilot-initialized }}" echo " - Update Needed: ${{ steps.version-check.outputs.update-needed }}" echo " - Setup Needed: ${{ steps.version-check.outputs.setup-needed }}" if [ "${{ steps.version-check.outputs.update-needed }}" = "false" ]; then echo "โœ… No action required - template is current" else echo "๐ŸŽฏ New automation issue created for repository setup/update" fi echo "" echo "๐Ÿ“ˆ This centralized workflow provides:" echo " โœจ Dynamic version checking from metadata.json" echo " ๐Ÿ” Repository status detection" echo " ๐Ÿค– Copilot-driven automation (no manual scripts)" echo " ๐Ÿ›ก๏ธ Custom section preservation" echo " ๐Ÿ“… Weekly monitoring"