diff --git a/.github/workflows/test-chocolatey-deploy.yml b/.github/workflows/test-chocolatey-deploy.yml new file mode 100644 index 0000000..3341eac --- /dev/null +++ b/.github/workflows/test-chocolatey-deploy.yml @@ -0,0 +1,56 @@ +name: Test release Managarr to Chocolatey + +permissions: + pull-requests: write + contents: write + +on: + workflow_dispatch: + +jobs: + publish-chocolatey-package: + needs: [publish-github-release] + name: Publish Chocolatey Package + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Get release artifacts + uses: actions/download-artifact@v4.1.7 + with: + name: artifacts + path: artifacts + + - name: Set release assets and version + shell: pwsh + run: | + # Read the first column from the SHA256 file + $windows_sha = Get-Content ./artifacts/managarr-windows.sha256 | ForEach-Object { $_.Split(' ')[0] } + Add-Content -Path $env:GITHUB_ENV -Value "WINDOWS_SHA=$windows_sha" + + # Read the release version from the release-version file + $release_version = Get-Content ./artifacts/release-version + Add-Content -Path $env:GITHUB_ENV -Value "RELEASE_VERSION=$release_version" + + - name: Validate release environment variables + run: | + echo "Release SHA windows: ${{ env.WINDOWS_SHA }}" + echo "Release version: ${{ env.RELEASE_VERSION }}" + + - name: Package and Publish package to Chocolatey + run: | + mkdir ./deployment/chocolatey/tools + # Run packaging script + python "./deployment/chocolatey/packager.py" ${{ env.RELEASE_VERSION }} "./deployment/chocolatey/managarr.nuspec.template" "./deployment/chocolatey/managarr.nuspec" ${{ env.WINDOWS_SHA }} + python "./deployment/chocolatey/packager.py" ${{ env.RELEASE_VERSION }} "./deployment/chocolatey/chocolateyinstall.ps1.template" "./deployment/chocolatey/tools/chocolateyinstall.ps1" ${{ env.WINDOWS_SHA }} + + # Publish to Chocolatey + cd ./deployment/chocolatey + choco pack + echo y | choco install managarr -dv -s . + $version = managarr --version + $version = $version -replace " ", "." + choco push $version.nupkg -s https://push.chocolatey.org/ --api-key ${{ secrets.CHOCOLATEY_API_KEY }}; diff --git a/deployment/chocolatey/chocolateyinstall.ps1.template b/deployment/chocolatey/chocolateyinstall.ps1.template new file mode 100644 index 0000000..e70133a --- /dev/null +++ b/deployment/chocolatey/chocolateyinstall.ps1.template @@ -0,0 +1,20 @@ +$ErrorActionPreference = 'Stop'; + +$PackageName = 'kdash' +$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" +$url64 = 'https://github.com/Dark-Alex-17/managarr/releases/download/v$version/managarr-windows.tar.gz' +$checksum64 = '$hash_64' + +$packageArgs = @{ + packageName = $packageName + softwareName = $packageName + unzipLocation = $toolsDir + fileType = 'exe' + url = $url64 + checksum = $checksum64 + checksumType = 'sha256' + +} +Install-ChocolateyZipPackage @packageArgs +$File = Get-ChildItem -File -Path $env:ChocolateyInstall\lib\$packageName\tools\ -Filter *.tar +Get-ChocolateyUnzip -fileFullPath $File.FullName -destination $env:ChocolateyInstall\lib\$packageName\tools\ diff --git a/deployment/chocolatey/managarr.nuspec.template b/deployment/chocolatey/managarr.nuspec.template new file mode 100644 index 0000000..a421a22 --- /dev/null +++ b/deployment/chocolatey/managarr.nuspec.template @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + managarr + $version + + + + Managarr + Alex Clarke + https://github.com/Dark-Alex-17/managarr + https://github.com/Dark-Alex-17/managarr/blob/main/LICENSE + true + https://github.com/Dark-Alex-17/managarr + https://github.com/Dark-Alex-17/managarr/blob/main/README.md + https://github.com/Dark-Alex-17/managarr/issues + cli cross-platform terminal servarr tui sonarr radarr rust + A TUI and CLI for managing *arr servers. + + A TUI and CLI for managing *arr servers. Build with love in Rust! + + **Usage** + To use, run `managarr` in a terminal. + + For more [documentation and usage](https://github.com/Dark-Alex-17/managarr/blob/main/README.md), see the [official repo](https://github.com/Dark-Alex-17/managarr). + + + https://github.com/Dark-Alex-17/managarr/releases/tag/v$version/ + + + + + + + diff --git a/deployment/chocolatey/packager.py b/deployment/chocolatey/packager.py new file mode 100644 index 0000000..e2d1837 --- /dev/null +++ b/deployment/chocolatey/packager.py @@ -0,0 +1,27 @@ +import hashlib +import sys +from string import Template + +args = sys.argv +version = args[1].replace("v", "") +template_file_path = args[2] +generated_file_path = args[3] + +# Deployment files +hash_64 = args[4].strip() + +print("Generating formula") +print(" VERSION: %s" % version) +print(" TEMPLATE PATH: %s" % template_file_path) +print(" SAVING AT: %s" % generated_file_path) +print(" HASH: %s" % hash_64) + +with open(template_file_path, "r") as template_file: + template = Template(template_file.read()) + substitute = template.safe_substitute(version=version, hash_64=hash_64) + print("\n================== Generated package file ==================\n") + print(substitute) + print("\n============================================================\n") + + with open(generated_file_path, "w") as generated_file: + generated_file.write(substitute) \ No newline at end of file