Skip to content

Instantly share code, notes, and snippets.

@cdhunt
Last active February 17, 2022 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdhunt/e3bd589481e2f3e9de4c23ed45519a3b to your computer and use it in GitHub Desktop.
Save cdhunt/e3bd589481e2f3e9de4c23ed45519a3b to your computer and use it in GitHub Desktop.
# I don't want to install Python so this docker image and Pwsh function mimic a binary
<# Dockerfile
FROM python:3-alpine
RUN pip install --upgrade cloudsmith-cli
WORKDIR /working
ENTRYPOINT ["cloudsmith"]
#>
function cloudsmith {
& docker run --rm -it `
-v "$($PWD.Path):/working" `
-v "$($env:LOCALAPPDATA)\cloudsmith:/root/.config/cloudsmith" `
cloudsmith-cli:3-alpine `
$args
}
# Get Package List
$names = gh api -X GET "/orgs/ORGNAME/packages" -F package_type=nuget --paginate | ConvertFrom-Json | select -exp Name
# Download all of the Packages
# The `dotnet nuget` command doesn't appear to have a raw download option. It wants to install it into a project.
$names | foreach-object { nuget install $_ -Source ProGet -DirectDownload -PackageSaveMode nupkg}
# Upload to CloudSmith
$names | %{ ls -path "$_*" -Directory } |
foreach-object { ls "$($_.FullName)\*.nupkg" |
foreach-object { nuget push $_.FullName -Source nuget -SkipDuplicate -ApiKey $api.GetNetworkCredential().Password}}
$files = Get-ChildItem -Path C:\temp\zipfiles\ -Recurse -File
# Grab the version string from the filename
$pattern = [regex]'app-setup\.(\d{4}\.\d{1,2}\.\d{1,3}\.\d{1,3})(-pre-release)*\.zip'
foreach ($file in $files) {
$name = $file.Name
$folder = $file.FullName | Split-Path -Parent | Split-Path -Leaf
if ($file.Name -match $pattern) {
$version = $Matches[1]
# Check if it has a prerelease tag
if ($Matches.Count -eq 3) {
$version += $Matches[2]
}
cloudsmith push raw org/rawrepo $folder/$name --version $version -W --name enterprise-setup
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment