|
| 1 | +# .github/workflows/plugin-release.yml |
| 2 | +# CI/CD pipeline for the DocTest validation plugin |
| 3 | +# |
| 4 | +# This workflow demonstrates best practices for Unraid plugin releases: |
| 5 | +# - Builds TXZ package with proper line endings |
| 6 | +# - Calculates SHA256 for integrity verification |
| 7 | +# - Generates PLG file from template with correct URLs |
| 8 | +# - Creates GitHub releases with all artifacts |
| 9 | +# |
| 10 | +# Triggers: |
| 11 | +# - Push to main (validation only, no release) |
| 12 | +# - Manual workflow_dispatch (for testing) |
| 13 | +# - New tag matching v* pattern (creates release) |
| 14 | + |
| 15 | +name: Build & Release Plugin |
| 16 | + |
| 17 | +on: |
| 18 | + push: |
| 19 | + branches: [main] |
| 20 | + paths: |
| 21 | + - 'validation/plugin/**' |
| 22 | + - '.github/workflows/plugin-release.yml' |
| 23 | + tags: |
| 24 | + - 'v*' |
| 25 | + workflow_dispatch: |
| 26 | + inputs: |
| 27 | + version: |
| 28 | + description: 'Version to build (e.g., 2026.02.01)' |
| 29 | + required: false |
| 30 | + default: '' |
| 31 | + |
| 32 | +permissions: |
| 33 | + contents: write |
| 34 | + |
| 35 | +env: |
| 36 | + PLUGIN_NAME: doctest |
| 37 | + |
| 38 | +jobs: |
| 39 | + build: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + outputs: |
| 42 | + version: ${{ steps.version.outputs.VERSION }} |
| 43 | + sha256: ${{ steps.package.outputs.SHA256 }} |
| 44 | + |
| 45 | + steps: |
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + |
| 51 | + - name: Determine version |
| 52 | + id: version |
| 53 | + run: | |
| 54 | + if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/v* ]]; then |
| 55 | + # Release tag - extract version from tag (remove 'v' prefix) |
| 56 | + VERSION="${GITHUB_REF#refs/tags/v}" |
| 57 | + elif [[ -n "${{ github.event.inputs.version }}" ]]; then |
| 58 | + # Manual input |
| 59 | + VERSION="${{ github.event.inputs.version }}" |
| 60 | + else |
| 61 | + # Default: date-based version |
| 62 | + VERSION="$(date +%Y.%m.%d)" |
| 63 | + fi |
| 64 | + echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT |
| 65 | + echo "Building version: ${VERSION}" |
| 66 | +
|
| 67 | + - name: Build TXZ package |
| 68 | + id: package |
| 69 | + run: | |
| 70 | + VERSION="${{ steps.version.outputs.VERSION }}" |
| 71 | + cd validation/plugin |
| 72 | + |
| 73 | + # Create build directory structure |
| 74 | + rm -rf build dist |
| 75 | + mkdir -p build/usr/local/emhttp/plugins/${{ env.PLUGIN_NAME }} |
| 76 | + mkdir -p dist |
| 77 | + |
| 78 | + # Copy source files |
| 79 | + cp -R source/emhttp/* build/usr/local/emhttp/plugins/${{ env.PLUGIN_NAME }}/ |
| 80 | + |
| 81 | + # CRITICAL: Convert Windows line endings to Unix (CRLF → LF) |
| 82 | + find build -type f \( -name "*.sh" -o -name "*.page" -o -name "*.cfg" \) -exec sed -i 's/\r$//' {} \; |
| 83 | + find build -path "*/event/*" -type f -exec sed -i 's/\r$//' {} \; |
| 84 | + |
| 85 | + # Set permissions |
| 86 | + find build -type d -exec chmod 755 {} \; |
| 87 | + find build -type f -exec chmod 644 {} \; |
| 88 | + find build -path "*/event/*" -type f -exec chmod 755 {} \; |
| 89 | + |
| 90 | + # Create TXZ package |
| 91 | + cd build |
| 92 | + tar -cJf "../dist/${{ env.PLUGIN_NAME }}-${VERSION}.txz" . |
| 93 | + cd .. |
| 94 | + |
| 95 | + # Calculate SHA256 |
| 96 | + SHA256=$(sha256sum "dist/${{ env.PLUGIN_NAME }}-${VERSION}.txz" | cut -d' ' -f1) |
| 97 | + echo "SHA256=${SHA256}" >> $GITHUB_OUTPUT |
| 98 | + echo "Package SHA256: ${SHA256}" |
| 99 | +
|
| 100 | + - name: Generate PLG file |
| 101 | + run: | |
| 102 | + VERSION="${{ steps.version.outputs.VERSION }}" |
| 103 | + SHA256="${{ steps.package.outputs.SHA256 }}" |
| 104 | + |
| 105 | + cd validation/plugin |
| 106 | + |
| 107 | + # Generate PLG from template with substitutions |
| 108 | + sed -e "s|<!ENTITY version.*|<!ENTITY version \"${VERSION}\">|" \ |
| 109 | + -e "s|<!ENTITY txzName.*|<!ENTITY txzName \"${{ env.PLUGIN_NAME }}-${VERSION}.txz\">|" \ |
| 110 | + -e "s|<!ENTITY txzURL.*|<!ENTITY txzURL \"https://github.com/${{ github.repository }}/releases/download/v${VERSION}/${{ env.PLUGIN_NAME }}-${VERSION}.txz\">|" \ |
| 111 | + -e "s|<!ENTITY txzSHA256.*|<!ENTITY txzSHA256 \"${SHA256}\">|" \ |
| 112 | + doctest.plg.template > dist/${{ env.PLUGIN_NAME }}.plg |
| 113 | + |
| 114 | + echo "Generated PLG file:" |
| 115 | + head -20 dist/${{ env.PLUGIN_NAME }}.plg |
| 116 | +
|
| 117 | + - name: Upload build artifacts |
| 118 | + uses: actions/upload-artifact@v4 |
| 119 | + with: |
| 120 | + name: plugin-package |
| 121 | + path: | |
| 122 | + validation/plugin/dist/*.txz |
| 123 | + validation/plugin/dist/*.plg |
| 124 | + retention-days: 30 |
| 125 | + |
| 126 | + # Only run release job on tag push |
| 127 | + release: |
| 128 | + needs: build |
| 129 | + runs-on: ubuntu-latest |
| 130 | + if: startsWith(github.ref, 'refs/tags/v') |
| 131 | + |
| 132 | + steps: |
| 133 | + - name: Download artifacts |
| 134 | + uses: actions/download-artifact@v4 |
| 135 | + with: |
| 136 | + name: plugin-package |
| 137 | + path: dist/ |
| 138 | + |
| 139 | + - name: Create GitHub Release |
| 140 | + uses: softprops/action-gh-release@v2 |
| 141 | + with: |
| 142 | + name: "DocTest Plugin v${{ needs.build.outputs.version }}" |
| 143 | + body: | |
| 144 | + ## DocTest Validation Plugin v${{ needs.build.outputs.version }} |
| 145 | + |
| 146 | + This plugin validates features documented at [unraid-plugin-docs](https://mstrhakr.github.io/unraid-plugin-docs/). |
| 147 | + |
| 148 | + ### Installation |
| 149 | + |
| 150 | + **Via Plugin Manager:** |
| 151 | + ``` |
| 152 | + https://raw.githubusercontent.com/${{ github.repository }}/main/validation/doctest.plg |
| 153 | + ``` |
| 154 | + |
| 155 | + **Or install directly:** |
| 156 | + ```bash |
| 157 | + plugin install https://raw.githubusercontent.com/${{ github.repository }}/main/validation/doctest.plg |
| 158 | + ``` |
| 159 | + |
| 160 | + ### What's Validated |
| 161 | + - All 16 documented event handlers |
| 162 | + - `parse_plugin_cfg()` and `mk_option()` functions |
| 163 | + - `$var` array properties |
| 164 | + - Page file rendering and form handling |
| 165 | + - Notification system integration |
| 166 | + |
| 167 | + ### Package Details |
| 168 | + - **SHA256:** `${{ needs.build.outputs.sha256 }}` |
| 169 | + files: | |
| 170 | + dist/*.txz |
| 171 | + dist/*.plg |
| 172 | + fail_on_unmatched_files: true |
| 173 | + env: |
| 174 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 175 | + |
| 176 | + - name: Update main branch PLG |
| 177 | + run: | |
| 178 | + # This step would update the PLG in the main branch |
| 179 | + # For now, we'll document that this should be done manually |
| 180 | + # or via a separate workflow that commits the updated PLG |
| 181 | + echo "Release created. Remember to update validation/doctest.plg in main branch." |
0 commit comments