|
| 1 | +# Publish to Chocolatey Community Repository |
| 2 | +# |
| 3 | +# PREREQUISITES: |
| 4 | +# 1. Create a Chocolatey account at https://community.chocolatey.org/account/Register |
| 5 | +# 2. Get your API key from https://community.chocolatey.org/account |
| 6 | +# 3. Add the API key as repository secret: CHOCOLATEY_API_KEY |
| 7 | +# |
| 8 | +# Reference: https://docs.chocolatey.org/en-us/create/create-packages-quick-start |
| 9 | + |
| 10 | +name: Publish to Chocolatey |
| 11 | + |
| 12 | +on: |
| 13 | + release: |
| 14 | + types: [released] |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + release_tag: |
| 18 | + description: 'Release tag to publish (e.g., v0.96.1)' |
| 19 | + required: true |
| 20 | + type: string |
| 21 | + |
| 22 | +jobs: |
| 23 | + publish: |
| 24 | + runs-on: windows-latest |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v6 |
| 28 | + |
| 29 | + - name: Get version from tag |
| 30 | + id: version |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + TAG="${{ github.event.inputs.release_tag || github.event.release.tag_name }}" |
| 34 | + # Strip 'v' prefix if present |
| 35 | + VERSION="${TAG#v}" |
| 36 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 37 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 38 | +
|
| 39 | + - name: Download MSI from release |
| 40 | + shell: pwsh |
| 41 | + run: | |
| 42 | + $version = "${{ steps.version.outputs.version }}" |
| 43 | + $tag = "${{ steps.version.outputs.tag }}" |
| 44 | + $msiUrl = "https://github.com/CCExtractor/ccextractor/releases/download/$tag/CCExtractor.$version.msi" |
| 45 | +
|
| 46 | + Write-Host "Downloading MSI from: $msiUrl" |
| 47 | + Invoke-WebRequest -Uri $msiUrl -OutFile "CCExtractor.msi" |
| 48 | +
|
| 49 | + # Calculate SHA256 checksum |
| 50 | + $hash = (Get-FileHash -Path "CCExtractor.msi" -Algorithm SHA256).Hash |
| 51 | + Write-Host "SHA256: $hash" |
| 52 | + echo "MSI_CHECKSUM=$hash" >> $env:GITHUB_ENV |
| 53 | +
|
| 54 | + - name: Update nuspec version |
| 55 | + shell: pwsh |
| 56 | + run: | |
| 57 | + $version = "${{ steps.version.outputs.version }}" |
| 58 | + $nuspecPath = "packaging/chocolatey/ccextractor.nuspec" |
| 59 | +
|
| 60 | + $content = Get-Content $nuspecPath -Raw |
| 61 | + $content = $content -replace '<version>.*</version>', "<version>$version</version>" |
| 62 | + Set-Content -Path $nuspecPath -Value $content |
| 63 | +
|
| 64 | + Write-Host "Updated nuspec to version $version" |
| 65 | +
|
| 66 | + - name: Update install script |
| 67 | + shell: pwsh |
| 68 | + run: | |
| 69 | + $version = "${{ steps.version.outputs.version }}" |
| 70 | + $tag = "${{ steps.version.outputs.tag }}" |
| 71 | + $checksum = $env:MSI_CHECKSUM |
| 72 | + $installScript = "packaging/chocolatey/tools/chocolateyInstall.ps1" |
| 73 | +
|
| 74 | + $content = Get-Content $installScript -Raw |
| 75 | +
|
| 76 | + # Update URL |
| 77 | + $newUrl = "https://github.com/CCExtractor/ccextractor/releases/download/$tag/CCExtractor.$version.msi" |
| 78 | + $content = $content -replace "url64bit\s*=\s*'[^']*'", "url64bit = '$newUrl'" |
| 79 | +
|
| 80 | + # Update checksum |
| 81 | + $content = $content -replace "checksum64\s*=\s*'[^']*'", "checksum64 = '$checksum'" |
| 82 | +
|
| 83 | + Set-Content -Path $installScript -Value $content |
| 84 | +
|
| 85 | + Write-Host "Updated install script with URL and checksum" |
| 86 | +
|
| 87 | + - name: Build Chocolatey package |
| 88 | + shell: pwsh |
| 89 | + run: | |
| 90 | + cd packaging/chocolatey |
| 91 | + choco pack ccextractor.nuspec |
| 92 | +
|
| 93 | + # List the generated package |
| 94 | + Get-ChildItem *.nupkg |
| 95 | +
|
| 96 | + - name: Test package locally |
| 97 | + shell: pwsh |
| 98 | + run: | |
| 99 | + cd packaging/chocolatey |
| 100 | + $nupkg = Get-ChildItem *.nupkg | Select-Object -First 1 |
| 101 | + Write-Host "Testing package: $($nupkg.Name)" |
| 102 | +
|
| 103 | + # Install from local package |
| 104 | + choco install ccextractor --source="'.;https://community.chocolatey.org/api/v2/'" --yes --force |
| 105 | +
|
| 106 | + # Verify installation |
| 107 | + $ccx = Get-Command ccextractor -ErrorAction SilentlyContinue |
| 108 | + if ($ccx) { |
| 109 | + Write-Host "CCExtractor found at: $($ccx.Source)" |
| 110 | + & ccextractor --version |
| 111 | + } else { |
| 112 | + Write-Host "CCExtractor not found in PATH, checking Program Files..." |
| 113 | + $exePath = Join-Path $env:ProgramFiles "CCExtractor\ccextractor.exe" |
| 114 | + if (Test-Path $exePath) { |
| 115 | + & $exePath --version |
| 116 | + } |
| 117 | + } |
| 118 | +
|
| 119 | + - name: Push to Chocolatey |
| 120 | + shell: pwsh |
| 121 | + env: |
| 122 | + CHOCOLATEY_API_KEY: ${{ secrets.CHOCOLATEY_API_KEY }} |
| 123 | + run: | |
| 124 | + cd packaging/chocolatey |
| 125 | + $nupkg = Get-ChildItem *.nupkg | Select-Object -First 1 |
| 126 | +
|
| 127 | + Write-Host "Pushing $($nupkg.Name) to Chocolatey..." |
| 128 | + choco push $nupkg.Name --source="https://push.chocolatey.org/" --api-key="$env:CHOCOLATEY_API_KEY" |
| 129 | +
|
| 130 | + Write-Host "Package submitted to Chocolatey! It may take some time to be moderated and published." |
| 131 | +
|
| 132 | + - name: Upload package artifact |
| 133 | + uses: actions/upload-artifact@v6 |
| 134 | + with: |
| 135 | + name: chocolatey-package |
| 136 | + path: packaging/chocolatey/*.nupkg |
0 commit comments