Skip to content

Commit

Permalink
fix chocolatey workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
marianina8 committed May 20, 2024
1 parent b927d0a commit 15a75f4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/chocolatey.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,29 @@ jobs:
run: |
filename="timetravel.exe"
url="https://github.com/${{ github.repository }}/releases/download/${{ steps.latesttag.outputs.tag }}/${filename}"
sed -i "s#{URL64}#${url}#g" "Assets/Choco/timetravel/tools/chocolateyinstall.ps1"
curl -sSL "${url}" -o "Assets/Choco/${filename}"
sha256=$(cat "Assets/Choco/${filename}" | sha256sum -)
sed -i "s/{SHA256CHECKSUM64}/${sha256:0:64}/g" "Assets/Choco/timetravel/tools/chocolateyinstall.ps1"
sed -i "s#{URL64}#${url}#g" "choco/tools/chocolateyinstall.ps1"
curl -sSL "${url}" -o "choco/${filename}"
sha256=$(cat "choco/${filename}" | sha256sum -)
sed -i "s/{SHA256CHECKSUM64}/${sha256:0:64}/g" "choco/tools/chocolateyinstall.ps1"
- name: Set Version
id: version
run: |
version=${{ steps.latesttag.outputs.tag }}
echo "nuget=$version" >> $GITHUB_OUTPUT
sed -i "s/{VERSION}/${version}/g" "Assets/Choco/timetravel/timetravel.nuspec"
sed -i "s/{VERSION}/${version}/g" "choco/timetravel/timetravel.nuspec"
- name: Choco Downgrade
uses: crazy-max/ghaction-chocolatey@v3
with:
args: install chocolatey --version=1.2.1 --allow-downgrade -y -r --no-progress
- name: Pack Release
uses: crazy-max/ghaction-chocolatey@v3
with:
args: pack Assets/Choco/timetravel/timetravel.nuspec --outputdirectory Assets/Choco/timetravel
args: pack choco/timetravel/timetravel.nuspec --outputdirectory choco/timetravel
- name: Choco Upgrade
uses: crazy-max/ghaction-chocolatey@v3
with:
args: upgrade chocolatey
- name: Upload Release
uses: crazy-max/ghaction-chocolatey@v3
with:
args: push Assets/Choco/timetravel/timetravel.${{ steps.version.outputs.nuget }}.nupkg -s https://push.chocolatey.org/ -k ${{ secrets.CHOCO_KEY }}
args: push choco/timetravel/timetravel.${{ steps.version.outputs.nuget }}.nupkg -s https://push.chocolatey.org/ -k ${{ secrets.CHOCO_KEY }}
16 changes: 16 additions & 0 deletions choco/timetravel.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>timetravel</id>
<version>{{ .Version }}</version>
<title>Time Travel CLI</title>
<authors>marianina8</authors>
<owners>marianina8</owners>
<projectUrl>https://github.com/marianina8/timetravel</projectUrl>
<description>A CLI tool for time travel</description>
<tags>cli golang timetravel</tags>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
36 changes: 36 additions & 0 deletions choco/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$ErrorActionPreference = 'Stop'

$packageName = 'timetravel'
$toolsDir = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)"
$binRoot = Get-ToolsLocation

# Use the package version from Chocolatey's environment variable
$packageVersion = $env:chocolateyPackageVersion

# Define the URL for the binary package dynamically
$url = "https://github.com/marianina8/timetravel/releases/download/v$packageVersion/timetravel-windows-amd64.zip"

# Define the file paths
$zipPath = Join-Path $toolsDir 'timetravel-windows-amd64.zip'
$exePath = Join-Path $toolsDir 'timetravel.exe'

# Download the zip file
Write-Host "Downloading $url to $zipPath"
Invoke-WebRequest -Uri $url -OutFile $zipPath

# Unzip the file
Write-Host "Unzipping $zipPath to $toolsDir"
Get-ChocolateyUnzip -FileFullPath $zipPath -Destination $toolsDir

# Move the binary to the tools directory
Write-Host "Moving timetravel.exe to $toolsDir"
Move-Item -Path (Join-Path $toolsDir 'timetravel-windows-amd64\timetravel.exe') -Destination $exePath

# Remove the zip file
Write-Host "Removing $zipPath"
Remove-Item -Path $zipPath

# Add to PATH
Install-BinFile -Name 'timetravel' -Path $exePath

Write-Host "$packageName has been installed."

0 comments on commit 15a75f4

Please sign in to comment.